ism_helper.cpp
Go to the documentation of this file.
1 
18 //Global includes
19 #include <Eigen/Geometry>
20 
21 //ISM includes
22 #include "ISM/utility/GeometryHelper.hpp"
23 
24 //local includes
26 
27 IH::ObjectConverter::ObjectConverter(const std::string& pBaseFrame, const bool pIgnoreTypes, const bool pIgnoreIds, const int pEnableRotationMode, const std::string pRotationFrame, const std::string pRotationObjType, const std::string pRotationObjId) : mBaseFrame(pBaseFrame),
28  mIgnoreTypes(pIgnoreTypes), mIgnoreIds(pIgnoreIds), mEnableRotationMode(pEnableRotationMode), mRotationFrame(pRotationFrame), mRotationObjType(pRotationObjType), mRotationObjId(pRotationObjId), mUseConfidenceFromMsg(false),
29  nodehandle(ros::this_node::getName())
30 {
31  objectMetaDataClient = nodehandle.serviceClient<asr_object_database::ObjectMetaData>("/asr_object_database/object_meta_data");
32 }
33 
34 IH::ObjectConverter::ObjectConverter(const std::string& pBaseFrame, const bool pIgnoreTypes, const bool pIgnoreIds, const int pEnableRotationMode, const std::string pRotationFrame, const std::string pRotationObjType, const std::string pRotationObjId, const bool pUseConfidenceFromMsg)
35  : mBaseFrame(pBaseFrame), mIgnoreTypes(pIgnoreTypes), mIgnoreIds(pIgnoreIds), mEnableRotationMode(pEnableRotationMode), mRotationFrame(pRotationFrame), mRotationObjType(pRotationObjType), mRotationObjId(pRotationObjId), mUseConfidenceFromMsg(pUseConfidenceFromMsg),
36  nodehandle(ros::this_node::getName())
37 {
38  objectMetaDataClient = nodehandle.serviceClient<asr_object_database::ObjectMetaData>("/asr_object_database/object_meta_data");
39 }
40 
41 void IH::ObjectConverter::normalizeRotationInvariantObjects(ISM::ObjectSetPtr objectSet) {
43  Eigen::Quaterniond orientationRef;
44  Eigen::Vector3d yUnitVector; //
45  // Search reference object in set
47  for (ISM::ObjectPtr object : objectSet->objects) {
48  if (object->type == mRotationObjType && object->observedId == mRotationObjId) {
49  mRotationRefObject = object;
50  break;
51  }
52  }
53  // return if object not found
54  if (!mRotationRefObject) {
55  ROS_INFO_STREAM("Orientation reference object: [" << mRotationObjType << ", " << mRotationObjId << "] is not set.");
56  return;
57  }
58  orientationRef = ISM::GeometryHelper::quatToEigenQuat(mRotationRefObject->pose->quat);
59  yUnitVector = Eigen::Vector3d::UnitY();
61  if (mRotationFrame != mBaseFrame) {
62  ROS_INFO_STREAM("Base frame: " << mBaseFrame << " is not equal to rotation frame: " << mRotationFrame << ". Normalization not possible.");
63  return;
64  }
65  orientationRef = Eigen::Quaterniond(1.0, 0, 0, 0);
66  yUnitVector = -Eigen::Vector3d::UnitZ(); // NOTE: in world coordinates system is the -Z-Axis equivalent to the Y-Axis in objects coordinates system.
67  }
68  orientationRef.normalize();
69 
70  for (ISM::ObjectPtr object : objectSet->objects) {
71  asr_object_database::ObjectMetaData objMetaData;
72  objMetaData.request.object_type = object->type;
73  objMetaData.request.recognizer = object->providedBy == "fake_data_publisher" || "fake_object_recognition" ? "segmentable" : object->providedBy;
74  if (objectMetaDataClient.call(objMetaData)) {
75  if (objMetaData.response.is_rotation_invariant)
76  {
77  Eigen::Quaterniond orientation = ISM::GeometryHelper::quatToEigenQuat(object->pose->quat);
78  orientation.normalize();
79  Eigen::Vector3d objYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientation), Eigen::Vector3d::UnitY());
80  Eigen::Vector3d refYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), yUnitVector);
81  Eigen::AngleAxisd yTransform = calculateTransform(objYAxis, refYAxis, Eigen::Vector3d::UnitX());
82  Eigen::Quaterniond yAlignedOrientation = (yTransform * orientation).normalized();
83  Eigen::Vector3d objXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(yAlignedOrientation), Eigen::Vector3d::UnitX());
84  Eigen::Vector3d refXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), Eigen::Vector3d::UnitX());
85  object->pose->quat->eigen = (yTransform.inverse() * calculateTransform(objXAxis, refXAxis, Eigen::Vector3d::UnitY())).normalized() * yAlignedOrientation;
86  }
87  } else {
88  ROS_ERROR("Could not call the asr_object_database::ObjectMetaData service call");
89  }
90  }
91 }
92 
93 Eigen::AngleAxisd IH::ObjectConverter::calculateTransform(const Eigen::Vector3d& objectAxis, const Eigen::Vector3d& referenceAxis, const Eigen::Vector3d& unitAxis) {
94  double angle = ISM::GeometryHelper::getAngleBetweenAxes(referenceAxis, objectAxis);
95  Eigen::Vector3d rotationAxis = objectAxis.cross(referenceAxis);
96  rotationAxis.normalize();
97 
98  angle *= M_PI/180; // Convert to radians
99  if (angle < 0.001) {
100  return Eigen::AngleAxisd(0, unitAxis);
101  } else if (fabs(angle - M_PI) < 0.001) {
102  return Eigen::AngleAxisd(M_PI, unitAxis);
103  } else {
104  return Eigen::AngleAxisd(angle, rotationAxis);
105  }
106 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ISM::ObjectPtr mRotationRefObject
Current object pose, to which rotation invariant objects are normalized.
Definition: ism_helper.h:93
const bool mIgnoreTypes
Whether to take over object types from AsrObjects.
Definition: ism_helper.h:79
const std::string mRotationObjType
If normalizing to object: Which type of object to normalize to.
Definition: ism_helper.h:89
bool call(MReq &req, MRes &res)
std::string getName(void *handle)
const bool mUseConfidenceFromMsg
Whether to take over recognition confidences (into ism rating) from AsrObjects.
Definition: ism_helper.h:96
const int mEnableRotationMode
Normalize orientations of rotation invariant objects to either a coordinate frame or an not-rotation ...
Definition: ism_helper.h:84
Eigen::AngleAxisd calculateTransform(const Eigen::Vector3d &objectAxis, const Eigen::Vector3d &referenceAxis, const Eigen::Vector3d &unitAxis)
calculateTransform Caculate the transformation between two vectors.
Definition: ism_helper.cpp:93
void normalizeRotationInvariantObjects(ISM::ObjectSetPtr objectSet)
normalizeOrientation Normalizes the orientation of rotation invariance objects accroding to: ...
Definition: ism_helper.cpp:41
ros::ServiceClient objectMetaDataClient
Definition: ism_helper.h:100
ObjectConverter(const std::string &pBaseFrame, const bool pIgnoreTypes, const bool pIgnoreIds, const int pEnableRotationMode, const std::string pRotationFrame, const std::string pRotationObjType, const std::string pRotationObjId)
Definition: ism_helper.cpp:27
const std::string mRotationFrame
If normalizing to frame: Which frame to normalize to.
Definition: ism_helper.h:87
const std::string mBaseFrame
Frame to which incoming object messages are transformed.
Definition: ism_helper.h:76
#define ROS_INFO_STREAM(args)
ros::NodeHandle nodehandle
Definition: ism_helper.h:98
const int ROTATION_MODE_FRAME
Definition: ism_helper.h:72
const bool mIgnoreIds
Whether to take over object ids from AsrObjects.
Definition: ism_helper.h:81
#define ROS_ERROR(...)
const std::string mRotationObjId
If normalizing to object: Which id of object to normalize to.
Definition: ism_helper.h:91
const int ROTATION_MODE_OBJECT
Definition: ism_helper.h:73
const int ROTATION_MODE_DEACTIVATED
Definition: ism_helper.h:71


asr_recognizer_prediction_ism
Author(s): Aumann Florian, Heller Florian, Hutmacher Robin, Meißner Pascal, Stöckle Patrick, Stroh Daniel
autogenerated on Wed Jan 8 2020 03:18:32