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


uga_tum_ardrone
Author(s):
autogenerated on Sat Jun 8 2019 20:30:11