comm_util.c
Go to the documentation of this file.
00001 #include "mav_common/comm_util.h"
00002 
00003 void normalizeSIAngle2Pi(Angle * angle)
00004 {
00005   if      (*angle <         0.0) *angle += 2.0 * M_PI;
00006   else if (*angle >= 2.0 * M_PI) *angle -= 2.0 * M_PI;
00007 }
00008 
00009 void normalizeSIAnglePi(Angle * angle)
00010 {
00011   if      (*angle <  -M_PI) *angle += 2.0 * M_PI;
00012   else if (*angle >=  M_PI) *angle -= 2.0 * M_PI;
00013 }
00014 
00015 /*
00016 // ****************** covariance ***********************
00017 
00018 float commToSIKFCov(uint32_t cov)
00019 {
00020   return (float)(cov) / 1000000.0;
00021 }
00022 
00023 uint32_t SIToCommKFCov(float cov)
00024 {
00025   return (uint32_t)(cov * 1000000.0);
00026 }
00027 
00028 // ****************** accel ***********************
00029 
00030 int32_t SItoCommAcc(float acc)
00031 {
00032   return (int16_t)(acc * 1000.0);
00033 }
00034 
00035 float commToSIAcc(int32_t acc)
00036 {
00037   return ((float)(acc)) / 1000.0;
00038 }
00039 
00040 // ****************** angle ***********************
00041 
00042 float commToSIAngle(uint16_t angle)
00043 {
00044   return ((float)(angle)) / 65535 * (2.0 * M_PI);
00045 }
00046 
00047 uint16_t SIToCommAngle(float angle)
00048 {
00049   return (int)(angle / (2.0 * M_PI) * 65535.0);
00050 }
00051 
00052 // ****************** position ***********************
00053 
00054 float commToSIPosition(int32_t pos)
00055 {
00056   return ((float)(pos) ) / 1000.0;
00057 }
00058 
00059 int32_t SIToCommPosition(float pos)
00060 {
00061   return (int32_t)(pos * 1000.0);
00062 }
00063 
00064 // ****************** velocity ***********************
00065 
00066 float commToSIVelocity(int16_t vel)
00067 {
00068   return ((float)(vel) ) / 1000.0;
00069 }
00070 
00071 int16_t SIToCommVelocity(float vel)
00072 {
00073   return (int16_t)(vel * 1000.0);
00074 }
00075 
00076 // ****************** Motor commands ****************
00077 
00078 int16_t SItoCommCmdRoll(float roll)
00079 {
00080   return (int16_t)(roll / (2.0 * M_PI) * 65535.0);
00081   //return (int16_t)(roll * 1000.0);
00082 }
00083 
00084 int16_t SItoCommCmdPitch(float pitch)
00085 {
00086   return (int16_t)(pitch / (2.0 * M_PI) * 65535.0);
00087   //return (int16_t)(pitch * 1000.0);
00088 }
00089 
00090 int32_t SItoCommCmdYawRate(float yaw_rate)
00091 {
00092   return (int32_t)(yaw_rate / (2.0 * M_PI) * 65535.0);
00093   //return (int16_t)(yaw_rate * 1000.0);
00094 }
00095 
00096 int16_t SItoCommCmdThrust (float thrust)
00097 {
00098   return (int16_t)(thrust * 100.0);
00099 }
00100 
00101 float commToSICmdRoll(int16_t roll)
00102 {
00103   return ((float)(roll)) / 65535 * (2.0 * M_PI);
00104   //return ((float)(roll) / 1000.0);
00105 }
00106 
00107 float commToSICmdPitch(int16_t pitch)
00108 {
00109   return ((float)(pitch)) / 65535 * (2.0 * M_PI);
00110   //return ((float)(pitch) / 1000.0);
00111 }
00112 
00113 float commToSICmdYawRate (int32_t yaw_rate)
00114 {
00115   return ((float)(yaw_rate)) / 65535 * (2.0 * M_PI);
00116   //return ((float)(yaw_rate) / 1000.0);
00117 }
00118 
00119 float commToSICmdThrust  (int16_t thrust)
00120 {
00121   return ((float)(thrust) / 100.0);
00122 }
00123 
00124 */


mav_common
Author(s): Ivan Dryanovski
autogenerated on Thu Jan 2 2014 11:28:00