Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FLYER_INTERFACE_UTIL_H
00023 #define FLYER_INTERFACE_UTIL_H
00024
00025 #include <stdint.h>
00026 #include <math.h>
00027
00028 namespace asctec
00029 {
00030
00031 #define GRAVITY 9.810665
00032
00033 inline double commToSIAngle(uint16_t angle);
00034 inline uint16_t SIToCommAngle(double angle);
00035
00036 inline double commToSIPosition(int32_t position);
00037 inline int32_t SIToCommPosition(double position);
00038
00039 inline double commToSILinearVelocity(int16_t velocity);
00040 inline int16_t SIToCommLinearVelocity(double velocity);
00041
00042 inline double degToRad(double angle);
00043 inline double radToDeg(double angle);
00044
00045 inline float commToSIAcc(int16_t acc);
00046
00047 inline float commToSIKFCov(uint32_t cov);
00048 inline uint32_t SIToCommKFCov(float cov);
00049
00050 inline float commToSIVoltage(int16_t voltage);
00051
00052
00053
00054 inline int16_t SItoCommCmdRoll (float roll);
00055 inline int16_t SItoCommCmdPitch (float pitch);
00056 inline int16_t SItoCommCmdYawRate (float yaw_rate);
00057 inline int16_t SItoCommCmdThrust (float thrust);
00058
00059 inline float commToSICmdRoll (int16_t roll);
00060 inline float commToSICmdPitch (int16_t pitch);
00061 inline float commToSICmdYawRate (int16_t yaw_rate);
00062 inline float commToSICmdThrust (int16_t thrust);
00063
00064
00065
00066 inline double commToSIAngle(uint16_t angle)
00067 {
00068 return degToRad(static_cast<double>(angle) / 100.0);
00069 }
00070
00071 inline uint16_t SIToCommAngle(double angle)
00072 {
00073 return static_cast<uint16_t>(radToDeg(angle * 100.0));
00074 }
00075
00076 inline double commToSIPosition(int32_t position)
00077 {
00078 return static_cast<double>(position) / 1000.0;
00079 }
00080
00081 inline int32_t SIToCommPosition(double position)
00082 {
00083 return static_cast<int32_t>(position * 1000.0);
00084 }
00085
00086 inline double commToSILinearVelocity(int16_t velocity)
00087 {
00088 return static_cast<double>(velocity) / 1000.0;
00089 }
00090
00091 inline int16_t SIToCommLinearVelocity(double velocity)
00092 {
00093 return static_cast<int32_t>(velocity * 1000.0);
00094 }
00095
00096 inline double degToRad(double angle)
00097 {
00098 return angle * M_PI / 180.0;
00099 }
00100
00101 inline double radToDeg(double angle)
00102 {
00103 return angle * 180.0 / M_PI;
00104 }
00105
00106
00107 inline void normalizeSIAngle(double& angle)
00108 {
00109 while (angle < 0.0) angle += 2.0 * M_PI;
00110 while (angle >= 2.0 * M_PI) angle -= 2.0 * M_PI;
00111 }
00112
00113 float commToSIAcc(int16_t acc)
00114 {
00115 return ( (float)(acc) ) * GRAVITY / 1000.0;
00116 }
00117
00118 inline float commToSIKFCov(uint32_t cov)
00119 {
00120 return (float)(cov) / 1000000.0;
00121 }
00122
00123 inline uint32_t SIToCommKFCov(float cov)
00124 {
00125 return (uint32_t)(cov * 1000000.0);
00126 }
00127
00128 inline float commToSIVoltage(int16_t voltage)
00129 {
00130 return (float)(voltage) / 1000.0;
00131 }
00132
00133
00134
00135 inline int16_t SItoCommCmdRoll(float roll)
00136 {
00137 return (int16_t)(radToDeg(roll) * 100.0);
00138 }
00139
00140 inline int16_t SItoCommCmdPitch(float pitch)
00141 {
00142 return (int16_t)(radToDeg(pitch) * 100.0);
00143 }
00144
00145 inline int16_t SItoCommCmdYawRate(float yaw_rate)
00146 {
00147 return (int16_t)(radToDeg(yaw_rate) * 100.0);
00148 }
00149
00150 inline int16_t SItoCommCmdThrust (float thrust)
00151 {
00152 return (int16_t)(thrust * 100.0);
00153 }
00154
00155 inline float commToSICmdRoll(int16_t roll)
00156 {
00157 return degToRad((float)(roll) / 100.0);
00158 }
00159
00160 inline float commToSICmdPitch(int16_t pitch)
00161 {
00162 return degToRad((float)(pitch) / 100.0);
00163 }
00164
00165 inline float commToSICmdYawRate (int16_t yaw_rate)
00166 {
00167 return degToRad((float)(yaw_rate) / 100.0);
00168 }
00169
00170 inline float commToSICmdThrust (int16_t thrust)
00171 {
00172 return (float)(thrust) / 100.0;
00173 }
00174
00175 }
00176
00177 #endif // FLYER_INTERFACE_UTIL_H