Skip to content

Commit

Permalink
Merge pull request #616 from iNavFlight/bmp280-baro-fix
Browse files Browse the repository at this point in the history
Bugfixes backport to master
  • Loading branch information
digitalentity authored Sep 18, 2016
2 parents a5f7067 + a3a5b71 commit 36954a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/main/build/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#define FC_VERSION_MAJOR 1 // increment when a major release is made (big new feature, etc)
#define FC_VERSION_MINOR 2 // increment when a minor release is made (small new feature, change etc)
#define FC_VERSION_PATCH_LEVEL 0 // increment when a bug is fixed
#define FC_VERSION_PATCH_LEVEL 1 // increment when a bug is fixed

#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
Expand Down
6 changes: 4 additions & 2 deletions src/main/fc/mw.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,10 @@ void taskUpdateCompass(void)
void taskUpdateBaro(void)
{
if (sensors(SENSOR_BARO)) {
uint32_t newDeadline = baroUpdate();
rescheduleTask(TASK_SELF, newDeadline);
const uint32_t newDeadline = baroUpdate();
if (newDeadline != 0) {
rescheduleTask(TASK_SELF, newDeadline);
}
}

//updatePositionEstimator_BaroTopic(currentTime);
Expand Down
23 changes: 6 additions & 17 deletions src/main/flight/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,33 +219,22 @@ static void pidApplyHeadingLock(const pidProfile_t *pidProfile, pidState_t *pidS
}
}

// Value derived from LibrePilot:
// we are looking for where the stick angle == transition angle
// and the Att rate equals the Rate rate
// that's where Rate x (1-StickAngle) [Attitude pulling down max X Ratt proportion]
// == Rate x StickAngle [Rate pulling up according to stick angle]
// * StickAngle [X Ratt proportion]
// so 1-x == x*x or x*x+x-1=0 where xE(0,1)
// (-1+-sqrt(1+4))/2 = (-1+sqrt(5))/2
// and quadratic formula says that is 0.618033989f
#define STICK_DEFLECTION_AT_MODE_TRANSITION 0.618033989f
static float calcHorizonRateMagnitude(const pidProfile_t *pidProfile, const rxConfig_t *rxConfig)
{
// Figure out the raw stick positions
const int32_t stickPosAil = ABS(getRcStickDeflection(FD_ROLL, rxConfig->midrc));
const int32_t stickPosEle = ABS(getRcStickDeflection(FD_PITCH, rxConfig->midrc));
const int32_t mostDeflectedPos = MAX(stickPosAil, stickPosEle);
const float mostDeflectedStickPos = constrain(MAX(stickPosAil, stickPosEle), 0, 500) / 500.0f;
const float modeTransitionStickPos = constrain(pidProfile->D8[PIDLEVEL], 0, 100) / 100.0f;

float horizonRateMagnitude = mostDeflectedPos / 500.0f;
float horizonRateMagnitude;

if (horizonRateMagnitude <= modeTransitionStickPos) {
horizonRateMagnitude *= STICK_DEFLECTION_AT_MODE_TRANSITION / modeTransitionStickPos;
// Calculate transition point according to stick deflection
if (mostDeflectedStickPos <= modeTransitionStickPos) {
horizonRateMagnitude = mostDeflectedStickPos / modeTransitionStickPos;
}
else {
horizonRateMagnitude = (horizonRateMagnitude - modeTransitionStickPos) *
(1.0f - STICK_DEFLECTION_AT_MODE_TRANSITION) / (1.0f - modeTransitionStickPos) +
STICK_DEFLECTION_AT_MODE_TRANSITION;
horizonRateMagnitude = 1.0f;
}

return horizonRateMagnitude;
Expand Down

0 comments on commit 36954a8

Please sign in to comment.