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