Skip to content

Commit

Permalink
Removed IMU kP gain scaling based on spin rate. Works better without …
Browse files Browse the repository at this point in the history
…it in real life
  • Loading branch information
digitalentity committed Nov 7, 2015
1 parent 5c8970e commit 621008c
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/main/flight/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,14 @@ static bool imuUseFastGains(void)
return !ARMING_FLAG(ARMED) && millis() < 20000;
}

// Taken from http://gentlenav.googlecode.com/files/fastRotations.pdf
static float imuGetPGainScaleFactor(float spin_rate)
{
if (spin_rate < DEGREES_TO_RADIANS(50)) {
return 1.0f;
}
else if (spin_rate > DEGREES_TO_RADIANS(500)) {
if (imuUseFastGains()) {
return 10.0f;
}

return spin_rate / DEGREES_TO_RADIANS(50);
else {
return 1.0f;
}
}

static void imuMahonyAHRSupdate(float dt, float gx, float gy, float gz,
Expand Down Expand Up @@ -309,13 +306,7 @@ static void imuMahonyAHRSupdate(float dt, float gx, float gy, float gz,
}

// Calculate kP gain. If we are acquiring initial attitude (not armed and within 20 sec from powerup) scale the kP to converge faster
float dcmKpGain = imuRuntimeConfig->dcm_kp;
if (imuUseFastGains()) {
dcmKpGain *= 10;
}
else {
dcmKpGain *= imuGetPGainScaleFactor(spin_rate);
}
float dcmKpGain = imuRuntimeConfig->dcm_kp * imuGetPGainScaleFactor(spin_rate);

// Apply proportional and integral feedback
gx += dcmKpGain * ex + integralFBx;
Expand Down

0 comments on commit 621008c

Please sign in to comment.