31 #include <MemoryX/interface/core/EntityBase.h>
32 #include <MemoryX/interface/memorytypes/MemoryEntities.h>
33 #include <MemoryX/interface/memorytypes/MemorySegments.h>
41 virtual public PersistentObjectInstanceSegmentBase
49 ObjectInstanceBasePtr
getObjectInstanceById(const ::std::string&
id, const ::Ice::Current& = Ice::emptyCurrent)
const override
51 return ObjectInstanceBasePtr::dynamicCast(getEntityById(
id));
54 ObjectInstanceBasePtr
getObjectInstanceByName(const ::std::string& name, const ::Ice::Current& = Ice::emptyCurrent)
const override
56 return ObjectInstanceBasePtr::dynamicCast(getEntityByName(name));
61 ObjectInstanceList result;
63 classList.push_back(className);
64 return getObjectInstancesByClassList(classList,
c);
69 ObjectInstanceList result;
70 const EntityBaseList entityList = getEntitiesByAttrValueList(
"classes", classList);
72 for (EntityBaseList::const_iterator it = entityList.begin(); it != entityList.end(); ++it)
74 const ObjectInstanceBasePtr instance = ObjectInstanceBasePtr::dynamicCast(*it);
78 result.push_back(instance);
85 void setNewMotionModel(const ::std::string& entityId, const ::memoryx::MotionModelInterfacePtr& newMotionModel, const ::Ice::Current& = Ice::emptyCurrent)
override
87 throw armarx::LocalException() <<
"This function does not work on the persistent instance segment since the motion model is only temporary!";
91 ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(getObjectInstanceById(entityId));
92 MotionModelInterfacePtr oldMotionModel =
object->getMotionModel();
96 armarx::LinkedPoseBasePtr oldPose = oldMotionModel->getPoseAtLastLocalisation();
100 newMotionModel->setPoseAtLastLocalisation(oldPose, NULL, NULL);
104 ARMARX_ERROR_S <<
"Object has an old motion model, but that motion model has no pose.";
109 ARMARX_WARNING_S <<
"Object didn't have a motion model before, this may cause problems";
112 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(newMotionModel));
116 void setObjectPose(
const std::string& entityId,
const armarx::LinkedPoseBasePtr& objectPose, const ::Ice::Current& = Ice::emptyCurrent)
override
118 ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(getObjectInstanceById(entityId));
121 object->setPosition(position);
123 object->setOrientation(orientation);
129 object->getMotionModel()->setPoseAtLastLocalisation(objectPose, NULL, NULL);
134 ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(getObjectInstanceById(entityId));
137 object->setPosition(position);
140 object->setOrientation(orientation);
143 if (object->getMotionModel())
145 ARMARX_WARNING_S <<
object->getName() <<
" has a motion model - You should not call setObjectPoseWithoutMotionModel() when a motion model is set. Use set setObjectPose() instead!";
150 std::string
addObjectInstance(
const std::string& instanceName,
const std::string& className,
const armarx::LinkedPoseBasePtr& objectPose,
151 const ::memoryx::MotionModelInterfacePtr& motionModel, const ::Ice::Current& = Ice::emptyCurrent)
override
155 object->setPosition(position);
157 object->setOrientation(orientation);
158 FloatVector mean = {objectPose->position->x, objectPose->position->y, objectPose->position->z};
161 object->setPositionUncertainty(uncertainty);
162 object->addClass(className, 1.0);
163 object->setExistenceCertainty(1.0);
165 motionModel->setPoseAtLastLocalisation(objectPose, NULL, NULL);
166 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(motionModel));
168 return addEntity(
object);