72 addPlugin(humanPersonInstanceReaderPlugin);
73 addPlugin(navigationHumanPoseReaderPlugin);
78 const std::string Component::defaultName =
"social_cost_map";
100 def->optional(properties.robotName,
"p.robotName",
"");
101 def->optional(properties.human.providerName,
"p.human.providerName",
"");
102 def->optional(properties.human.naviProviderName,
"p.human.naviProviderName",
"");
105 properties.taskPeriodMs,
"p.taskPeriodMs",
"Period in ms for updating the costmap.");
106 def->optional(properties.enableHumanPoseReader,
107 "p.enableHumanPoseReader",
108 "Enable human pose reader");
109 def->optional(properties.enableHumanPersonInstanceReader,
110 "p.enableHumanPersonInstanceReader",
111 "Enable human person instance reader");
112 def->optional(properties.enableNavigationHumanPoseReader,
113 "p.enableNavigationHumanPoseReader",
114 "Enable navigation human pose reader");
115 def->optional(properties.restrictToRooms,
117 "Restrict considered objects to those inside the given rooms.");
118 def->optional(properties.roomNames,
120 "Comma separated list of room names to restrict considered objects to.");
147 std::vector<armarx::navigation::algorithms::Room>
rooms;
148 if (properties.restrictToRooms)
150 const std::vector<std::string> roomNames =
151 simox::alg::split(properties.roomNames,
",",
true);
155 .providerName = std::nullopt, .timestamp =
timestamp};
157 const auto result = navigationRoomReaderPlugin->get().query(query);
161 ARMARX_INFO <<
"Failed to obtain rooms from navigation memory. Reason: "
162 << result.errorMessage;
166 for (
const auto& roomName : roomNames)
168 auto it = ranges::find(
171 if (it != result.rooms.end())
173 rooms.push_back(*it);
178 <<
" not found in navigation memory.";
188 objectPoses, VirtualRobot::ObjectIO::ObjectDescription::eCollisionModel);
191 objects = std::make_shared<VirtualRobot::SceneObjectSet>();
193 for (
const auto&
object : objectsAll->getSceneObjects())
195 const Eigen::Vector3f global_P_obj =
object->getGlobalPosition();
197 if (not object->getCollisionModel())
200 <<
" has no collision model. Skipping.";
204 if (not properties.restrictToRooms)
206 objects->addSceneObject(
object);
210 for (
const auto& room :
rooms)
212 if (room.isInside(global_P_obj,
true))
214 objects->addSceneObject(
object);
219 ARMARX_INFO <<
"Number of objects considered for costmap: "
220 << objects->getSceneObjects().size();
224 this, &Component::visualizeOnce, properties.taskPeriodMs,
"runningTask");
229 periodicTask->start();
243 Component::visualizeOnce()
245 const auto debugObserverLogCb =
253 const auto makeSwCb = [&](
const std::string& name)
254 {
return [=](
const armarx::Duration& duration) { debugObserverLogCb(name, duration); }; };
258 std::vector<Eigen::Vector3f> humanPositions;
262 if (properties.enableHumanPoseReader)
265 .providerName = properties.human.providerName,
269 const auto humanPoseResult = humanPoseReaderPlugin->get().query(query);
271 if (not humanPoseResult)
274 << humanPoseResult.errorMessage;
279 for (
const auto& humanPose : humanPoseResult.humanPoses)
284 humanPositions.push_back(meanPos.value());
288 ARMARX_INFO <<
"Found " << humanPoseResult.humanPoses.size()
289 <<
" humans in human pose memory.";
294 if(properties.enableHumanPersonInstanceReader)
296 const armarx::armem::human::client::PersonInstanceReader::Query query{
301 const auto result = humanPersonInstanceReaderPlugin->get().query(query);
305 ARMARX_INFO <<
"Failed to obtain human person instances from memory. Reason: "
306 << result.errorMessage;
311 ARMARX_INFO <<
"Found " << result.personInstances.size()
312 <<
" human persons in human person instance memory.";
314 for (
const auto& person : result.personInstances)
316 humanPositions.emplace_back(person.globalPose.translation());
321 if (properties.enableNavigationHumanPoseReader)
324 const armarx::navigation::memory::client::human::Reader::Query queryNavigationHumans{
325 .providerName = properties.human.naviProviderName,
329 const auto resultNavi =
330 navigationHumanPoseReaderPlugin->get().queryHumans(queryNavigationHumans);
334 ARMARX_INFO <<
"Failed to obtain humans from navigation memory. Reason: "
335 << resultNavi.errorMessage;
339 if (resultNavi.humans.empty())
344 ARMARX_INFO <<
"Found " << resultNavi.humans.size() <<
" humans in navigation memory.";
346 for (
const auto& human : resultNavi.humans)
348 humanPositions.emplace_back(
conv::to3D(human.pose.translation()));
352 ARMARX_INFO <<
"Total number of humans considered: " << humanPositions.size();
362 SocialCostmapBuilder socialCostmapBuilder(
364 armarx::navigation::algorithms::Costmap::Parameters{.binaryGrid =
false,
369 const std::vector<navigation::core::Pose2D> humanPoses =
371 ranges::views::transform(
372 [](
const Eigen::Vector3f& humanPosition)
374 return Eigen::Isometry2f{
375 Eigen::Translation2f(humanPosition.x(), humanPosition.y())};
381 armarx::core::time::ScopedStopWatch sw(makeSwCb(
"platform"));
383 auto costmapPlatform =
387 const float intimateZoneCostTh = 0.6f;
390 const Eigen::Matrix<bool, -1, -1> mask =
391 (costmapPlatform.getMutableGrid().array() < intimateZoneCostTh);
392 costmapPlatform.getMutableMask().emplace(mask);
394 armarx::core::time::ScopedStopWatch sw2(makeSwCb(
"platform_storing"));
396 costmapWriterPlugin->get().store(
408 return Component::defaultName;
414 return Component::defaultName;
SceneBounds computeSceneBounds(const VirtualRobot::SceneObjectSetPtr &obstacles, const std::vector< VirtualRobot::RobotPtr > &articulatedObjects, const SceneBounds &init, const std::vector< Room > &rooms, const float margin, const bool restrictToRooms)