32 #include <SimoxUtility/algorithm/string/string_tools.h>
33 #include <VirtualRobot/SceneObjectSet.h>
34 #include <VirtualRobot/VirtualRobot.h>
35 #include <VirtualRobot/XML/RobotIO.h>
59 #include <range/v3/range/conversion.hpp>
60 #include <range/v3/view/filter.hpp>
61 #include <range/v3/view/transform.hpp>
74 const std::string Component::defaultName =
"distance_to_obstacle_costmap_provider";
82 def->required(properties.robotName,
"p.robotName",
"Robot name.");
84 def->optional(properties.costmapParams.binaryGrid,
"p.costmapParams.binaryGrid");
85 def->optional(properties.costmapParams.cellSize,
"p.costmapParams.cellSize");
86 def->optional(properties.costmapParams.sceneBoundsMargin,
87 "p.costmapParams.sceneBoundsMargin");
88 def->optional(properties.costmapBuilderParams.restrictToRooms,
89 "p.costmapBuilderParams.restrictToRooms");
91 def->optional(properties.colModel,
"p.colModel");
92 def->optional(properties.buildSecondCostmapWithSmallerMargins,
93 "p.buildSecondCostmapWithSmallerMargins");
95 def->optional(properties.costmapToExtend,
97 "Name the initial costmap that should be extended. Format is "
98 "`ProviderName`/`EntityName` to reference a costmap in the memory.");
100 properties.costmapSmallerMarginsToExtend,
101 "p.costmapSmallerMarginsToExtend",
102 "Name the initial costmap that should be extended with smaller margins. Format is "
103 "`ProviderName`/`EntityName` to reference a costmap in the memory.");
127 const std::vector<armem::MemoryID>& snapshotIDs)
136 const std::vector<armarx::ObjectID> changedObjectClasses =
141 const std::set<std::string> nonRelevantObjectClasses = {
"KIT",
151 const auto isRelevantClass =
153 {
return nonRelevantObjectClasses.count(objectID.dataset()) == 0; };
155 const std::vector<armarx::ObjectID> relevantObjectClasses =
156 changedObjectClasses | ranges::views::filter(isRelevantClass) | ranges::to_vector;
158 if (relevantObjectClasses.empty())
163 ARMARX_INFO <<
"Relevant object classes changed: " << relevantObjectClasses;
172 std::string& costmapNameWithProvider)
174 ARMARX_INFO <<
"Extending costmap `" << costmapNameWithProvider <<
"`.";
175 const std::vector<std::string> splits =
simox::alg::split(costmapNameWithProvider,
"/");
179 const auto initialCostmap =
185 .name = splits.back(),
188 const auto result = costmapReaderPlugin->
get().query(query);
193 <<
"` is not available yet. Retrying ...";
199 return result.costmap.value();
202 return initialCostmap;
209 std::string& costmapNameWithProvider)
211 if (not costmapNameWithProvider.empty())
213 const auto initialCostmap =
loadCostmap(costmapReaderPlugin, costmapNameWithProvider);
214 const auto costmap = costmapBuilder.
extend(initialCostmap);
220 const auto costmap = costmapBuilder.
create();
228 std::lock_guard g{createCostmapMtx};
232 const std::vector<std::string> primitiveModelIds = [&]() -> std::vector<std::string>
234 if (not properties.primitiveModelIds.empty())
236 const std::vector<std::string> primitiveModelIds =
239 return primitiveModelIds;
245 const auto loadMode = primitiveModelIds.empty()
246 ? VirtualRobot::RobotIO::RobotDescription::eCollisionModel
247 : VirtualRobot::RobotIO::RobotDescription::eStructure;
249 const auto robot = virtualRobotReaderPlugin->get().getRobotWaiting(
254 if (not primitiveModelIds.empty())
257 robot->setPrimitiveApproximationModel(primitiveModelIds);
273 const VirtualRobot::SceneObjectSetPtr obstacles =
277 for (
const auto& objectPoseStaticArticulated : objectPosesStaticArticulated)
280 << objectPoseStaticArticulated.objectID;
282 const auto articulatedObject =
284 objectPoseStaticArticulated.objectID.getClassID().str(),
287 objectPoseStaticArticulated.objectID.instanceName());
290 << objectPoseStaticArticulated.objectID.getClassID().str();
293 *articulatedObject,
Clock::Now(), std::nullopt));
295 std::set<std::string> primitiveIDs;
296 articulatedObject->getPrimitiveApproximationIDs(primitiveIDs);
298 if (articulatedObject->getCollisionModels().empty())
301 <<
"The articualted object `" << articulatedObject->getType() <<
"/"
302 << articulatedObject->getName()
303 <<
"` does not have a collision model. Using primitive model instead.";
307 const std::vector<std::string> usedPrimitiveModelIDs(primitiveIDs.begin(),
309 articulatedObject->setPrimitiveApproximationModel(usedPrimitiveModelIDs);
317 ARMARX_INFO << obstacles->getSize() <<
" objects in the scene";
328 ARMARX_VERBOSE <<
" - " <<
object->getType() <<
"/" <<
object->getName();
337 const auto result = roomReaderPlugin->get().query(query);
339 const auto&
rooms = result.rooms;
341 for (
const auto& room :
rooms)
353 properties.costmapParams,
355 properties.costmapBuilderParams);
358 costmapReaderPlugin, costmapBuilder, properties.costmapToExtend);
362 bool successful = costmapWriterPlugin->get().store(
365 if (properties.buildSecondCostmapWithSmallerMargins)
367 auto costmapBuilderParams = properties.costmapBuilderParams;
368 costmapBuilderParams.collisionModelScaleFactor = Eigen::Vector3f{0.01, 1, 0.01};
373 properties.costmapParams,
375 costmapBuilderParams);
378 costmapReaderPlugin, costmapBuilder, properties.costmapSmallerMarginsToExtend);
380 ARMARX_VERBOSE <<
"Storing costmap with smaller margins in the memory.";
383 costmapWriterPlugin->get().store(
403 return Component::defaultName;
409 return Component::defaultName;