HelperFunctions.h
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 *********** Pose-Representation Conversion **********
00032 ****************************************************/
00033 // SEEE http://de.wikipedia.org/wiki/Roll-Nick-Gier-Winkel
00034 
00035 // the drone coordinate system is:
00036 // x-axis: to the left
00037 // y-axis: up
00038 // z-axis: forward
00039 // roll rhs-system correnct
00040 // pitch: rhs-system *-1;
00041 // yaw: rhs system *-1;
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);   // a is yaw = psi
00052         double ca = cos(yaw);
00053         double sb = sin(roll);  // b is roll = phi
00054         double cb = cos(roll);
00055         double sg = sin(pitch); // g is pitch = theta
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         //mat = mat.T();
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();//.T();
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 // gets a relative ms-time from a ROS time.
00102 // can only be used to compute time differences, as it has no absolute reference.
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 /* __HELPERFUNCTIONS_H */


tum_ardrone
Author(s):
autogenerated on Sat Jun 8 2019 20:27:23