39 ObjectInstanceMemorySegmentBase::ObjectInstanceMemorySegmentBase(),
40 matchThreshold(matchThreshold),
41 matchByClass(matchByClass)
47 const Ice::Current&)
const
49 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(
getEntityById(
id));
53 ARMARX_WARNING_S <<
"Entity with id " <<
id <<
" is not of type ObjectInstance!"
62 const Ice::Current&)
const
64 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(
getEntityByName(name));
68 ARMARX_WARNING_S <<
"Entity with name " << name <<
" is not of type ObjectInstance!"
77 const Ice::Current&
c)
const
80 classList.push_back(className);
86 const ::Ice::Current&
c)
const
88 ObjectInstanceList result;
93 ObjectInstanceBasePtr inst = ObjectInstanceBasePtr::dynamicCast(it->second);
94 ClassProbabilityMap instClasses = inst->getClasses();
96 for (NameList::const_iterator itCls = classList.begin(); itCls != classList.end();
99 if (instClasses.count(*itCls))
101 result.push_back(inst);
110 ObjectInstanceBasePtr
112 const ObjectInstanceBasePtr& objectInstance,
113 const ::Ice::Current&
c)
const
117 Eigen::MatrixXd i(3, 3);
119 ARMARX_DEBUG <<
"Position: " << objectInstance->getPositionBase()->output()
120 <<
" mean: " << objectInstance->getPositionUncertainty()->getMean();
127 double maxProb = -FLT_MAX;
128 std::string matchingId =
"";
129 std::string instanceName = objectInstance->getName();
130 const std::string mostProbableClass = objectInstance->getMostProbableClass();
143 if (!matchByClass && current->getName() != instanceName)
147 else if (matchByClass && mostProbableClass != current->getMostProbableClass())
153 MultivariateNormalDistributionBasePtr uncertainty =
154 current->getPositionUncertainty();
159 << current->getName()
160 <<
" is nullptr! Creating default uncertainty";
163 current->setPositionUncertainty(uncertainty);
189 matchingId = current->getId();
194 if (matchingId.empty())
197 <<
"Could not find any match for " << objectInstance->getName()
198 <<
" with most probable class: " << objectInstance->getName();
202 if (maxProb >= matchThreshold)
205 return ObjectInstanceBasePtr::dynamicCast(
getEntityById(matchingId));
210 <<
"Best match probability below threshold for object "
211 << objectInstance->getName() <<
" " <<
VAROUT(maxProb)
212 <<
VAROUT(matchThreshold);
220 const MotionModelInterfacePtr& newMotionModel,
221 const Ice::Current&
c)
223 auto getObjectInstanceByIdUnsafe = [
this](
const std::string& id)
228 ARMARX_WARNING_S <<
"Entity with id " <<
id <<
" is not of type ObjectInstance!"
238 ObjectInstancePtr::dynamicCast(getObjectInstanceByIdUnsafe(entityId));
239 MotionModelInterfacePtr oldMotionModel =
object->getMotionModel();
244 armarx::LinkedPoseBasePtr oldPose = oldMotionModel->getPredictedPose();
248 if (!newMotionModel->getUncertainty())
250 newMotionModel->setPoseAtLastLocalisation(
251 oldPose,
nullptr, oldMotionModel->getUncertainty());
255 newMotionModel->setPoseAtLastLocalisation(oldPose,
nullptr,
nullptr);
261 <<
" has an old motion model, but that motion model has no pose.";
267 <<
" didn't have a motion model before, this may cause problems - "
268 "setting pose to current robot pose";
269 newMotionModel->setPoseAtLastLocalisation(
271 newMotionModel->robotStateProxy->getRobotSnapshot(
272 newMotionModel->robotStateProxy->getRobotName())),
277 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(newMotionModel));
278 ARMARX_INFO_S <<
"New motion model set for " <<
object->getName() <<
": "
279 <<
object->getMotionModel()->ice_id();
285 const armarx::LinkedPoseBasePtr& objectPose,
286 const Ice::Current&
c)
291 auto oldObject =
object->clone();
293 armarx::Vector3Ptr::dynamicCast(objectPose->position)->toEigen(),
296 object->setPosition(position);
299 armarx::QuaternionPtr::dynamicCast(objectPose->orientation)->toEigen(),
302 object->setOrientation(orientation);
304 ARMARX_DEBUG_S <<
"New pose for object " <<
object->getName() <<
": "
305 << objectPose->output();
307 if (object->getMotionModel())
309 object->getMotionModel()->setPoseAtLastLocalisation(
313 listenerProxy->reportEntityUpdated(
getSegmentName(), oldObject,
object);
320 const std::string& entityId,
321 const armarx::FramedPoseBasePtr& objectPose,
322 const Ice::Current&
c)
327 auto oldObject =
object->clone();
329 armarx::Vector3Ptr::dynamicCast(objectPose->position)->toEigen(),
332 object->setPosition(position);
335 armarx::QuaternionPtr::dynamicCast(objectPose->orientation)->toEigen(),
338 object->setOrientation(orientation);
341 if (object->getMotionModel())
345 <<
" has a motion model - You should not call setObjectPoseWithoutMotionModel() "
346 "when a motion model is set. Use set setObjectPose() instead!";
350 listenerProxy->reportEntityUpdated(
getSegmentName(), oldObject,
object);
356 const std::string& className,
357 const armarx::LinkedPoseBasePtr& objectPose,
358 const MotionModelInterfacePtr& motionModel,
363 armarx::Vector3Ptr::dynamicCast(objectPose->position)->toEigen(),
366 object->setPosition(position);
367 object->setLocalizationTimestamp(objectPose->referenceRobot->getTimestamp());
369 armarx::QuaternionPtr::dynamicCast(objectPose->orientation)->toEigen(),
372 object->setOrientation(orientation);
373 Eigen::Vector3f
mean = {
374 objectPose->position->x, objectPose->position->y, objectPose->position->z};
376 variances << 10000, 0, 0, 0, 10000, 0, 0, 0, 10000;
379 object->setPositionUncertainty(uncertainty);
380 object->addClass(className, 1.0);
381 object->setExistenceCertainty(1.0);
383 motionModel->setPoseAtLastLocalisation(objectPose,
nullptr,
nullptr);
384 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(motionModel));
391 const EntityBasePtr&
update,
395 <<
"You may not call the updateEntity() function for object instances. Use the "
396 "setObjectPose(), setMotionModel(), setEntityAttribute(), setEntityAttributes() "
397 "etc. functions to manually modify the object instance.";