25 #include <SimoxUtility/math/pose/pose.h>
26 #include <VirtualRobot/RobotNodeSet.h>
41 using namespace MemoryXUtility;
44 AddAndAttachObjectInWorkingMemory::SubClassRegistry
56 memoryx::ObjectInstanceMemorySegmentBasePrx instanceMemory =
57 getWorkingMemory()->getObjectInstancesSegment();
58 std::string objectClassName = in.getObjectClassName();
60 Eigen::Matrix4f transformationOffset = in.getTransformationOffset()->toEigen();
64 VirtualRobot::RobotNodeSetPtr kinematicChain =
65 robot->getRobotNodeSet(in.getAttachToTCPofKinematicChain());
66 VirtualRobot::RobotNodePtr tcp = kinematicChain->getTCP();
73 std::string objectID =
"";
74 if (objectClassName.find(
"/") != std::string::npos)
76 ARMARX_INFO <<
"Attach object '" << objectClassName <<
"' to new ObjectMemory!";
78 armarx::objpose::AttachObjectToRobotNodeInput
input;
81 input.providerName =
"";
82 input.frameName =
"Hand R TCP";
83 input.agentName =
"Armar6";
86 simox::math::pose(Eigen::AngleAxisf(
M_PI, Eigen::Vector3f::UnitZ()))));
87 armarx::objpose::AttachObjectToRobotNodeOutput result =
88 getObjectPoseStorage()->attachObjectToRobotNode(
input);
92 <<
input.frameName <<
"' of agent '" <<
input.agentName <<
"'.";
98 ARMARX_INFO <<
"Attach object '" << objectClassName <<
"' to old WorkingMemory!";
100 std::string memoryHandName = nameHelper->getArm(in.getSide()).getMemoryHandName();
102 getPriorKnowledge()->getObjectClassesSegment()->getObjectClassByName(objectClassName);
111 Eigen::Vector3f placeOrientationAngles = simoxWrapper->getPutdownOrientationRPY();
113 (Eigen::AngleAxisf(placeOrientationAngles(0), Eigen::Vector3f::UnitX()) *
114 Eigen::AngleAxisf(placeOrientationAngles(1), Eigen::Vector3f::UnitY()) *
115 Eigen::AngleAxisf(placeOrientationAngles(2), Eigen::Vector3f::UnitZ()))
117 objectPose.block<3, 3>(0, 0) = objectPose.block<3, 3>(0, 0) * orientationVisu;
126 if (in.isHandChannelSet())
128 handChannel = in.getHandChannel();
132 ARMARX_INFO <<
"Using memory hand name: " << memoryHandName;
133 std::string handChannelClass = memoryHandName;
135 std::vector<ChannelRefBasePtr> objectInstanceList =
136 getObjectMemoryObserver()->getObjectInstancesByClass(handChannelClass);
137 ARMARX_INFO <<
"found " << objectInstanceList.size() <<
" instances for object "
139 if (objectInstanceList.size())
141 handChannel = ChannelRefPtr::dynamicCast(objectInstanceList.front());
145 ARMARX_WARNING <<
"No hand channel defined. Trying to request hand localization.";
147 ARMARX_INFO <<
"Requesting localization for object class '" << handChannelClass;
149 int cycleTimeInMS =
static_cast<int>(1000.0f * 0.2f);
150 int localizationPriority = 50;
151 getObjectMemoryObserver()->requestObjectClassRepeated(
152 handChannelClass, cycleTimeInMS, localizationPriority);
156 bool timeout =
false;
158 while (!isRunningTaskStopped())
160 c.waitForCycleDuration();
162 std::vector<ChannelRefBasePtr> objectInstanceList =
163 getObjectMemoryObserver()->getObjectInstancesByClass(handChannelClass);
165 <<
" instances for object " << handChannelClass;
167 if (!objectInstanceList.empty())
169 handChannel = ChannelRefPtr::dynamicCast(objectInstanceList.front());
170 if (!handChannel || !handChannel->hasDatafield(
"pose"))
172 ARMARX_WARNING <<
"Unable to cast channel reference or datafield pose "
184 double timeElapsed = (now - startTime).toSecondsDouble();
185 timeout = timeElapsed > in.getLocalizationTimeoutInSeconds();
188 ARMARX_WARNING <<
"Could not localize hand '" << handChannelClass <<
"' in "
189 << in.getLocalizationTimeoutInSeconds() <<
" seconds.";
200 instanceMemory->addObjectInstance(objectClassName,
206 if (objectID.empty())
208 ARMARX_ERROR <<
"The output value 'objectID' is empty. It should be either set from the "
209 "old or the new memory.";
211 out.setNewObjectID(objectID);