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:
parent
41b5a01958
commit
d7eb416aa9
5 changed files with 14 additions and 5 deletions
|
@ -29,10 +29,9 @@ void initBoardAlignment(boardAlignment_t *boardAlignment)
|
|||
|
||||
standardBoardAlignment = false;
|
||||
|
||||
// deg2rad
|
||||
roll = boardAlignment->rollDegrees * M_PI / 180.0f;
|
||||
pitch = boardAlignment->pitchDegrees * M_PI / 180.0f;
|
||||
yaw = boardAlignment->yawDegrees * M_PI / 180.0f;
|
||||
roll = degreesToRadians(boardAlignment->rollDegrees);
|
||||
pitch = degreesToRadians(boardAlignment->pitchDegrees);
|
||||
yaw = degreesToRadians(boardAlignment->yawDegrees);
|
||||
|
||||
cosx = cosf(roll);
|
||||
sinx = sinf(roll);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "maths.h"
|
||||
|
@ -40,3 +41,9 @@ float devStandardDeviation(stdev_t *dev)
|
|||
{
|
||||
return sqrtf(devVariance(dev));
|
||||
}
|
||||
|
||||
float degreesToRadians(int16_t degrees)
|
||||
{
|
||||
return degrees * RAD;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#define RADX10 (M_PI / 1800.0f) // 0.001745329252f
|
||||
#define RAD (M_PI / 180.0f)
|
||||
|
||||
#define DEG2RAD(degrees) (degrees * RAD)
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define abs(x) ((x) > 0 ? (x) : -(x))
|
||||
|
@ -28,3 +30,4 @@ void devClear(stdev_t *dev);
|
|||
void devPush(stdev_t *dev, float x);
|
||||
float devVariance(stdev_t *dev);
|
||||
float devStandardDeviation(stdev_t *dev);
|
||||
float degreesToRadians(int16_t degrees);
|
||||
|
|
2
src/mw.c
2
src/mw.c
|
@ -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]
|
||||
|
||||
if (f.HEADFREE_MODE) {
|
||||
float radDiff = (heading - headFreeModeHold) * M_PI / 180.0f;
|
||||
float radDiff = degreesToRadians(heading - headFreeModeHold);
|
||||
float cosDiff = cosf(radDiff);
|
||||
float sinDiff = sinf(radDiff);
|
||||
int16_t rcCommand_PITCH = rcCommand[PITCH] * cosDiff + rcCommand[ROLL] * sinDiff;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue