Go to the documentation of this file.00001 #pragma once
00002
00022 #ifndef __HELPERFUNCTIONS_H
00023 #define __HELPERFUNCTIONS_H
00024
00025
00026 #include <stdlib.h>
00027 #include <TooN/TooN.h>
00028 #include <TooN/so3.h>
00029 #include "ros/ros.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 inline static TooN::SO3<> rpy2rod(double roll, double pitch, double yaw)
00045 {
00046 TooN::Matrix<3,3> mat;
00047
00048 pitch /= 180/3.14159265;
00049 roll /= 180/3.14159265;
00050 yaw /= -180/3.14159265;
00051
00052 double sa = sin(yaw);
00053 double ca = cos(yaw);
00054 double sb = sin(roll);
00055 double cb = cos(roll);
00056 double sg = sin(pitch);
00057 double cg = cos(pitch);
00058
00059 mat(0,0) = ca*cb;
00060 mat(0,1) = sa*cb;
00061 mat(0,2) = -sb;
00062
00063 mat(1,0) = ca*sb*sg-sa*cg;
00064 mat(1,1) = sa*sb*sg+ca*cg;
00065 mat(1,2) = cb*sg;
00066
00067 mat(2,0) = ca*sb*cg+sa*sg;
00068 mat(2,1) = sa*sb*cg-ca*sg;
00069 mat(2,2) = cb*cg;
00070
00071
00072
00073 TooN::SO3<> res = mat;
00074 return res.inverse();
00075 }
00076
00077 inline static void rod2rpy(TooN::SO3<> trans, double* roll, double* pitch, double* yaw)
00078 {
00079 TooN::Matrix<3,3> mat = trans.inverse().get_matrix();
00080
00081 *roll = atan2(-mat(0,2),sqrt(mat(0,0)*mat(0,0) + mat(0,1)*mat(0,1)));
00082 *yaw = atan2(mat(0,1)/cos(*roll),mat(0,0)/cos(*roll));
00083 *pitch = atan2(mat(1,2)/cos(*roll),mat(2,2)/cos(*roll));
00084
00085 *pitch *= 180/3.14159265;
00086 *roll *= 180/3.14159265;
00087 *yaw *= -180/3.14159265;
00088
00089
00090 while(*pitch > 180) *pitch -= 360;
00091 while(*pitch < -180) *pitch += 360;
00092 while(*roll > 180) *roll -= 360;
00093 while(*roll < -180) *roll += 360;
00094 while(*yaw > 180) *yaw -= 360;
00095 while(*yaw < -180) *yaw += 360;
00096 }
00097
00098
00099
00100
00101 extern unsigned int ros_header_timestamp_base;
00102
00103
00104 inline static int getMS(ros::Time stamp = ros::Time::now())
00105 {
00106 if(ros_header_timestamp_base == 0)
00107 {
00108 ros_header_timestamp_base = stamp.sec;
00109 std::cout << "set ts base to " << ros_header_timestamp_base << std::endl;
00110 }
00111 int mss = (stamp.sec - ros_header_timestamp_base) * 1000 + stamp.nsec/1000000;
00112
00113 if(mss < 0)
00114 std::cout << "ERROR: negative timestamp..."<< std::endl;
00115 return mss;
00116 }
00117
00118 #endif