Skip to content

Commit

Permalink
Plane: remove trig calls from constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
kd0aij authored and tridge committed Mar 27, 2019
1 parent 494a3f8 commit b3f093b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ArduPlane/tailsitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,18 @@ void QuadPlane::tailsitter_speed_scaling(void)
} else {
// if no airspeed sensor reduce control surface throws at large tilt
// angles (assuming high airspeed)

// ramp down from 1 to max_atten at tilt angles over trans_angle
// (angles here are represented by their cosines)
constexpr float c_trans_angle = cosf(.125f * M_PI);
constexpr float alpha = (1 - max_atten) / (c_trans_angle - cosf(radians(90)));

// Note that the cosf call will be necessary if trans_angle becomes a parameter
// but the C language spec does not guarantee that trig functions can be used
// in constant expressions, even though gcc currently allows it.
constexpr float c_trans_angle = 0.9238795; // cosf(.125f * M_PI)

// alpha = (1 - max_atten) / (c_trans_angle - cosf(radians(90)));
constexpr float alpha = (1 - max_atten) / c_trans_angle;
constexpr float beta = 1 - alpha * c_trans_angle;

const float c_tilt = ahrs_view->get_rotation_body_to_ned().c.z;
if (c_tilt < c_trans_angle) {
spd_scaler = constrain_float(beta + alpha * c_tilt, max_atten, 1.0f);
Expand Down

0 comments on commit b3f093b

Please sign in to comment.