27 #include <Ice/ObjectAdapter.h>
29 #include <SimoxUtility/math/convert.h>
30 #include <VirtualRobot/MathTools.h>
37 #include <ArmarXCore/interface/observers/VariantBase.h>
53 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
60 usingProxy(getProperty<std::string>(
"SimulatorName").getValue());
61 if (getProperty<bool>(
"LoadToMemory"))
63 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
77 const std::string& projects,
78 bool createTrajectoryPlayer,
88 if (!projects.empty())
90 std::vector<std::string> proj =
armarx::Split(projects,
",;",
true,
true);
92 for (std::string& p : proj)
99 ARMARX_WARNING <<
"ArmarX Package " << p <<
" has not been found!";
128 <<
". Valid model names are " <<
motionWrapper->getModelNames();
180 TrajectoryBasePtr t =
motionData->getJointTrajectory();
192 getProxy<SimulatorInterfacePrx>(getProperty<std::string>(
"SimulatorName").getValue());
199 MMMSimulation::initialize()
201 const std::string name = this->
getName();
202 agentName = getProperty<std::string>(
"AgentName").getValue();
203 const std::string mmmModelFileProject =
204 getProperty<std::string>(
"RobotFileNameProject").getValue();
205 const std::string mmmModelFilePath = getProperty<std::string>(
"RobotFileName").getValue();
206 const std::string mmmRobotNodeSetName = getProperty<std::string>(
"RobotNodeSetName").getValue();
207 const std::string simulatorName = getProperty<std::string>(
"SimulatorName").getValue();
209 modelFileName = std::filesystem::path(mmmModelFilePath).stem();
211 loadMMMFile(getProperty<std::string>(
"MMMFile").getValue(),
"",
false);
214 motionData->setScaling(getProperty<float>(
"Scaling").getValue());
219 Eigen::Vector3f position(getProperty<float>(
"StartPose.x").getValue(),
220 getProperty<float>(
"StartPose.y").getValue(),
221 getProperty<float>(
"StartPose.z").getValue());
222 Eigen::Vector3f orientation(getProperty<float>(
"StartPose.roll").getValue(),
223 getProperty<float>(
"StartPose.pitch").getValue(),
224 getProperty<float>(
"StartPose.yaw").getValue());
225 startPose = simox::math::pos_rpy_to_mat4f(position, orientation);
226 std::string robotName =
simulatorPrx->addScaledRobotName(
231 ARMARX_INFO <<
"Added robot " << robotName <<
" to simulator";
233 const std::string robotStateConfigName =
"RobotStateComponent";
236 std::string packageName(
"RobotAPI");
238 std::string appPath = finder.getBinaryDir() +
"/RobotStateComponentRun";
239 pros.push_back(appPath);
243 const std::string robotSateConfPre =
getConfigDomain() +
"." + robotStateConfigName +
".";
244 properties->setProperty(robotSateConfPre +
"AgentName",
agentName);
245 properties->setProperty(robotSateConfPre +
"RobotFileName", mmmModelFilePath);
246 properties->setProperty(robotSateConfPre +
"RobotFileNameProject", mmmModelFileProject);
247 properties->setProperty(robotSateConfPre +
"RobotNodeSetName", mmmRobotNodeSetName);
248 properties->setProperty(robotSateConfPre +
"RobotModelScaling",
250 properties->setProperty(robotSateConfPre +
"ObjectName", robotStateConfigName + name);
251 properties->setProperty(
getConfigDomain() +
".RobotStateObserver." +
"ObjectName",
252 "RobotStateObserver" + name);
253 ARMARX_DEBUG <<
"creating unit " << robotStateConfigName
254 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
256 Component::create<RobotStateComponent>(
262 if (getProperty<bool>(
"LoadToMemory"))
265 std::string packageName(
"ArmarXSimulation");
267 std::string appPath = finder.getBinaryDir() +
"/SelfLocalizationDynamicSimulationAppRun";
268 pros.push_back(appPath);
272 const std::string localizationConfigName =
"SelfLocalizationDynamicSimulation";
273 const std::string localizationConfPre =
275 properties->setProperty(localizationConfPre +
"AgentName",
agentName);
276 properties->setProperty(localizationConfPre +
"RobotStateComponentName",
277 robotStateConfigName + name);
278 properties->setProperty(localizationConfPre +
"RobotName", robotName);
279 properties->setProperty(localizationConfPre +
"SimulatorName", simulatorName);
280 properties->setProperty(localizationConfPre +
"ObjectName", localizationConfigName + name);
281 properties->setProperty(localizationConfPre +
"WorkingMemoryName",
282 getProperty<std::string>(
"WorkingMemoryName").
getValue());
283 ARMARX_DEBUG <<
"creating unit " << localizationConfigName
284 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
286 Component::create<SelfLocalizationDynamicSimulation>(
291 std::string kinematicUnitConfigName =
"KinematicUnit";
293 const std::string kinematicUnitConfPre =
296 properties->setProperty(kinematicUnitConfPre +
"RobotName", robotName);
297 properties->setProperty(kinematicUnitConfPre +
"RobotFileName", mmmModelFilePath);
298 properties->setProperty(kinematicUnitConfPre +
"RobotFileNameProject", mmmModelFileProject);
299 properties->setProperty(kinematicUnitConfPre +
"RobotNodeSetName", mmmRobotNodeSetName);
300 properties->setProperty(kinematicUnitConfPre +
"ObjectName",
301 kinematicUnitConfigName + name);
302 properties->setProperty(kinematicUnitConfPre +
"SimulatorName", simulatorName);
303 ARMARX_DEBUG <<
"creating unit " << kinematicUnitConfigName
304 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
306 Component::create<KinematicUnitDynamicSimulation>(
312 const std::string robotposeUnitConfigName =
"RobotPoseUnit";
314 const std::string robotposeUnitConfPre =
317 properties->setProperty(robotposeUnitConfPre +
"RobotName", robotName);
318 properties->setProperty(robotposeUnitConfPre +
"ObjectName",
319 robotposeUnitConfigName + name);
320 properties->setProperty(robotposeUnitConfPre +
"SimulatorProxyName", simulatorName);
321 ARMARX_DEBUG <<
"creating unit " << robotposeUnitConfigName
322 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
324 Component::create<RobotPoseUnitDynamicSimulation>(
339 if (getProperty<bool>(
"AutoPlay").
getValue())
347 <<
"Could not load motion as trajectory player could not be not instanciated";
355 Eigen::Vector3f position = simox::math::mat4f_to_pos(
startPose);
356 Eigen::Vector3f orientation = simox::math::mat4f_to_rpy(
startPose);
357 const std::string trajectoryPlayerConfigName =
"TrajectoryPlayer";
358 const std::string trajectoryPlayerConfPre =
361 properties->setProperty(trajectoryPlayerConfPre +
"KinematicTopicName",
kinematicUnitName);
362 properties->setProperty(trajectoryPlayerConfPre +
"KinematicUnitName",
kinematicUnitName);
363 properties->setProperty(trajectoryPlayerConfPre +
"ObjectName",
364 trajectoryPlayerConfigName +
getName());
365 properties->setProperty(trajectoryPlayerConfPre +
"LoopPlayback",
367 properties->setProperty(trajectoryPlayerConfPre +
"Offset.x",
std::to_string(position(0)));
368 properties->setProperty(trajectoryPlayerConfPre +
"Offset.y",
std::to_string(position(1)));
369 properties->setProperty(trajectoryPlayerConfPre +
"Offset.z",
std::to_string(position(2)));
370 properties->setProperty(trajectoryPlayerConfPre +
"Offset.roll",
372 properties->setProperty(trajectoryPlayerConfPre +
"Offset.pitch",
374 properties->setProperty(trajectoryPlayerConfPre +
"Offset.yaw",
std::to_string(orientation(2)));
375 properties->setProperty(trajectoryPlayerConfPre +
"EnableRobotPoseUnit",
"true");
376 properties->setProperty(trajectoryPlayerConfPre +
"RobotPoseUnitName",
robotPoseUnitName);
377 ARMARX_DEBUG <<
"creating unit " << trajectoryPlayerConfigName
378 <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
379 auto trajectoryPlayerComponent = Component::create<TrajectoryPlayer>(