37 #include <SimoxUtility/math/pose/pose.h>
43 using namespace MemoryXUtility;
56 memoryx::ObjectInstanceMemorySegmentBasePrx instanceMemory = getWorkingMemory()->getObjectInstancesSegment();
57 std::string objectClassName = in.getObjectClassName();
59 Eigen::Matrix4f transformationOffset = in.getTransformationOffset()->toEigen();
63 VirtualRobot::RobotNodeSetPtr kinematicChain = robot->getRobotNodeSet(in.getAttachToTCPofKinematicChain());
64 VirtualRobot::RobotNodePtr tcp = kinematicChain->getTCP();
71 std::string objectID =
"";
72 if (objectClassName.find(
"/") != std::string::npos)
74 ARMARX_INFO <<
"Attach object '" << objectClassName <<
"' to new ObjectMemory!";
76 armarx::objpose::AttachObjectToRobotNodeInput
input;
79 input.providerName =
"";
80 input.frameName =
"Hand R TCP";
81 input.agentName =
"Armar6";
83 armarx::objpose::AttachObjectToRobotNodeOutput result = getObjectPoseStorage()->attachObjectToRobotNode(
input);
86 ARMARX_WARNING <<
"Failed to attach object '" <<
input.objectID <<
"' to frame '" <<
input.frameName <<
"' of agent '" <<
input.agentName <<
"'.";
92 ARMARX_INFO <<
"Attach object '" << objectClassName <<
"' to old WorkingMemory!";
94 std::string memoryHandName = nameHelper->getArm(in.getSide()).getMemoryHandName();
95 auto objClassBase = getPriorKnowledge()->getObjectClassesSegment()->getObjectClassByName(objectClassName);
102 Eigen::Vector3f placeOrientationAngles = simoxWrapper->getPutdownOrientationRPY();
103 Eigen::Matrix3f orientationVisu = (Eigen::AngleAxisf(placeOrientationAngles(0), Eigen::Vector3f::UnitX())
104 * Eigen::AngleAxisf(placeOrientationAngles(1), Eigen::Vector3f::UnitY())
105 * Eigen::AngleAxisf(placeOrientationAngles(2), Eigen::Vector3f::UnitZ())).toRotationMatrix();
106 objectPose.block<3, 3>(0, 0) = objectPose.block<3, 3>(0, 0) * orientationVisu;
115 if (in.isHandChannelSet())
117 handChannel = in.getHandChannel();
121 ARMARX_INFO <<
"Using memory hand name: " << memoryHandName;
122 std::string handChannelClass = memoryHandName;
124 std::vector<ChannelRefBasePtr> objectInstanceList = getObjectMemoryObserver()->getObjectInstancesByClass(handChannelClass);
125 ARMARX_INFO <<
"found " << objectInstanceList.size() <<
" instances for object " << handChannelClass;
126 if (objectInstanceList.size())
128 handChannel = ChannelRefPtr::dynamicCast(objectInstanceList.front());
132 ARMARX_WARNING <<
"No hand channel defined. Trying to request hand localization.";
134 ARMARX_INFO <<
"Requesting localization for object class '" << handChannelClass;
136 int cycleTimeInMS =
static_cast<int>(1000.0f * 0.2f);
137 int localizationPriority = 50;
138 getObjectMemoryObserver()->requestObjectClassRepeated(handChannelClass, cycleTimeInMS, localizationPriority);
142 bool timeout =
false;
144 while (!isRunningTaskStopped())
146 c.waitForCycleDuration();
148 std::vector<ChannelRefBasePtr> objectInstanceList = getObjectMemoryObserver()->getObjectInstancesByClass(handChannelClass);
149 ARMARX_INFO <<
deactivateSpam(1) <<
"Found " << objectInstanceList.size() <<
" instances for object " << handChannelClass;
151 if (!objectInstanceList.empty())
153 handChannel = ChannelRefPtr::dynamicCast(objectInstanceList.front());
154 if (!handChannel || !handChannel->hasDatafield(
"pose"))
156 ARMARX_WARNING <<
"Unable to cast channel reference or datafield pose does not exists.";
167 double timeElapsed = (now - startTime).toSecondsDouble();
168 timeout = timeElapsed > in.getLocalizationTimeoutInSeconds();
171 ARMARX_WARNING <<
"Could not localize hand '" << handChannelClass <<
"' in "
172 << in.getLocalizationTimeoutInSeconds() <<
" seconds.";
181 objectID = instanceMemory->addObjectInstance(objectClassName, objectClassName,
new LinkedPose(objectPose,
GlobalFrame, sharedRobot), motionModel);
184 if (objectID.empty())
186 ARMARX_ERROR <<
"The output value 'objectID' is empty. It should be either set from the old or the new memory.";
188 out.setNewObjectID(objectID);