util.h
Go to the documentation of this file.
00001 /*
00002  * util.h
00003  *
00004  *  Created on: Aug 6, 2010
00005  *      Author: jscholz
00006  */
00007 
00008 #ifndef UTIL_H_
00009 #define UTIL_H_
00010 
00011 #include <ros/ros.h>
00012 #include <LinearMath/btTransform.h>
00013 #include <geometry_msgs/PolygonStamped.h>
00014 #include <string>
00015 #include <boost/format.hpp>
00016 
00017 /*********
00018  * UTILS *
00019  *********/
00020 namespace manipulation_transforms_util {
00021 template<typename T>
00022 T getParam(const ros::NodeHandle &nh, const std::string &param) {
00023         T val;
00024         bool found = nh.getParam(param, val);
00025         ROS_ASSERT_MSG(found, "Did not find param %s in %s", param.c_str(), nh.getNamespace().c_str());
00026 
00027         return val;
00028 }
00029 
00030 btTransform readTransformParameter(const ros::NodeHandle &nh,
00031                 const std::string &name) {
00032         using XmlRpc::XmlRpcValue;
00033         XmlRpcValue position = getParam<XmlRpcValue> (nh, name + "/position");
00034         XmlRpcValue orientation = getParam<XmlRpcValue> (nh, name + "/orientation");
00035         ROS_ASSERT(position.getType() == XmlRpc::XmlRpcValue::TypeArray &&
00036                         orientation.getType() == XmlRpc::XmlRpcValue::TypeArray &&
00037                         position.size() == 3 && orientation.size() == 4);
00038         const double x = position[0];
00039         const double y = position[1];
00040         const double z = position[2];
00041         const btVector3 tr(x, y, z);
00042         const btQuaternion q(orientation[0], orientation[1], orientation[2],
00043                         orientation[3]);
00044 
00045         { // debugging
00046                 btTransform trans(q, tr);
00047                 geometry_msgs::Transform transform;
00048                 tf::transformTFToMsg(trans, transform);
00049                 ROS_DEBUG_STREAM ("read transform param from " << nh.getNamespace() << " into transform: " << std::endl << transform);
00050         }
00051         return btTransform(q, tr);
00052 }
00053 
00054 std::string btTransform_to_string(const btTransform &t) {
00055         btVector3 v = t.getOrigin();
00056         btQuaternion r = t.getRotation();
00057         return (boost::format("((%.3f, %.3f, %.3f), (%.3f, %.3f, %.3f, %.3f))")
00058                         % v.x() % v.y() % v.z() % r.x() % r.y() % r.z() % r.w()).str();
00059 }
00060 
00061 std::string btVector3_to_string(const btVector3 &v) {
00062         return (boost::format("% .3f, % .3f, % .3f") % v.x() % v.y() % v.z()).str();
00063 }
00064 
00065 std::string btMatrix3x3_to_string(const btMatrix3x3 &m) {
00066         return (btVector3_to_string(m.getRow(0)) + "\n" + btVector3_to_string(
00067                         m.getRow(1)) + "\n" + btVector3_to_string(m.getRow(2)) + "\n");
00068 }
00069 } // namespace manipulation_transforms_util
00070 
00071 #endif /* UTIL_H_ */


manipulation_transforms
Author(s): Jonathan Scholz
autogenerated on Tue Jan 7 2014 11:10:08