31 #include <SimoxUtility/algorithm/string/string_tools.h>
32 #include <VirtualRobot/Robot.h>
33 #include <VirtualRobot/VirtualRobot.h>
34 #include <VirtualRobot/XML/RobotIO.h>
50 defs->component(simulator);
52 defs->optional(p.cycleTime,
"cycleTime");
53 defs->optional(p.cycleTimeUpdateObjectsInSimulator,
"cycleTimeUpdateObjectList");
54 defs->optional(p.objects,
"objects",
"The objects to (fake) localize.");
75 ARMARX_INFO <<
"Starting `localizeArticulatedObjects` task";
81 "localizeArticulatedObjects");
83 task->setDelayWarningTolerance(100);
89 p.cycleTimeUpdateObjectsInSimulator,
92 taskUpdateObjects->start();
93 taskUpdateObjects->setDelayWarningTolerance(100);
110 return "ArticulatedObjectLocalizerDynamicSimulation";
116 const auto descriptions = articulatedObjectReaderPlugin->get().queryDescriptions(
119 std::unordered_map<std::string, std::shared_ptr<VirtualRobot::Robot>> newKnownObjects;
122 std::unique_lock lck{knownObjectsMtx};
123 std::unordered_map<std::string, std::shared_ptr<VirtualRobot::Robot>> oldKnownObjects =
127 const auto tryRegister = [&](
const std::string& name)
129 ARMARX_DEBUG <<
"Checking element '" << name <<
"' ...";
131 const auto isKnownObject = [&name,
this](
const auto description) ->
bool
133 if (description.name == name)
139 if (not splits.empty())
141 if (splits.back() == name)
143 ARMARX_DEBUG <<
"Relaxed filter successful: Object description '"
144 << description.name <<
"' matches '" << name;
152 const auto it = std::find_if(descriptions.begin(), descriptions.end(), isKnownObject);
153 if (it == descriptions.end())
155 ARMARX_DEBUG <<
"Element '" << name <<
"' is either a robot or an unknown object";
159 ARMARX_DEBUG <<
"Found articulated object '" << name <<
"'";
162 if (oldKnownObjects.count(name) > 0)
164 newKnownObjects[name] = oldKnownObjects.at(name);
169 const auto robot = VirtualRobot::RobotIO::loadRobot(
171 VirtualRobot::RobotIO::eStructure);
176 <<
"At the moment, only one object per class supported.";
177 robot->setName(robot->getName() +
179 newKnownObjects[name] = robot;
184 const auto robots = simulator->getRobotNames();
185 std::for_each(
robots.begin(),
robots.end(), tryRegister);
188 std::lock_guard g{knownObjectsMtx};
189 knownObjects = newKnownObjects;
201 {
"PriorKnowledgeData"}, obj.getFilename()),
208 .timestamp = timestamp,
209 .globalPose = Eigen::Isometry3f(obj.getRootNode()->getGlobalPose()),
210 .jointMap = obj.getJointValues(),
211 .proprioception = std::nullopt,
213 .timestamp = timestamp,
231 std::lock_guard g{knownObjectsMtx};
233 for (
const auto& [name, robot] : knownObjects)
236 const PoseBasePtr poseBase = [
this, &name]() -> PoseBasePtr
240 const auto robotPose = simulator->getRobotPose(name);
253 <<
"No articulatd object pose from simulator for object " << name
258 robot->setGlobalPose(PosePtr::dynamicCast(poseBase)->
toEigen());
260 const auto jointMap = simulator->getRobotJointAngles(name);
261 robot->setJointValues(jointMap);
266 static_cast<std::string
>(
"0");
268 ARMARX_DEBUG <<
"Publishing new state for object `" << name <<
"`, instance id: `"
271 articulatedObjectWriterPlugin->get().store(obj);