19 #include <Eigen/Geometry> 23 #include <boost/filesystem.hpp> 26 #include "ISM/utility/GeometryHelper.hpp" 32 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),
33 mIgnoreTypes(pIgnoreTypes), mIgnoreIds(pIgnoreIds), mEnableRotationMode(pEnableRotationMode), mRotationFrame(pRotationFrame), mRotationObjType(pRotationObjType), mRotationObjId(pRotationObjId), mUseConfidenceFromMsg(false),
36 ROS_INFO(
"Waiting for service \"/asr_object_database/object_meta_data\" to become available.");
41 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)
50 #define KINEMATICCHAINTIMEOUT 0.1 55 new ISM::Pose(
new ISM::Point(p.position.x, p.position.y, p.position.z),
56 new ISM::Quaternion(p.orientation.w, p.orientation.x, p.orientation.y, p.orientation.z)));
62 geometry_msgs::PoseStamped input, output;
63 input.header = o.header;
65 if(!o.sampledPoses.size()){
66 std::cerr <<
"Got a AsrObject without poses." << std::endl;
70 input.pose = o.sampledPoses.front().pose;
74 ISM::ObjectPtr obj = ISM::ObjectPtr(
new ISM::Object(
mIgnoreTypes ?
"" : o.type,
77 obj->ressourcePath = boost::filesystem::path(o.meshResourcePath).replace_extension(
".dae");
79 obj->providedBy = o.providedBy;
86 Eigen::Quaterniond orientationRef;
87 Eigen::Vector3d yUnitVector;
90 for (ISM::ObjectPtr
object : objectSet->objects) {
101 orientationRef = ISM::GeometryHelper::quatToEigenQuat(
mRotationRefObject->pose->quat);
102 yUnitVector = Eigen::Vector3d::UnitY();
108 orientationRef = Eigen::Quaterniond(1.0, 0, 0, 0);
109 yUnitVector = -Eigen::Vector3d::UnitZ();
111 orientationRef.normalize();
113 for (ISM::ObjectPtr
object : objectSet->objects) {
114 asr_object_database::ObjectMetaData objMetaData;
115 objMetaData.request.object_type =
object->type;
116 objMetaData.request.recognizer =
object->providedBy ==
"fake_data_publisher" ||
"fake_object_recognition" ?
"segmentable" :
object->providedBy;
118 if (objMetaData.response.is_rotation_invariant)
120 Eigen::Quaterniond orientation = ISM::GeometryHelper::quatToEigenQuat(object->pose->quat);
121 orientation.normalize();
122 Eigen::Vector3d objYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientation), Eigen::Vector3d::UnitY());
123 Eigen::Vector3d refYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), yUnitVector);
124 Eigen::AngleAxisd yTransform =
calculateTransform(objYAxis, refYAxis, Eigen::Vector3d::UnitX());
125 Eigen::Quaterniond yAlignedOrientation = (yTransform * orientation).
normalized();
126 Eigen::Vector3d objXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(yAlignedOrientation), Eigen::Vector3d::UnitX());
127 Eigen::Vector3d refXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), Eigen::Vector3d::UnitX());
128 object->pose->quat->eigen = (yTransform.inverse() *
calculateTransform(objXAxis, refXAxis, Eigen::Vector3d::UnitY())).
normalized() * yAlignedOrientation;
131 ROS_ERROR(
"Could not call the asr_object_database::ObjectMetaData service call");
137 double angle = ISM::GeometryHelper::getAngleBetweenAxes(referenceAxis, objectAxis);
138 Eigen::Vector3d rotationAxis = objectAxis.cross(referenceAxis);
139 rotationAxis.normalize();
143 return Eigen::AngleAxisd(0, unitAxis);
144 }
else if (fabs(angle - M_PI) < 0.001) {
145 return Eigen::AngleAxisd(M_PI, unitAxis);
147 return Eigen::AngleAxisd(angle, rotationAxis);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
tf::TransformListener mTfListener
Needed for transform to base_frame coordinate system.
ISM::PosePtr rosPoseToISMPose(const geometry_msgs::Pose p)
ISM::ObjectPtr mRotationRefObject
Current object pose, to which rotation invariant objects are normalized.
const bool mIgnoreTypes
Whether to take over object types from AsrObjects.
const std::string mRotationObjType
If normalizing to object: Which type of object to normalize to.
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.
const int mEnableRotationMode
Normalize orientations of rotation invariant objects to either a coordinate frame or an not-rotation ...
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
Eigen::AngleAxisd calculateTransform(const Eigen::Vector3d &objectAxis, const Eigen::Vector3d &referenceAxis, const Eigen::Vector3d &unitAxis)
calculateTransform Caculate the transformation between two vectors.
#define KINEMATICCHAINTIMEOUT
TFSIMD_FORCE_INLINE Vector3 normalized() const
void normalizeRotationInvariantObjects(ISM::ObjectSetPtr objectSet)
normalizeOrientation Normalizes the orientation of rotation invariance objects accroding to: ...
ISM::ObjectPtr pbdObjectToISMObject(const asr_msgs::AsrObject &o)
ros::ServiceClient objectMetaDataClient
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 std::string mRotationFrame
If normalizing to frame: Which frame to normalize to.
const std::string mBaseFrame
Frame to which incoming object messages are transformed.
#define ROS_INFO_STREAM(args)
ros::NodeHandle nodehandle
const int ROTATION_MODE_FRAME
const bool mIgnoreIds
Whether to take over object ids from AsrObjects.
const std::string mRotationObjId
If normalizing to object: Which id of object to normalize to.
const int ROTATION_MODE_OBJECT
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
const int ROTATION_MODE_DEACTIVATED