27 tf_transform_listener_(),
28 object_type_client_ptr_(object_type_client_ptr),
29 model_type_ptr_per_type_map_ptr_(model_type_ptr_per_type_map_ptr),
30 settings_ptr_(settings_ptr)
39 asr_world_model::PushFoundObjectList::Response &response)
43 for (asr_msgs::AsrObject &foundObject : request.found_object_list)
46 if(!result)
ROS_ERROR_STREAM(
"Pushing found object to world model failed for type/id: " << foundObject.type <<
"/" << foundObject.identifier);
53 const std::string &CANDIDATE_TYPE = candidate.type;
54 const std::string &CANDIDATE_IDENTIFIER = candidate.identifier;
59 ROS_WARN_STREAM(
"The given type was not in the ISM_Tables -> not all information are available for it: " << CANDIDATE_TYPE);
63 ModelObjectPtrPerIdMap::iterator id_it = type_it->second->model_object_ptr_per_id_map.find(CANDIDATE_IDENTIFIER);
64 if (id_it == type_it->second->model_object_ptr_per_id_map.end()) {
65 ROS_WARN_STREAM(
"The given type and id was not in the ISM_Tables -> not all information are available for it: type: " << CANDIDATE_TYPE <<
", id: " << CANDIDATE_IDENTIFIER);
66 id_it = type_it->second->model_object_ptr_per_id_map.insert(std::make_pair(CANDIDATE_IDENTIFIER,
ModelObjectPtr(
new ModelObject(CANDIDATE_IDENTIFIER)))).first;
81 if (currentModelObjectPtr->bestHypotheses.size() == 0) {
83 currentModelObjectPtr->allFoundHypotheses.push_back(std::make_pair(candidate, 1));
85 currentModelObjectPtr->bestHypotheses.push_back(std::make_pair(candidate, 1));
87 debug_helper_ptr_->write(std::stringstream() <<
"Received object hypothesis for " << CANDIDATE_TYPE <<
" with ID " << CANDIDATE_IDENTIFIER <<
" is the first. Is trivially best hypothesis",
DebugHelper::FOUND_OBJECT);
93 const geometry_msgs::Point &candidate_position = candidate.sampledPoses.front().pose.position;
94 debug_helper_ptr_->write(std::stringstream() <<
"Position of object estimate, having been added to cluster list: " << candidate_position.x <<
", " << candidate_position.y <<
", " << candidate_position.z,
DebugHelper::FOUND_OBJECT);
108 int neighborCount = 1;
115 ++pdbObjectCluster.second;
120 allFoundHypotheses.push_back(std::make_pair(candidate, neighborCount));
122 debug_helper_ptr_->write(std::stringstream() <<
"Added new cluster for " << candidate.type <<
" with ID " << candidate.identifier <<
" with neighborCount " << neighborCount <<
" into clusterlist",
DebugHelper::FOUND_OBJECT);
137 bool isInNeighborhood =
false;
139 const geometry_msgs::Pose &clusterListCenterPose = pdbObjectCurrentCluster.first.sampledPoses.front().pose;
140 for (
const PbdObjectCluster &pdbObjectCurrentBestHypothese : currentBestHypothesis)
143 const geometry_msgs::Pose &bestCenterPose = pdbObjectCurrentBestHypothese.first.sampledPoses.front().pose;
144 isInNeighborhood |=
pose_helper_ptr_->checkPosesAreApproxEquale(clusterListCenterPose, bestCenterPose, 0.1, 2.0*M_PI);
147 if (!isInNeighborhood && pdbObjectCurrentCluster.second >=
settings_ptr_->object_rating_min_count)
149 currentBestHypothesis.push_back(std::make_pair(pdbObjectCurrentCluster.first, pdbObjectCurrentCluster.second));
154 debug_helper_ptr_->write(std::stringstream() <<
"Created new best cluster list with " << currentBestHypothesis.size() <<
" elements (objects) for " << candidate.type <<
" with ID " << candidate.identifier ,
DebugHelper::FOUND_OBJECT);
157 currentModelObjectPtr->bestHypotheses = currentBestHypothesis;
161 const geometry_msgs::Pose &detected_pose1 = object1.sampledPoses.front().pose;
162 const geometry_msgs::Pose &detected_pose2 = object2.sampledPoses.front().pose;
168 geometry_msgs::PoseStamped cameraPose, mapPose;
169 cameraPose.header = candidate.header;
170 cameraPose.pose = candidate.sampledPoses.front().pose;
177 cameraPose.header.stamp = transform.
stamp_;
181 ROS_ERROR_STREAM(
"tf exception when converting object to map frame :: " << ex.what());
185 candidate.header.frame_id = mapPose.header.frame_id;
186 geometry_msgs::PoseWithCovariance pose_with_c;
187 pose_with_c.pose = mapPose.pose;
188 candidate.sampledPoses.clear();
189 candidate.sampledPoses.push_back(pose_with_c);
201 bool isObjectToSample =
false;
202 for (
const std::pair<std::string, std::string> &type_to_id :
settings_ptr_->objects_to_sample) {
203 if (type_to_id.first == candidate.type && type_to_id.second == candidate.identifier) {
204 isObjectToSample =
true;
208 if (!isObjectToSample) {
209 ROS_WARN_STREAM(
"Given object is disabled for sampling type: " << candidate.type <<
" id: " << candidate.identifier);
231 const std::string &recognizerName = (*model_type_ptr_per_type_map_ptr_)[candidate.type]->recognizerName;
232 if (recognizerName.size() == 0) {
233 ROS_ERROR_STREAM(
"RecognizerName for type/id" << candidate.type <<
"/" << candidate.identifier <<
" not found: Please check the ISM_Table.");
237 asr_object_database::ObjectMetaData srv;
238 srv.request.object_type = candidate.type;
239 srv.request.recognizer = recognizerName;
242 std::vector<double> &deviations = srv.response.deviations;
243 if (deviations.size() == 6) {
244 std::vector<double>::iterator deviations_it = deviations.begin();
246 debug_helper_ptr_->write(std::stringstream() <<
"Sampling object (type = " << candidate.type <<
248 X_AXIS_ERROR = *(deviations_it++);
249 Y_AXIS_ERROR = *(deviations_it++);
250 Z_AXIS_ERROR = *(deviations_it++);
252 ALPHA_ERROR = *(deviations_it++);
253 BETA_ERROR = *(deviations_it++);
254 GAMMA_ERROR = *(deviations_it++);
256 ROS_ERROR_STREAM(
"The deviations from the objectdatabase has not 6 entries but " << deviations.size());
260 ROS_ERROR(
"Could not call the asr_object_database::ObjectMetaData service call");
272 if (!candidate.sampledPoses.size()) {
278 const geometry_msgs::PoseWithCovariance detected_pose_with_c = candidate.sampledPoses.front();
279 const geometry_msgs::Pose &detected_pose = detected_pose_with_c.pose;
281 debug_helper_ptr_->write(std::stringstream() <<
"Sampling around that position: x: " 282 << detected_pose.position.x <<
", y: " << detected_pose.position.y <<
", z: " << detected_pose.position.z,
DebugHelper::FOUND_OBJECT);
285 const int numberOfInterpolationsPerPosition = 2 *
settings_ptr_->deviation_number_of_samples_position + 1;
286 const int numberOfInterpolationsPerOrientation = 2 *
settings_ptr_->deviation_number_of_samples_orientation + 1;
290 geometry_msgs::Pose interpolatedPoseMinX = detected_pose;
291 interpolatedPoseMinX.position.x -= X_AXIS_ERROR;
292 geometry_msgs::Pose interpolatedPoseMaxX = detected_pose;
293 interpolatedPoseMaxX.position.x += X_AXIS_ERROR;
294 std::vector<geometry_msgs::Pose> allInterpolatedPerX =
interpolatePoses(interpolatedPoseMinX, interpolatedPoseMaxX, numberOfInterpolationsPerPosition);
296 for (
const geometry_msgs::Pose &interpolatedPerX : allInterpolatedPerX) {
298 geometry_msgs::Pose interpolatedPoseMinY = interpolatedPerX;
299 interpolatedPoseMinY.position.y -= Y_AXIS_ERROR;
300 geometry_msgs::Pose interpolatedPoseMaxY = interpolatedPerX;
301 interpolatedPoseMaxY.position.y += Y_AXIS_ERROR;
302 std::vector<geometry_msgs::Pose> allInterpolatedPerY =
interpolatePoses(interpolatedPoseMinY, interpolatedPoseMaxY, numberOfInterpolationsPerPosition);
304 for (
const geometry_msgs::Pose &interpolatedPerY : allInterpolatedPerY) {
306 geometry_msgs::Pose interpolatedPoseMinZ = interpolatedPerY;
307 interpolatedPoseMinZ.position.z -= Z_AXIS_ERROR;
308 geometry_msgs::Pose interpolatedPoseMaxZ = interpolatedPerY;
309 interpolatedPoseMaxZ.position.z += Z_AXIS_ERROR;
310 std::vector<geometry_msgs::Pose> allInterpolatedPerZ =
interpolatePoses(interpolatedPoseMinZ, interpolatedPoseMaxZ, numberOfInterpolationsPerPosition);
312 for (
const geometry_msgs::Pose &interpolatedPerZ : allInterpolatedPerZ) {
314 std::vector<geometry_msgs::Pose> allInterpolatedPerAlpha =
317 for (
const geometry_msgs::Pose &interpolatedPerAlpha : allInterpolatedPerAlpha) {
319 std::vector<geometry_msgs::Pose> allInterpolatedPerBeta =
322 for (
const geometry_msgs::Pose &interpolatedPerGamma : allInterpolatedPerBeta) {
324 std::vector<geometry_msgs::Pose> allInterpolatedPerGamma =
327 for (
const geometry_msgs::Pose &interpolatedPerGamma : allInterpolatedPerGamma) {
329 double positionDistance =
pose_helper_ptr_->calcDistancePositionEucl(interpolatedPerGamma, detected_pose);
330 double orientationDistance = fabs(
pose_helper_ptr_->calcAngularDistanceInRad(interpolatedPerGamma, detected_pose));
332 if (positionDistance <=
EPSILON && orientationDistance <=
EPSILON) {
344 geometry_msgs::PoseWithCovariance current_pose_with_covariance;
345 current_pose_with_covariance.pose = interpolatedPerGamma;
346 current_pose_with_covariance.covariance = detected_pose_with_c.covariance;
347 candidate.sampledPoses.push_back(current_pose_with_covariance);
355 ROS_INFO_STREAM(
"Number of sampled poses: " << candidate.sampledPoses.size() - 1);
360 const geometry_msgs::Pose &poseToInterpolate,
const double interpolationOffset,
const Eigen::Vector3d &axisToRotate,
const int numberOfInterpolationsPerOrientation)
const {
362 const geometry_msgs::Pose &interpolatedPoseMin =
rotateOrientationAroundAxis(poseToInterpolate, interpolationOffset, axisToRotate);
363 const geometry_msgs::Pose &interpolatedPoseMax =
rotateOrientationAroundAxis(poseToInterpolate, -1.0 * interpolationOffset, axisToRotate);
365 return interpolatePoses(interpolatedPoseMin, interpolatedPoseMax, numberOfInterpolationsPerOrientation);
369 const geometry_msgs::Pose &poseToRotate,
const double interpolationOffset,
const Eigen::Vector3d &axisToRotate)
const {
371 Eigen::Quaterniond poseToRotateQuat(poseToRotate.orientation.w,
372 poseToRotate.orientation.x,
373 poseToRotate.orientation.y,
374 poseToRotate.orientation.z);
375 poseToRotateQuat.normalize();
377 Eigen::Matrix3d rotatedOffsetMat;
378 rotatedOffsetMat = Eigen::AngleAxisd(interpolationOffset *
DEG_TO_RAD, axisToRotate);
379 Eigen::Quaterniond rotatedOffsetQuat(rotatedOffsetMat);
380 rotatedOffsetQuat.normalize();
382 Eigen::Quaterniond rotatedPoseQuat = rotatedOffsetQuat * poseToRotateQuat;
384 geometry_msgs::Pose rotatedPose = poseToRotate;
385 rotatedPose.orientation.w = rotatedPoseQuat.w();
386 rotatedPose.orientation.x = rotatedPoseQuat.x();
387 rotatedPose.orientation.y = rotatedPoseQuat.y();
388 rotatedPose.orientation.z = rotatedPoseQuat.z();
393 std::vector<geometry_msgs::Pose> allInterpolatedPoses;
395 Eigen::Vector3d fromPosition(fromPose.position.x, fromPose.position.y, fromPose.position.z);
396 Eigen::Vector3d toPosition(toPose.position.x, toPose.position.y, toPose.position.z);
397 Eigen::Quaterniond fromOrient(fromPose.orientation.w,
398 fromPose.orientation.x,
399 fromPose.orientation.y,
400 fromPose.orientation.z);
401 Eigen::Quaterniond toOrient(toPose.orientation.w,
402 toPose.orientation.x,
403 toPose.orientation.y,
404 toPose.orientation.z);
406 double divisor =
static_cast<double>(numberOfInterpolations + 1);
407 for (
int i = 1; i <= numberOfInterpolations; ++i) {
408 double weightForFirst = (divisor - i) / divisor;
409 double weightForSecond = i / divisor;
411 Eigen::Vector3d currentInterpolatedPosition = fromPosition * weightForFirst + toPosition * weightForSecond;
412 Eigen::Quaterniond currentInterpolatedQuat = fromOrient.slerp(weightForSecond, toOrient);
414 geometry_msgs::Pose currentInterpolatedPose;
415 currentInterpolatedPose.position.x = currentInterpolatedPosition[0];
416 currentInterpolatedPose.position.y = currentInterpolatedPosition[1];
417 currentInterpolatedPose.position.z = currentInterpolatedPosition[2];
418 currentInterpolatedPose.orientation.w = currentInterpolatedQuat.w();
419 currentInterpolatedPose.orientation.x = currentInterpolatedQuat.x();
420 currentInterpolatedPose.orientation.y = currentInterpolatedQuat.y();
421 currentInterpolatedPose.orientation.z = currentInterpolatedQuat.z();
423 bool isEquale =
false;
424 for (
const geometry_msgs::Pose &interpolatedPose : allInterpolatedPoses) {
431 allInterpolatedPoses.push_back(currentInterpolatedPose);
434 return allInterpolatedPoses;
440 for (
const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
441 for (
const PbdObjectCluster &best_object_hypotheses : model_object_ptr_per_id_pair.second->bestHypotheses) {
450 asr_world_model::VisualizeSampledPoses::Response &response) {
451 debug_helper_ptr_->write(std::stringstream() <<
"Calling processVisualizeSampledPosesCall for object_type: " 457 ROS_WARN_STREAM(
"The given type was not in the ISM_Tables -> processVisualizeSampledPosesCall not possible: " << request.object_type);
461 ModelObjectPtrPerIdMap::iterator id_it = type_it->second->model_object_ptr_per_id_map.find(request.object_id);
462 if (id_it == type_it->second->model_object_ptr_per_id_map.end()) {
463 ROS_WARN_STREAM(
"The given type and id was not in the ISM_Tables -> processVisualizeSampledPosesCall not possible: type: " << request.object_type <<
", id: " << request.object_id);
469 for (
const PbdObjectCluster &best_object_hypotheses : currentModelObjectPtr->bestHypotheses) {
480 std_srvs::Empty::Response &response)
484 for (
const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
485 model_object_ptr_per_id_pair.second->allFoundHypotheses.clear();
486 model_object_ptr_per_id_pair.second->bestHypotheses.clear();
496 asr_world_model::GetFoundObjectList::Response &response)
500 unsigned int hypotheses_counter = 0;
503 for (
const std::pair<std::string, ModelObjectPtr> &model_object_ptr_per_id_pair : model_type_ptr_per_type_pair.second->model_object_ptr_per_id_map) {
504 for (
const PbdObjectCluster &best_object_hypotheses : model_object_ptr_per_id_pair.second->bestHypotheses) {
505 response.object_list.push_back(best_object_hypotheses.first);
506 ++hypotheses_counter;
SettingsPtr settings_ptr_
boost::shared_ptr< ModelObject > ModelObjectPtr
bool processEmptyFoundObjectListServiceCall(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
Empties the found object list.
geometry_msgs::Pose rotateOrientationAroundAxis(const geometry_msgs::Pose &poseToRotate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate) const
boost::shared_ptr< WorldModelVisualizerRVIZ > WorldModelVisualizerRVIZPtr
FoundObjectHandler(boost::shared_ptr< ros::Publisher > marker_publisher_ptr, boost::shared_ptr< ros::ServiceClient > object_type_client_ptr, ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr, SettingsPtr settings_ptr)
Creates a new instance of FoundObjectHandler.
static boost::shared_ptr< PoseHelper > getInstance()
void updateBestHypothesis(ModelObjectPtr ¤tModelObjectPtr, const asr_msgs::AsrObject &candidate)
bool processGetFoundObjectListServiceCall(asr_world_model::GetFoundObjectList::Request &request, asr_world_model::GetFoundObjectList::Response &response)
Returns the already found objects.
bool transformToBaseFrame(asr_msgs::AsrObject &candidate) const
Transform object pose to base frame of world model.
tf::TransformListener tf_transform_listener_
static boost::shared_ptr< DebugHelper > getInstance()
std::vector< geometry_msgs::Pose > interpolateOrientationAroundAxis(const geometry_msgs::Pose &poseToInterpolate, const double interpolationOffset, const Eigen::Vector3d &axisToRotate, const int numberOfInterpolationsPerOrientation) const
WorldModelVisualizerRVIZPtr world_model_visualizer_ptr_
#define ROS_WARN_STREAM(args)
PoseHelperPtr pose_helper_ptr_
boost::shared_ptr< ros::ServiceClient > object_type_client_ptr_
DebugHelperPtr debug_helper_ptr_
std::vector< geometry_msgs::Pose > interpolatePoses(const geometry_msgs::Pose &fromPose, const geometry_msgs::Pose &toPose, const int numberOfInterpolations) const
bool comparePbdObjectCluster(const PbdObjectCluster &first, const PbdObjectCluster &second)
bool processVisualizeSampledPosesCall(asr_world_model::VisualizeSampledPoses::Request &request, asr_world_model::VisualizeSampledPoses::Response &response)
#define ROS_INFO_STREAM(args)
bool pushFoundObject(asr_msgs::AsrObject &candidate)
bool sampleFoundObject(asr_msgs::AsrObject &candidate)
Generates samples for object pose estimation to model uncertainty.
bool evaluateNeighborhood(const asr_msgs::AsrObject &object1, const asr_msgs::AsrObject &object2) const
Determines if two objects are neighbors to each other in terms of position and orientation distance...
#define ROS_ERROR_STREAM(args)
void visualizeFoundObjects()
ModelTypePtrPerTypeMapPtr model_type_ptr_per_type_map_ptr_
boost::shared_ptr< ModelType > ModelTypePtr
bool processPushFoundObjectListServiceCall(asr_world_model::PushFoundObjectList::Request &request, asr_world_model::PushFoundObjectList::Response &response)
Pushes the found object to a list.
std::list< PbdObjectCluster > PbdObjectClusterList
std::pair< asr_msgs::AsrObject, int > PbdObjectCluster