33 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
35 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
43 #include <VirtualRobot/MathTools.h>
52 usingProxy(getProperty<std::string>(
"WorkingMemoryName").getValue());
53 usingProxy(getProperty<std::string>(
"PriorKnowledgeName").getValue());
54 usingProxy(getProperty<std::string>(
"SimulatorName").getValue());
56 if (getProperty<bool>(
"LocalizeObject").getValue())
58 usingProxy(
"ObjectMemoryObserver");
59 usingProxy(
"ConditionHandler");
72 if (classChannel1 && memoryObserver)
75 memoryObserver->releaseObjectClass(classChannel1);
82 std::stringstream strStr;
84 strStr <<
"SceneModificationType";
91 ARMARX_DEBUG <<
"Checking for property " << strStr.str() <<
"...";
98 mode = getProperty<std::string>(strStr.str()).getValue();
102 ARMARX_DEBUG <<
"Failed to get property " << strStr.str() <<
"...";
111 if (mode ==
"addObject")
115 else if (mode ==
"removeObject")
117 removeObject(suffix);
119 else if (mode ==
"moveObject")
123 else if (mode !=
"none")
135 workingMemoryProxy = getProxy<memoryx::WorkingMemoryInterfacePrx>(getProperty<std::string>(
"WorkingMemoryName").getValue());
136 priorKnowledgeProxy = getProxy<memoryx::PriorKnowledgeInterfacePrx>(getProperty<std::string>(
"PriorKnowledgeName").getValue());
137 simulatorPrx = getProxy<SimulatorInterfacePrx>(getProperty<std::string>(
"SimulatorName").getValue());
141 for (
int i = 0; i < 10; i++)
143 std::stringstream strStr;
145 checkForConfigs(strStr.str());
150 if (getProperty<bool>(
"LocalizeObject").getValue())
152 std::string objClassName = getProperty<std::string>(
"ObjectClassName").getValue();
156 memoryObserver = getProxy<memoryx::ObjectMemoryObserverInterfacePrx>(
"ObjectMemoryObserver");
157 conditionHandler = getProxy<ConditionHandlerInterfacePrx>(
"ConditionHandler");
158 int timeS = getProperty<int>(
"LocalizeObject_seconds").getValue();
159 localizeSingleObject(objClassName, timeS);
164 std::string attachObjectName = getProperty<std::string>(
"AttachObjectToRobot.ObjectName").getValue();
165 std::string attachRobotName = getProperty<std::string>(
"AttachObjectToRobot.RobotName").getValue();
166 std::string attachRobotNodeName = getProperty<std::string>(
"AttachObjectToRobot.RobotNodeName").getValue();
168 if (!attachObjectName.empty() && !attachRobotName.empty() && !attachRobotNodeName.empty())
170 ARMARX_VERBOSE <<
"Attaching " << attachObjectName <<
"to robot " << attachRobotName <<
" at robot node " << attachRobotNodeName;
171 attachObject(attachObjectName, attachRobotName, attachRobotNodeName);
183 std::stringstream ss1, ss2, ss3, ss4, ss5, ss6;
187 ss4 <<
"OrientationRoll";
188 ss5 <<
"OrientationPitch";
189 ss6 <<
"OrientationYaw";
201 float x = getProperty<float>(ss1.str()).getValue();
202 float y = getProperty<float>(ss2.str()).getValue();
203 float z = getProperty<float>(ss3.str()).getValue();
204 float ro = getProperty<float>(ss4.str()).getValue();
205 float pi = getProperty<float>(ss5.str()).getValue();
206 float ya = getProperty<float>(ss6.str()).getValue();
208 Eigen::Vector3f pos = {x, y, z};
210 VirtualRobot::MathTools::rpy2eigen4f(ro,
pi, ya, globalPose);
211 globalPose.block<3, 1>(0, 3) = pos;
217 std::stringstream ss1;
218 ss1 <<
"StaticObject";
226 bool x = getProperty<bool>(ss1.str()).getValue();
233 if (!simulatorPrx->hasObject(objName))
235 ARMARX_ERROR <<
"Object " << objName <<
" is not present in simulator...";
239 if (!simulatorPrx->hasRobot(robotName))
241 ARMARX_ERROR <<
"Robot " << robotName <<
" is not present in simulator...";
245 if (!simulatorPrx->hasRobotNode(robotName, robotNodeName))
247 ARMARX_ERROR <<
"Robot node " << robotNodeName <<
" is not present in simulator...";
251 simulatorPrx->objectGrasped(robotName, robotNodeName, objName);
256 std::stringstream ss1, ss2;
257 ss1 <<
"ObjectClassName";
258 ss2 <<
"ObjectInstanceName";
266 ARMARX_DEBUG <<
"checking for object class property: " << ss1.str() <<
", and instance name:" << ss2.str();
268 std::string objClassName = getProperty<std::string>(ss1.str()).getValue();
269 std::string objInstanceName = getProperty<std::string>(ss2.str()).getValue();
270 ARMARX_DEBUG <<
"adding object class " << objClassName <<
", instance name:" << objInstanceName;
273 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx = priorKnowledgeProxy->getObjectClassesSegment();
281 memoryx::EntityBasePtr classesEntity = classesSegmentPrx->getEntityByName(objClassName);
285 ARMARX_ERROR <<
"No memory entity found with class name " << objClassName;
293 ARMARX_ERROR <<
"Could not cast entitiy to object class, name: " << objClassName;
300 bool isStatic = getStatic(suffix);
302 if (simulatorPrx->hasObject(objInstanceName))
304 ARMARX_ERROR <<
"Object " << objInstanceName <<
" is already present...";
308 ARMARX_IMPORTANT <<
"Adding Object " << objInstanceName <<
" at :\n" << pose;
309 simulatorPrx->addObject(objectClass, objInstanceName, pose, isStatic);
331 std::stringstream ss1, ss2;
332 ss1 <<
"ObjectClassName";
333 ss2 <<
"ObjectInstanceName";
341 std::string objInstanceName = getProperty<std::string>(ss2.str()).getValue();
342 ARMARX_DEBUG <<
"moving object instance :" << objInstanceName;
347 if (!simulatorPrx->hasObject(objInstanceName))
349 ARMARX_ERROR <<
"Object " << objInstanceName <<
" is not present in simulator...";
353 ARMARX_VERBOSE <<
"Moving object " << objInstanceName <<
" to :\n" << pose;
354 simulatorPrx->setObjectPose(objInstanceName, pose);
364 ARMARX_VERBOSE <<
"Initiating localization of " << objClass <<
" for " << sleepS <<
" seconds";
367 classChannel1 = memoryObserver->requestObjectClassRepeated(objClass, 50, armarx::DEFAULT_VIEWTARGET_PRIORITY);
371 ARMARX_ERROR <<
"Could not find class " << objClass <<
" in prior knowledge";
377 Literal objectLocalizationFinished1(ChannelRefPtr::dynamicCast(classChannel1)->getDataFieldIdentifier(
"localizationFinished"),
"equals",
Literal::createParameterList(
true));
378 EventBasePtr e1 =
new EventBase();
379 ConditionIdentifier id1 = conditionHandler->installCondition(EventListenerInterfacePrx::uncheckedCast(getProxy()), objectLocalizationFinished1.
getImpl(), e1,
true,
false, {});
385 ChannelRefBaseSequence channelRefs = memoryObserver->getObjectInstances(classChannel1);
386 ChannelRefBaseSequence::iterator iter = channelRefs.begin();
389 while (iter != channelRefs.end())
391 ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(*iter);
392 ARMARX_INFO << channelRef->getDataField(
"instanceName");
397 memoryObserver->releaseObjectClass(classChannel1);
398 classChannel1 = NULL;
400 conditionHandler->removeCondition(id1);