32 #include <ArmarXCore/interface/observers/VariantBase.h>
35 #include <VirtualRobot/MathTools.h>
43 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
46 #include <SimoxUtility/math/convert.h>
50 #include <Ice/ObjectAdapter.h>
57 usingProxy(getProperty<std::string>(
"SimulatorName").getValue());
58 if (getProperty<bool>(
"LoadToMemory"))
60 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
71 bool MMMSimulation::loadMMMFile(
const std::string& filePath,
const std::string& projects,
bool createTrajectoryPlayer,
const Ice::Current&)
80 if (!projects.empty())
82 std::vector<std::string> proj =
armarx::Split(projects,
",;",
true,
true);
84 for (std::string& p : proj)
91 ARMARX_WARNING <<
"ArmarX Package " << p <<
" has not been found!";
165 TrajectoryBasePtr t =
motionData->getJointTrajectory();
175 simulatorPrx = getProxy<SimulatorInterfacePrx>(getProperty<std::string>(
"SimulatorName").getValue());
181 void MMMSimulation::initialize()
183 const std::string name = this->
getName();
184 agentName = getProperty<std::string>(
"AgentName").getValue();
185 const std::string mmmModelFileProject = getProperty<std::string>(
"RobotFileNameProject").getValue();
186 const std::string mmmModelFilePath = getProperty<std::string>(
"RobotFileName").getValue();
187 const std::string mmmRobotNodeSetName = getProperty<std::string>(
"RobotNodeSetName").getValue();
188 const std::string simulatorName = getProperty<std::string>(
"SimulatorName").getValue();
190 modelFileName = std::filesystem::path(mmmModelFilePath).stem();
192 loadMMMFile(getProperty<std::string>(
"MMMFile").getValue(),
"",
false);
195 motionData->setScaling(getProperty<float>(
"Scaling").getValue());
200 Eigen::Vector3f position(getProperty<float>(
"StartPose.x").getValue(), getProperty<float>(
"StartPose.y").getValue(), getProperty<float>(
"StartPose.z").getValue());
201 Eigen::Vector3f orientation(getProperty<float>(
"StartPose.roll").getValue(), getProperty<float>(
"StartPose.pitch").getValue(), getProperty<float>(
"StartPose.yaw").getValue());
202 startPose = simox::math::pos_rpy_to_mat4f(position, orientation);
207 ARMARX_INFO <<
"Added robot " << robotName <<
" to simulator";
209 const std::string robotStateConfigName =
"RobotStateComponent";
212 std::string packageName(
"RobotAPI");
214 std::string appPath = finder.getBinaryDir() +
"/RobotStateComponentRun";
215 pros.push_back(appPath);
219 const std::string robotSateConfPre =
getConfigDomain() +
"." + robotStateConfigName +
".";
220 properties->setProperty(robotSateConfPre +
"AgentName",
agentName);
221 properties->setProperty(robotSateConfPre +
"RobotFileName", mmmModelFilePath);
222 properties->setProperty(robotSateConfPre +
"RobotFileNameProject", mmmModelFileProject);
223 properties->setProperty(robotSateConfPre +
"RobotNodeSetName", mmmRobotNodeSetName);
225 properties->setProperty(robotSateConfPre +
"ObjectName", robotStateConfigName + name);
226 properties->setProperty(
getConfigDomain() +
".RobotStateObserver." +
"ObjectName",
"RobotStateObserver" + name);
227 ARMARX_DEBUG <<
"creating unit " << robotStateConfigName <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
233 if (getProperty<bool>(
"LoadToMemory"))
236 std::string packageName(
"ArmarXSimulation");
238 std::string appPath = finder.getBinaryDir() +
"/SelfLocalizationDynamicSimulationAppRun";
239 pros.push_back(appPath);
243 const std::string localizationConfigName =
"SelfLocalizationDynamicSimulation";
244 const std::string localizationConfPre =
getConfigDomain() +
"." + localizationConfigName +
".";
245 properties->setProperty(localizationConfPre +
"AgentName",
agentName);
246 properties->setProperty(localizationConfPre +
"RobotStateComponentName", robotStateConfigName + name);
247 properties->setProperty(localizationConfPre +
"RobotName", robotName);
248 properties->setProperty(localizationConfPre +
"SimulatorName", simulatorName);
249 properties->setProperty(localizationConfPre +
"ObjectName", localizationConfigName + name);
250 properties->setProperty(localizationConfPre +
"WorkingMemoryName", getProperty<std::string>(
"WorkingMemoryName").
getValue());
251 ARMARX_DEBUG <<
"creating unit " << localizationConfigName <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
256 std::string kinematicUnitConfigName =
"KinematicUnit";
258 const std::string kinematicUnitConfPre =
getConfigDomain() +
"." + kinematicUnitConfigName +
".";
260 properties->setProperty(kinematicUnitConfPre +
"RobotName", robotName);
261 properties->setProperty(kinematicUnitConfPre +
"RobotFileName", mmmModelFilePath);
262 properties->setProperty(kinematicUnitConfPre +
"RobotFileNameProject", mmmModelFileProject);
263 properties->setProperty(kinematicUnitConfPre +
"RobotNodeSetName", mmmRobotNodeSetName);
264 properties->setProperty(kinematicUnitConfPre +
"ObjectName", kinematicUnitConfigName + name);
265 properties->setProperty(kinematicUnitConfPre +
"SimulatorName", simulatorName);
266 ARMARX_DEBUG <<
"creating unit " << kinematicUnitConfigName <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
272 const std::string robotposeUnitConfigName =
"RobotPoseUnit";
274 const std::string robotposeUnitConfPre =
getConfigDomain() +
"." + robotposeUnitConfigName +
".";
276 properties->setProperty(robotposeUnitConfPre +
"RobotName", robotName);
277 properties->setProperty(robotposeUnitConfPre +
"ObjectName", robotposeUnitConfigName + name);
278 properties->setProperty(robotposeUnitConfPre +
"SimulatorProxyName", simulatorName);
279 ARMARX_DEBUG <<
"creating unit " << robotposeUnitConfigName <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
294 if (getProperty<bool>(
"AutoPlay").
getValue())
301 ARMARX_ERROR <<
"Could not load motion as trajectory player could not be not instanciated";
308 Eigen::Vector3f position = simox::math::mat4f_to_pos(
startPose);
309 Eigen::Vector3f orientation = simox::math::mat4f_to_rpy(
startPose);
310 const std::string trajectoryPlayerConfigName =
"TrajectoryPlayer";
311 const std::string trajectoryPlayerConfPre =
getConfigDomain() +
"." + trajectoryPlayerConfigName +
".";
313 properties->setProperty(trajectoryPlayerConfPre +
"KinematicTopicName",
kinematicUnitName);
314 properties->setProperty(trajectoryPlayerConfPre +
"KinematicUnitName",
kinematicUnitName);
315 properties->setProperty(trajectoryPlayerConfPre +
"ObjectName", trajectoryPlayerConfigName +
getName());
316 properties->setProperty(trajectoryPlayerConfPre +
"LoopPlayback",
std::to_string(getProperty<bool>(
"LoopPlayback").getValue()));
317 properties->setProperty(trajectoryPlayerConfPre +
"Offset.x",
std::to_string(position(0)));
318 properties->setProperty(trajectoryPlayerConfPre +
"Offset.y",
std::to_string(position(1)));
319 properties->setProperty(trajectoryPlayerConfPre +
"Offset.z",
std::to_string(position(2)));
320 properties->setProperty(trajectoryPlayerConfPre +
"Offset.roll",
std::to_string(orientation(0)));
321 properties->setProperty(trajectoryPlayerConfPre +
"Offset.pitch",
std::to_string(orientation(1)));
322 properties->setProperty(trajectoryPlayerConfPre +
"Offset.yaw",
std::to_string(orientation(2)));
323 properties->setProperty(trajectoryPlayerConfPre +
"EnableRobotPoseUnit",
"true");
324 properties->setProperty(trajectoryPlayerConfPre +
"RobotPoseUnitName",
robotPoseUnitName);
325 ARMARX_DEBUG <<
"creating unit " << trajectoryPlayerConfigName <<
" using these properties: " << properties->getPropertiesForPrefix(
"");
326 auto trajectoryPlayerComponent = Component::create<TrajectoryPlayer>(properties, trajectoryPlayerConfigName,
getConfigDomain());