38 ObjectInstanceMemorySegmentBase::ObjectInstanceMemorySegmentBase(),
39 matchThreshold(matchThreshold),
40 matchByClass(matchByClass)
46 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(
getEntityById(
id));
50 ARMARX_WARNING_S <<
"Entity with id " <<
id <<
" is not of type ObjectInstance!" << std::endl;
58 ObjectInstanceBasePtr res = ObjectInstanceBasePtr::dynamicCast(
getEntityByName(name));
62 ARMARX_WARNING_S <<
"Entity with name " << name <<
" is not of type ObjectInstance!" << std::endl;
71 classList.push_back(className);
77 ObjectInstanceList result;
82 ObjectInstanceBasePtr inst = ObjectInstanceBasePtr::dynamicCast(it->second);
83 ClassProbabilityMap instClasses = inst->getClasses();
85 for (NameList::const_iterator itCls = classList.begin(); itCls != classList.end(); ++itCls)
87 if (instClasses.count(*itCls))
89 result.push_back(inst);
102 Eigen::MatrixXd i(3, 3);
104 ARMARX_DEBUG <<
"Position: " << objectInstance->getPositionBase()->output() <<
" mean: " << objectInstance->getPositionUncertainty()->getMean();
110 double maxProb = -FLT_MAX;
111 std::string matchingId =
"";
112 std::string instanceName = objectInstance->getName();
113 const std::string mostProbableClass = objectInstance->getMostProbableClass();
126 if (!matchByClass && current->getName() != instanceName)
130 else if (matchByClass && mostProbableClass != current->getMostProbableClass())
136 MultivariateNormalDistributionBasePtr uncertainty = current->getPositionUncertainty();
140 ARMARX_WARNING_S <<
"current->getPositionUncertainty() of object " << current->getName() <<
" is nullptr! Creating default uncertainty";
142 current->setPositionUncertainty(uncertainty);
167 matchingId = current->getId();
173 if (matchingId.empty())
175 ARMARX_INFO <<
deactivateSpam(5, objectInstance->getName()) <<
"Could not find any match for " << objectInstance->getName() <<
" with most probable class: " << objectInstance->getName();
179 if (maxProb >= matchThreshold)
182 return ObjectInstanceBasePtr::dynamicCast(
getEntityById(matchingId));
196 auto getObjectInstanceByIdUnsafe = [
this](
const std::string & id)
201 ARMARX_WARNING_S <<
"Entity with id " <<
id <<
" is not of type ObjectInstance!" << std::endl;
209 ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(getObjectInstanceByIdUnsafe(entityId));
210 MotionModelInterfacePtr oldMotionModel =
object->getMotionModel();
215 armarx::LinkedPoseBasePtr oldPose = oldMotionModel->getPredictedPose();
219 if (!newMotionModel->getUncertainty())
221 newMotionModel->setPoseAtLastLocalisation(oldPose,
nullptr, oldMotionModel->getUncertainty());
225 newMotionModel->setPoseAtLastLocalisation(oldPose,
nullptr,
nullptr);
230 ARMARX_ERROR_S <<
"Object " <<
object->getName() <<
" has an old motion model, but that motion model has no pose.";
235 ARMARX_WARNING_S <<
"Object " <<
object->getName() <<
" didn't have a motion model before, this may cause problems - setting pose to current robot pose";
237 newMotionModel->robotStateProxy->getRobotSnapshot(newMotionModel->robotStateProxy->getRobotName())),
nullptr,
nullptr);
240 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(newMotionModel));
241 ARMARX_INFO_S <<
"New motion model set for " <<
object->getName() <<
": " <<
object->getMotionModel()->ice_id();
250 auto oldObject =
object->clone();
252 object->setPosition(position);
255 object->setOrientation(orientation);
257 ARMARX_DEBUG_S <<
"New pose for object " <<
object->getName() <<
": " << objectPose->output();
259 if (object->getMotionModel())
277 auto oldObject =
object->clone();
279 object->setPosition(position);
282 object->setOrientation(orientation);
285 if (object->getMotionModel())
287 ARMARX_WARNING_S <<
object->getName() <<
" has a motion model - You should not call setObjectPoseWithoutMotionModel() when a motion model is set. Use set setObjectPose() instead!";
301 object->setPosition(position);
302 object->setLocalizationTimestamp(objectPose->referenceRobot->getTimestamp());
304 object->setOrientation(orientation);
305 Eigen::Vector3f
mean = {objectPose->position->x, objectPose->position->y, objectPose->position->z};
307 variances << 10000, 0, 0, 0, 10000, 0, 0, 0, 10000;
309 object->setPositionUncertainty(uncertainty);
310 object->addClass(className, 1.0);
311 object->setExistenceCertainty(1.0);
313 motionModel->setPoseAtLastLocalisation(objectPose,
nullptr,
nullptr);
314 object->setMotionModel(AbstractMotionModelPtr::dynamicCast(motionModel));
321 ARMARX_ERROR_S <<
"You may not call the updateEntity() function for object instances. Use the setObjectPose(), setMotionModel(), setEntityAttribute(), setEntityAttributes() etc. functions to manually modify the object instance.";