32 #include <VirtualRobot/MathTools.h>
40 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
43 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
54 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
55 usingProxy(getProperty<std::string>(
"PriorKnowledgeName").getValue());
56 usingProxy(getProperty<std::string>(
"SimulatorName").getValue());
58 if (getProperty<bool>(
"LocalizeObject").getValue())
60 usingProxy(
"ObjectMemoryObserver");
61 usingProxy(
"ConditionHandler");
77 if (classChannel1 && memoryObserver)
80 memoryObserver->releaseObjectClass(classChannel1);
88 std::stringstream strStr;
90 strStr <<
"SceneModificationType";
97 ARMARX_DEBUG <<
"Checking for property " << strStr.str() <<
"...";
104 mode = getProperty<std::string>(strStr.str()).getValue();
108 ARMARX_DEBUG <<
"Failed to get property " << strStr.str() <<
"...";
117 if (mode ==
"addObject")
121 else if (mode ==
"removeObject")
123 removeObject(suffix);
125 else if (mode ==
"moveObject")
129 else if (mode !=
"none")
142 workingMemoryProxy = getProxy<memoryx::WorkingMemoryInterfacePrx>(
143 getProperty<std::string>(
"WorkingMemoryName").getValue());
144 priorKnowledgeProxy = getProxy<memoryx::PriorKnowledgeInterfacePrx>(
145 getProperty<std::string>(
"PriorKnowledgeName").getValue());
147 getProxy<SimulatorInterfacePrx>(getProperty<std::string>(
"SimulatorName").getValue());
151 for (
int i = 0; i < 10; i++)
153 std::stringstream strStr;
155 checkForConfigs(strStr.str());
160 if (getProperty<bool>(
"LocalizeObject").getValue())
162 std::string objClassName = getProperty<std::string>(
"ObjectClassName").getValue();
167 getProxy<memoryx::ObjectMemoryObserverInterfacePrx>(
"ObjectMemoryObserver");
168 conditionHandler = getProxy<ConditionHandlerInterfacePrx>(
"ConditionHandler");
169 int timeS = getProperty<int>(
"LocalizeObject_seconds").getValue();
170 localizeSingleObject(objClassName, timeS);
175 std::string attachObjectName =
176 getProperty<std::string>(
"AttachObjectToRobot.ObjectName").getValue();
177 std::string attachRobotName =
178 getProperty<std::string>(
"AttachObjectToRobot.RobotName").getValue();
179 std::string attachRobotNodeName =
180 getProperty<std::string>(
"AttachObjectToRobot.RobotNodeName").getValue();
182 if (!attachObjectName.empty() && !attachRobotName.empty() && !attachRobotNodeName.empty())
184 ARMARX_VERBOSE <<
"Attaching " << attachObjectName <<
"to robot " << attachRobotName
185 <<
" at robot node " << attachRobotNodeName;
186 attachObject(attachObjectName, attachRobotName, attachRobotNodeName);
199 std::stringstream ss1, ss2, ss3, ss4, ss5, ss6;
203 ss4 <<
"OrientationRoll";
204 ss5 <<
"OrientationPitch";
205 ss6 <<
"OrientationYaw";
217 float x = getProperty<float>(ss1.str()).getValue();
218 float y = getProperty<float>(ss2.str()).getValue();
219 float z = getProperty<float>(ss3.str()).getValue();
220 float ro = getProperty<float>(ss4.str()).getValue();
221 float pi = getProperty<float>(ss5.str()).getValue();
222 float ya = getProperty<float>(ss6.str()).getValue();
224 Eigen::Vector3f pos = {x, y, z};
226 VirtualRobot::MathTools::rpy2eigen4f(ro,
pi, ya, globalPose);
227 globalPose.block<3, 1>(0, 3) = pos;
234 std::stringstream ss1;
235 ss1 <<
"StaticObject";
243 bool x = getProperty<bool>(ss1.str()).getValue();
250 const std::string& robotName,
251 const std::string& robotNodeName)
253 if (!simulatorPrx->hasObject(objName))
255 ARMARX_ERROR <<
"Object " << objName <<
" is not present in simulator...";
259 if (!simulatorPrx->hasRobot(robotName))
261 ARMARX_ERROR <<
"Robot " << robotName <<
" is not present in simulator...";
265 if (!simulatorPrx->hasRobotNode(robotName, robotNodeName))
267 ARMARX_ERROR <<
"Robot node " << robotNodeName <<
" is not present in simulator...";
271 simulatorPrx->objectGrasped(robotName, robotNodeName, objName);
277 std::stringstream ss1, ss2;
278 ss1 <<
"ObjectClassName";
279 ss2 <<
"ObjectInstanceName";
287 ARMARX_DEBUG <<
"checking for object class property: " << ss1.str()
288 <<
", and instance name:" << ss2.str();
290 std::string objClassName = getProperty<std::string>(ss1.str()).getValue();
291 std::string objInstanceName = getProperty<std::string>(ss2.str()).getValue();
292 ARMARX_DEBUG <<
"adding object class " << objClassName <<
", instance name:" << objInstanceName;
295 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
296 priorKnowledgeProxy->getObjectClassesSegment();
304 memoryx::EntityBasePtr classesEntity = classesSegmentPrx->getEntityByName(objClassName);
308 ARMARX_ERROR <<
"No memory entity found with class name " << objClassName;
316 ARMARX_ERROR <<
"Could not cast entitiy to object class, name: " << objClassName;
323 bool isStatic = getStatic(suffix);
325 if (simulatorPrx->hasObject(objInstanceName))
327 ARMARX_ERROR <<
"Object " << objInstanceName <<
" is already present...";
331 ARMARX_IMPORTANT <<
"Adding Object " << objInstanceName <<
" at :\n" << pose;
332 simulatorPrx->addObject(objectClass, objInstanceName, pose, isStatic);
356 std::stringstream ss1, ss2;
357 ss1 <<
"ObjectClassName";
358 ss2 <<
"ObjectInstanceName";
366 std::string objInstanceName = getProperty<std::string>(ss2.str()).getValue();
367 ARMARX_DEBUG <<
"moving object instance :" << objInstanceName;
372 if (!simulatorPrx->hasObject(objInstanceName))
374 ARMARX_ERROR <<
"Object " << objInstanceName <<
" is not present in simulator...";
378 ARMARX_VERBOSE <<
"Moving object " << objInstanceName <<
" to :\n" << pose;
379 simulatorPrx->setObjectPose(objInstanceName, pose);
389 ARMARX_VERBOSE <<
"Initiating localization of " << objClass <<
" for " << sleepS <<
" seconds";
392 classChannel1 = memoryObserver->requestObjectClassRepeated(
393 objClass, 50, armarx::DEFAULT_VIEWTARGET_PRIORITY);
397 ARMARX_ERROR <<
"Could not find class " << objClass <<
" in prior knowledge";
403 Literal objectLocalizationFinished1(
404 ChannelRefPtr::dynamicCast(classChannel1)->getDataFieldIdentifier(
"localizationFinished"),
407 EventBasePtr e1 =
new EventBase();
408 ConditionIdentifier id1 =
409 conditionHandler->installCondition(EventListenerInterfacePrx::uncheckedCast(getProxy()),
410 objectLocalizationFinished1.
getImpl(),
420 ChannelRefBaseSequence channelRefs = memoryObserver->getObjectInstances(classChannel1);
421 ChannelRefBaseSequence::iterator iter = channelRefs.begin();
424 while (iter != channelRefs.end())
426 ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(*iter);
427 ARMARX_INFO << channelRef->getDataField(
"instanceName");
432 memoryObserver->releaseObjectClass(classChannel1);
433 classChannel1 = NULL;
435 conditionHandler->removeCondition(id1);