26 #include <VirtualRobot/SceneObjectSet.h>
47 const std::string Component::defaultName =
"dynamic_scene_provider";
52 addPlugin(laserScannerFeaturesReaderPlugin);
57 addPlugin(laserScannerFeaturesWriterPlugin);
81 properties.taskPeriodMs,
"p.taskPeriodMs",
"Update rate of the running task.");
83 def->optional(properties.laserScannerFeatures.enabled,
84 "p.laserScannerFeatures.enabled",
85 "Whether laser scanner features are used.");
86 def->optional(properties.laserScannerFeatures.providerName,
87 "p.laserScannerFeatures.providerName",
89 def->optional(properties.laserScannerFeatures.name,
"p.laserScannerFeatures.name",
"");
91 def->required(properties.robot.name,
"p.robot.name",
"");
93 def->optional(properties.occupancyGrid.providerName,
"p.occupancyGrid.providerName",
"");
94 def->optional(properties.occupancyGrid.name,
"p.occupancyGrid.name",
"");
96 properties.occupancyGrid.freespaceThreshold,
"p.occupancyGrid.freespaceThreshold",
"");
98 properties.occupancyGrid.occupiedThreshold,
"p.occupancyGrid.occupiedThreshold",
"");
101 properties.humanPoses.enabled,
"p.humanPoses.enabled",
"Whether human poses are used.");
102 def->optional(properties.humanPoses.providerName,
"p.humanPoses.providerName",
"");
151 robot = virtualRobotReaderPlugin->get().getRobotWaiting(properties.robot.name);
152 if (robot !=
nullptr)
161 humanTracker.
reset();
164 this, &Component::runPeriodically, properties.taskPeriodMs,
false,
"runningTask");
182 return Component::defaultName;
188 return Component::defaultName;
192 Component::runPeriodically()
194 const auto logDuration = [
this](
const std::string& name,
const Duration& duration)
197 const auto makeSWlog = [&](
const std::string& name)
198 {
return [=](
const Duration& duration) { logDuration(name, duration); }; };
212 ARMARX_CHECK(virtualRobotReaderPlugin->get().synchronizeRobot(*robot, timestamp));
213 const core::Pose global_T_robot(robot->getGlobalPose());
215 ARMARX_VERBOSE <<
"Robot position: " << global_T_robot.translation().head<2>();
222 const std::vector<armem::human::HumanPose> humanPoses = [&]
224 if (!properties.humanPoses.enabled)
226 return std::vector<armem::human::HumanPose>{};
232 const armem::human::client::Reader::Query humanPoseQuery{
233 .providerName = properties.humanPoses.providerName,
234 .timestamp = timestamp,
237 const armem::human::client::Reader::Result humanPoseResult =
238 humanPoseReaderPlugin->get().query(humanPoseQuery);
241 << humanPoseResult.errorMessage;
243 ARMARX_VERBOSE << humanPoseResult.humanPoses.size() <<
" humans in the scene.";
245 return humanPoseResult.humanPoses;
252 const memory::LaserScannerFeatures laserFeatures = [&]
254 if (!properties.laserScannerFeatures.enabled)
256 return memory::LaserScannerFeatures{};
262 const memory::client::laser_scanner_features::Reader::Query laserFeaturesQuery{
263 .providerName = properties.laserScannerFeatures.providerName,
264 .name = properties.laserScannerFeatures.name,
265 .timestamp = timestamp};
267 const memory::client::laser_scanner_features::Reader::Result laserFeaturesResult =
268 laserScannerFeaturesReaderPlugin->get().queryData(laserFeaturesQuery);
271 << laserFeaturesResult.errorMessage;
273 ARMARX_VERBOSE << laserFeaturesResult.features.size() <<
" clusters/features";
276 <<
"We request the merged instance with only one result";
278 return laserFeaturesResult.features.front();
399 if (properties.humanPoses.enabled)
403 ARMARX_VERBOSE <<
"Running human tracker with camera measurements";
404 humanTracker.
update(human::HumanTracker::CameraMeasurement{.detectionTime = timestamp,
405 .humanPoses = humanPoses});
410 const std::vector<memory::LaserScannerFeature> unusedFeatures = [&]
412 if (!properties.laserScannerFeatures.enabled)
414 return std::vector<memory::LaserScannerFeature>{};
418 makeSWlog(
"dynamic_scene.human_tracker.laserscanner"));
420 ARMARX_VERBOSE <<
"Running human tracker with lasersensor measurements";
422 return humanTracker.
update(human::HumanTracker::LaserMeasurement{
423 .detectionTime = timestamp, .clusters = laserFeatures.features});
440 if (not humans.empty())
443 humanWriterPlugin->get().store(humans,
getName(), timestamp);
446 if (not unusedFeatures.empty())
449 <<
" laser scanner features not associated with humans";
451 laserScannerFeaturesWriterPlugin->get().store(
452 memory::LaserScannerFeatures{.frame =
"global",
454 .features = unusedFeatures},