1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 21:05:35 +03:00

de-duplicate degrees to radians code.

Note, this also makes the operator precedence clearer.
This commit is contained in:
Dominic Clifton 2014-04-17 19:37:56 +01:00
parent 41b5a01958
commit d7eb416aa9
5 changed files with 14 additions and 5 deletions

View file

@ -29,10 +29,9 @@ void initBoardAlignment(boardAlignment_t *boardAlignment)
standardBoardAlignment = false; standardBoardAlignment = false;
// deg2rad roll = degreesToRadians(boardAlignment->rollDegrees);
roll = boardAlignment->rollDegrees * M_PI / 180.0f; pitch = degreesToRadians(boardAlignment->pitchDegrees);
pitch = boardAlignment->pitchDegrees * M_PI / 180.0f; yaw = degreesToRadians(boardAlignment->yawDegrees);
yaw = boardAlignment->yawDegrees * M_PI / 180.0f;
cosx = cosf(roll); cosx = cosf(roll);
sinx = sinf(roll); sinx = sinf(roll);

View file

@ -1,3 +1,4 @@
#include <stdint.h>
#include <math.h> #include <math.h>
#include "maths.h" #include "maths.h"
@ -40,3 +41,9 @@ float devStandardDeviation(stdev_t *dev)
{ {
return sqrtf(devVariance(dev)); return sqrtf(devVariance(dev));
} }
float degreesToRadians(int16_t degrees)
{
return degrees * RAD;
}

View file

@ -12,6 +12,8 @@
#define RADX10 (M_PI / 1800.0f) // 0.001745329252f #define RADX10 (M_PI / 1800.0f) // 0.001745329252f
#define RAD (M_PI / 180.0f) #define RAD (M_PI / 180.0f)
#define DEG2RAD(degrees) (degrees * RAD)
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(x) ((x) > 0 ? (x) : -(x)) #define abs(x) ((x) > 0 ? (x) : -(x))
@ -28,3 +30,4 @@ void devClear(stdev_t *dev);
void devPush(stdev_t *dev, float x); void devPush(stdev_t *dev, float x);
float devVariance(stdev_t *dev); float devVariance(stdev_t *dev);
float devStandardDeviation(stdev_t *dev); float devStandardDeviation(stdev_t *dev);
float degreesToRadians(int16_t degrees);

View file

@ -142,7 +142,7 @@ void annexCode(void)
rcCommand[THROTTLE] = lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100; // [0;1000] -> expo -> [MINTHROTTLE;MAXTHROTTLE] rcCommand[THROTTLE] = lookupThrottleRC[tmp2] + (tmp - tmp2 * 100) * (lookupThrottleRC[tmp2 + 1] - lookupThrottleRC[tmp2]) / 100; // [0;1000] -> expo -> [MINTHROTTLE;MAXTHROTTLE]
if (f.HEADFREE_MODE) { if (f.HEADFREE_MODE) {
float radDiff = (heading - headFreeModeHold) * M_PI / 180.0f; float radDiff = degreesToRadians(heading - headFreeModeHold);
float cosDiff = cosf(radDiff); float cosDiff = cosf(radDiff);
float sinDiff = sinf(radDiff); float sinDiff = sinf(radDiff);
int16_t rcCommand_PITCH = rcCommand[PITCH] * cosDiff + rcCommand[ROLL] * sinDiff; int16_t rcCommand_PITCH = rcCommand[PITCH] * cosDiff + rcCommand[ROLL] * sinDiff;