20 const WorkingMemoryInterfacePrx& workingMemory,
26 this->robotStateComponent = robotStateComponent;
28 robotStateComponent,
"", {}, VirtualRobot::RobotIO::RobotDescription::eStructure);
29 this->objectInstanceSegment = workingMemory->getObjectInstancesSegment();
34 const AttachObjectToRobotNodeInput& input)
39 ARMARX_WARNING <<
"No object instance with ID '" << input.object.memoryID
40 <<
"' or class '" << input.object.className <<
"' found.";
44 ARMARX_VERBOSE <<
"Attaching object '" << instance->getId() <<
"' (class '"
45 << instance->getMostProbableClass() <<
"')"
46 <<
" to robot node '" << input.robotNodeName <<
"'.";
48 Attachment attachment;
49 attachment.robotNode = input.robotNodeName;
50 if (input.useCurrentPose)
55 if (input.objectOffset)
57 attachment.objectOffset = armarx::PosePtr::dynamicCast(input.objectOffset)->toEigen();
65 const DetachObjectFromRobotNodeInput& detachment)
70 ARMARX_WARNING <<
"No object instance with ID '" << detachment.object.memoryID
71 <<
"' or class '" << detachment.object.className <<
"' found.";
75 if (
auto it = attachments.find(
id); it != attachments.end())
77 ARMARX_VERBOSE <<
"Detaching object '" <<
id <<
"' from robot node '"
78 << it->second.robotNode <<
"'.";
79 attachments.erase(it);
87 std::vector<ObjectInstancePtr>
90 EntityBaseList entities = objectInstanceSegment->getAllEntities();
92 std::vector<ObjectInstancePtr> instances;
93 for (
const auto& entity : entities)
98 instances.push_back(
object);
107 const std::string& frame)
109 if (
auto it = attachments.find(object->getId()); it != attachments.end())
111 return getAttachedObjectPoseInFrame(it->second, frame);
120 ObjectInstanceToRobotNodeAttachments::getAttachedObjectPoseInFrame(
const Attachment& attachment,
121 const std::string& frame)
126 attachment.robotNode,
131 return framed.toGlobalEigen(robot);
135 framed.changeFrame(robot, frame);
136 return framed.toEigen();
141 ObjectInstanceToRobotNodeAttachments::getDetachedObjectPoseInFrame(
ObjectInstancePtr object,
142 const std::string& frame)
144 if (object->getPose()->getFrame() == frame)
146 return object->getPose()->toEigen();
150 auto it = objectPoseCache.find(object->getId());
151 if (it != objectPoseCache.end() && object->hasLocalizationTimestamp())
153 const IceUtil::Time localizationTimestamp =
object->getLocalizationTimestamp();
154 const IceUtil::Time previousTimestamp = it->second.first;
155 if (previousTimestamp >= localizationTimestamp)
158 armarx::FramedPose& pose = it->second.second;
170 const IceUtil::Time ts =
object->hasLocalizationTimestamp()
171 ?
object->getLocalizationTimestamp()
174 armarx::FramedPose pose = *
object->getPose();
181 objectPoseCache[
object->getId()] = std::make_pair(ts, pose);
188 return attachments.count(
id) > 0;
194 if (!
object.memoryID.empty())
196 return object.memoryID;
200 return instance->getId();
211 if (!
object.memoryID.empty())
216 if (instance && instance->getId() ==
object.memoryID)
228 if (instance && instance->getMostProbableClass() ==
object.className)
std::string getFrame() const
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
virtual Eigen::Matrix4f toEigen() const
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
ObjectInstanceToRobotNodeAttachments()
bool isObjectAttached(const std::string &id) const
std::string getMatchingObjectID(const memoryx::ObjectIdOrClass &object)
void attachObjectToRobotNode(const memoryx::AttachObjectToRobotNodeInput &attachment)
void detachObjectFromRobotNode(const memoryx::DetachObjectFromRobotNodeInput &detachment)
std::vector< ObjectInstancePtr > queryObjects()
Get all entities from objectInstanceSegment and cast them to ObjectInstance.
ObjectInstancePtr getMatchingObjectInstance(const memoryx::ObjectIdOrClass &object)
void initFromProxies(const WorkingMemoryInterfacePrx &workingMemory, const armarx::RobotStateComponentInterfacePrx &robotStateComponent)
Set the proxies.
Eigen::Matrix4f getObjectPoseInFrame(ObjectInstancePtr object, const std::string &frame)
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< ObjectInstance > ObjectInstancePtr