Go to the documentation of this file.00001 #include <Eigen/LU>
00002
00003 #include <LinearMath/btMatrix3x3.h>
00004 #include <LinearMath/btQuaternion.h>
00005
00006 #include "walk_msgs/conversion.hh"
00007 #include "walk_interfaces/util.hh"
00008
00009 namespace walk_msgs
00010 {
00011 void convertPoseToHomogeneousMatrix(walk::HomogeneousMatrix3d& dst,
00012 const geometry_msgs::Pose& src)
00013 {
00014 btQuaternion quaternion
00015 (src.orientation.x, src.orientation.y, src.orientation.z,
00016 src.orientation.w);
00017 btMatrix3x3 rotation (quaternion);
00018
00019 dst.setIdentity();
00020
00021
00022 for(unsigned i = 0; i < 3; ++i)
00023 for(unsigned j = 0; j < 3; ++j)
00024 dst (i, j) = rotation[i][j];
00025
00026
00027 dst(0, 3) = src.position.x;
00028 dst(1, 3) = src.position.y;
00029 dst(2, 3) = src.position.z;
00030 }
00031
00032
00033 void convertPointToVector3d(walk::Vector3d& dst,
00034 const geometry_msgs::Point& src)
00035 {
00036 dst[0] = src.x;
00037 dst[1] = src.y;
00038 dst[2] = src.z;
00039 }
00040
00041 void convertHomogeneousMatrixToPose(geometry_msgs::Pose& dst,
00042 const walk::HomogeneousMatrix3d& src)
00043 {
00044 btMatrix3x3 rotation;
00045 btQuaternion quaternion;
00046 for(unsigned i = 0; i < 3; ++i)
00047 for(unsigned j = 0; j < 3; ++j)
00048 rotation[i][j] = src (i, j);
00049 rotation.getRotation (quaternion);
00050
00051 dst.position.x = src (0, 3);
00052 dst.position.y = src (1, 3);
00053 dst.position.z = src (2, 3);
00054
00055 dst.orientation.x = quaternion.x ();
00056 dst.orientation.y = quaternion.y ();
00057 dst.orientation.z = quaternion.z ();
00058 dst.orientation.w = quaternion.w ();
00059
00060 }
00061
00062 void convertTrajectoryToPath(nav_msgs::Path& dst,
00063 const walk::DiscretizedTrajectory3d& src,
00064 const std::string& frameName)
00065 {
00066 std::size_t size = src.data().size();
00067
00068 std_msgs::Header poseHeader;
00069 poseHeader.seq = 0;
00070 poseHeader.stamp.sec = 0.;
00071 poseHeader.stamp.nsec = 0.;
00072 poseHeader.frame_id = frameName;
00073
00074 geometry_msgs::PoseStamped poseStamped;
00075
00076 walk::TimeDuration duration;
00077 for (std::size_t i = 0; i < size; ++i)
00078 {
00079
00080 ++poseHeader.seq;
00081 poseHeader.stamp.sec =
00082 duration.ticks() / walk::TimeDuration::rep_type::res_adjust ();
00083 poseHeader.stamp.nsec = duration.fractional_seconds() * 1e3;
00084
00085
00086 poseStamped.header = poseHeader;
00087
00088
00089 convertHomogeneousMatrixToPose
00090 (poseStamped.pose,
00091 src.data()[i].position);
00092
00093
00094 dst.poses.push_back(poseStamped);
00095
00096 duration += src.data()[i].duration;
00097 }
00098 }
00099
00100 void convertTrajectoryV2dToPath(walk_msgs::PathPoint2d& dst,
00101 const walk::DiscretizedTrajectoryV2d& src,
00102 const std::string& frameName)
00103 {
00104 std::size_t size = src.data().size();
00105
00106 std_msgs::Header pointHeader;
00107 pointHeader.seq = 0;
00108 pointHeader.stamp.sec = 0.;
00109 pointHeader.stamp.nsec = 0.;
00110 pointHeader.frame_id = frameName;
00111
00112 walk_msgs::Point2dStamped pointStamped;
00113
00114 walk::TimeDuration duration;
00115 for (std::size_t i = 0; i < size; ++i)
00116 {
00117
00118 ++pointHeader.seq;
00119 pointHeader.stamp.sec =
00120 duration.ticks() / walk::TimeDuration::rep_type::res_adjust ();
00121 pointHeader.stamp.nsec = duration.fractional_seconds() * 1000000;
00122
00123
00124 pointStamped.header = pointHeader;
00125
00126
00127 pointStamped.point.x = src.data()[i].position[0];
00128 pointStamped.point.y = src.data()[i].position[1];
00129
00130
00131 dst.points.push_back(pointStamped);
00132
00133 duration += src.data()[i].duration;
00134 }
00135 }
00136
00137 void convertTrajectoryV3dToPath(walk_msgs::PathPoint3d& dst,
00138 const walk::DiscretizedTrajectoryV3d& src,
00139 const std::string& frameName)
00140 {
00141 std::size_t size = src.data().size();
00142
00143 std_msgs::Header pointHeader;
00144 pointHeader.seq = 0;
00145 pointHeader.stamp.sec = 0.;
00146 pointHeader.stamp.nsec = 0.;
00147 pointHeader.frame_id = frameName;
00148
00149 geometry_msgs::PointStamped pointStamped;
00150
00151 walk::TimeDuration duration;
00152 for (std::size_t i = 0; i < size; ++i)
00153 {
00154
00155 ++pointHeader.seq;
00156 pointHeader.stamp.sec =
00157 duration.ticks() / walk::TimeDuration::rep_type::res_adjust ();
00158 pointHeader.stamp.nsec = duration.fractional_seconds() * 1000000;
00159
00160
00161 pointStamped.header = pointHeader;
00162
00163
00164 pointStamped.point.x = src.data()[i].position[0];
00165 pointStamped.point.y = src.data()[i].position[1];
00166 pointStamped.point.z = src.data()[i].position[2];
00167
00168
00169 dst.points.push_back(pointStamped);
00170
00171 duration += src.data()[i].duration;
00172 }
00173 }
00174
00175 void convertTrajectoryV2dToPath(nav_msgs::Path& dst,
00176 const walk::DiscretizedTrajectoryV2d& src,
00177 const std::string& frameName)
00178 {
00179 std::size_t size = src.data().size();
00180
00181 std_msgs::Header poseHeader;
00182 poseHeader.seq = 0;
00183 poseHeader.stamp.sec = 0.;
00184 poseHeader.stamp.nsec = 0.;
00185 poseHeader.frame_id = frameName;
00186
00187 geometry_msgs::PoseStamped poseStamped;
00188
00189 walk::TimeDuration duration;
00190 for (std::size_t i = 0; i < size; ++i)
00191 {
00192
00193 ++poseHeader.seq;
00194 poseHeader.stamp.sec =
00195 duration.ticks() / walk::TimeDuration::rep_type::res_adjust ();
00196 poseHeader.stamp.nsec = duration.fractional_seconds() * 1000000;
00197
00198
00199 poseStamped.header = poseHeader;
00200
00201
00202 poseStamped.pose.position.x = src.data()[i].position[0];
00203 poseStamped.pose.position.y = src.data()[i].position[1];
00204 poseStamped.pose.position.z = 0.;
00205
00206 poseStamped.pose.orientation.x = 0.;
00207 poseStamped.pose.orientation.y = 0.;
00208 poseStamped.pose.orientation.z = 0.;
00209 poseStamped.pose.orientation.z = 1.;
00210
00211
00212 dst.poses.push_back(poseStamped);
00213
00214 duration += src.data()[i].duration;
00215 }
00216 }
00217
00218 void convertTrajectoryV3dToPath(nav_msgs::Path& dst,
00219 const walk::DiscretizedTrajectoryV3d& src,
00220 const std::string& frameName)
00221 {
00222 std::size_t size = src.data().size();
00223
00224 std_msgs::Header poseHeader;
00225 poseHeader.seq = 0;
00226 poseHeader.stamp.sec = 0.;
00227 poseHeader.stamp.nsec = 0.;
00228 poseHeader.frame_id = frameName;
00229
00230 geometry_msgs::PoseStamped poseStamped;
00231
00232 walk::TimeDuration duration;
00233 for (std::size_t i = 0; i < size; ++i)
00234 {
00235
00236 ++poseHeader.seq;
00237 poseHeader.stamp.sec =
00238 duration.ticks() / walk::TimeDuration::rep_type::res_adjust ();
00239 poseHeader.stamp.nsec = duration.fractional_seconds() * 1000000;
00240
00241
00242 poseStamped.header = poseHeader;
00243
00244
00245 poseStamped.pose.position.x = src.data()[i].position[0];
00246 poseStamped.pose.position.y = src.data()[i].position[1];
00247 poseStamped.pose.position.z = src.data()[i].position[2];
00248
00249 poseStamped.pose.orientation.x = 0.;
00250 poseStamped.pose.orientation.y = 0.;
00251 poseStamped.pose.orientation.z = 0.;
00252 poseStamped.pose.orientation.z = 1.;
00253
00254
00255 dst.poses.push_back(poseStamped);
00256
00257 duration += src.data()[i].duration;
00258 }
00259 }
00260
00261 void
00262 convertFootprint2dToHomogeneousMatrix3d
00263 (walk::HomogeneousMatrix3d& dst, const walk_msgs::Footprint2d& src)
00264 {
00265 dst.setIdentity();
00266 walk::trans2dToTrans3d (dst, src.x, src.y, src.theta);
00267 }
00268
00269 void
00270 convertHomogeneousMatrix3dToFootprint2d
00271 (walk_msgs::Footprint2d& dst, const walk::HomogeneousMatrix3d& src)
00272 {
00273 dst.x = src (0, 3);
00274 dst.y = src (1, 3);
00275 dst.theta = std::atan2 (src (1, 0), src (0, 0));
00276 }
00277
00278 }