31#include <SimoxUtility/algorithm/string/string_tools.h>
32#include <VirtualRobot/Robot.h>
33#include <VirtualRobot/VirtualRobot.h>
34#include <VirtualRobot/XML/RobotIO.h>
51 defs->component(simulator);
53 defs->optional(p.cycleTime,
"cycleTime");
54 defs->optional(p.cycleTimeUpdateObjectsInSimulator,
"cycleTimeUpdateObjectList");
55 defs->optional(p.objects,
"objects",
"The objects to (fake) localize.");
76 ARMARX_INFO <<
"Starting `localizeArticulatedObjects` task";
82 "localizeArticulatedObjects");
84 task->setDelayWarningTolerance(100);
90 p.cycleTimeUpdateObjectsInSimulator,
93 taskUpdateObjects->start();
94 taskUpdateObjects->setDelayWarningTolerance(100);
117 return "ArticulatedObjectLocalizerDynamicSimulation";
123 const auto descriptions = articulatedObjectReaderPlugin->get().queryDescriptions(
126 std::unordered_map<std::string, std::shared_ptr<VirtualRobot::Robot>> newKnownObjects;
129 std::unique_lock lck{knownObjectsMtx};
130 std::unordered_map<std::string, std::shared_ptr<VirtualRobot::Robot>> oldKnownObjects =
134 const auto tryRegister = [&](
const std::string& name)
136 ARMARX_DEBUG <<
"Checking element '" << name <<
"' ...";
138 const auto isKnownObject = [&name,
this](
const auto description) ->
bool
140 if (description.name == name)
145 const auto splits = simox::alg::split(description.name,
"/");
146 if (not splits.empty())
148 if (splits.back() == name)
150 ARMARX_DEBUG <<
"Relaxed filter successful: Object description '"
151 << description.name <<
"' matches '" << name;
159 const auto it = std::find_if(descriptions.begin(), descriptions.end(), isKnownObject);
160 if (it == descriptions.end())
162 ARMARX_DEBUG <<
"Element '" << name <<
"' is either a robot or an unknown object";
166 ARMARX_DEBUG <<
"Found articulated object '" << name <<
"'";
169 if (oldKnownObjects.count(name) > 0)
171 newKnownObjects[name] = oldKnownObjects.at(name);
176 const auto robot = VirtualRobot::RobotIO::loadRobot(
178 VirtualRobot::RobotIO::eStructure);
183 <<
"At the moment, only one object per class supported.";
184 robot->setName(robot->getName() +
186 newKnownObjects[name] = robot;
191 const auto robots = simulator->getRobotNames();
192 std::for_each(robots.begin(), robots.end(), tryRegister);
195 std::lock_guard g{knownObjectsMtx};
196 knownObjects = newKnownObjects;
206 .description = {.name = obj.getType(),
208 {
"PriorKnowledgeData"}, obj.getFilename()),
216 .globalPose = Eigen::Isometry3f(obj.getRootNode()->getGlobalPose()),
217 .jointMap = obj.getJointValues(),
218 .proprioception = std::nullopt,
238 std::lock_guard g{knownObjectsMtx};
240 for (
const auto& [name, robot] : knownObjects)
243 const PoseBasePtr poseBase = [
this, &name]() -> PoseBasePtr
247 const auto robotPose = simulator->getRobotPose(name);
260 <<
"No articulatd object pose from simulator for object " << name
265 robot->setGlobalPose(PosePtr::dynamicCast(poseBase)->
toEigen());
267 const auto jointMap = simulator->getRobotJointAngles(name);
268 robot->setJointValues(jointMap);
273 static_cast<std::string
>(
"0");
275 ARMARX_DEBUG <<
"Publishing new state for object `" << name <<
"`, instance id: `"
278 articulatedObjectWriterPlugin->get().store(obj,
true);
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
static std::string getProject(const std::vector< std::string > &projects, const std::string &relativeFilename)
static std::string resolvePath(const std::string &path, bool verbose=true)
Resolves environment variables and home paths and tries to make path absolute.
Brief description of class ArticulatedObjectLocalizerDynamicSimulation.
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
ArticulatedObjectLocalizerDynamicSimulation()
static std::string GetDefaultName()
void onExitComponent() override
std::string getDefaultName() const override
Retrieve default name of component.
Default component property definition container.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
armarx::armem::robot_state::Robot ArticulatedObject
armarx::core::time::DateTime Time
This file offers overloads of toIce() and fromIce() functions for STL container types.
armem::articulated_object::ArticulatedObject convert(const VirtualRobot::Robot &obj, const armem::Time ×tamp)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Eigen::Vector3f toEigen(const pcl::PointXYZ &pt)