|
|
|
@ -94,31 +94,35 @@ float Copter::get_look_ahead_yaw()
@@ -94,31 +94,35 @@ float Copter::get_look_ahead_yaw()
|
|
|
|
|
* throttle control |
|
|
|
|
****************************************************************/ |
|
|
|
|
|
|
|
|
|
// update_thr_average - update estimated throttle required to hover (if necessary)
|
|
|
|
|
// should be called at 100hz
|
|
|
|
|
void Copter::update_thr_average() |
|
|
|
|
// update estimated throttle required to hover (if necessary)
|
|
|
|
|
// called at 100hz
|
|
|
|
|
void Copter::update_throttle_hover() |
|
|
|
|
{ |
|
|
|
|
// ensure throttle_average has been initialised
|
|
|
|
|
if( is_zero(throttle_average) ) { |
|
|
|
|
throttle_average = 0.5f; |
|
|
|
|
// update position controller
|
|
|
|
|
pos_control.set_throttle_hover(throttle_average); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if FRAME_CONFIG != HELI_FRAME |
|
|
|
|
// if not armed or landed exit
|
|
|
|
|
if (!motors.armed() || ap.land_complete) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// do not update in manual throttle modes or Drift
|
|
|
|
|
if (mode_has_manual_throttle(control_mode) || (control_mode == DRIFT)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// do not update while climbing or descending
|
|
|
|
|
if (!is_zero(pos_control.get_desired_velocity().z)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// get throttle output
|
|
|
|
|
float throttle = motors.get_throttle(); |
|
|
|
|
|
|
|
|
|
// calc average throttle if we are in a level hover
|
|
|
|
|
if (throttle > 0.0f && abs(climb_rate) < 60 && labs(ahrs.roll_sensor) < 500 && labs(ahrs.pitch_sensor) < 500) { |
|
|
|
|
throttle_average = throttle_average * 0.99f + throttle * 0.01f; |
|
|
|
|
// update position controller
|
|
|
|
|
pos_control.set_throttle_hover(throttle_average); |
|
|
|
|
// Can we set the time constant automatically
|
|
|
|
|
motors.update_throttle_hover(0.01f); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set_throttle_takeoff - allows parents to tell throttle controller we are taking off so I terms can be cleared
|
|
|
|
@ -141,7 +145,7 @@ float Copter::get_pilot_desired_throttle(int16_t throttle_control)
@@ -141,7 +145,7 @@ float Copter::get_pilot_desired_throttle(int16_t throttle_control)
|
|
|
|
|
throttle_control = constrain_int16(throttle_control,0,1000); |
|
|
|
|
// ensure mid throttle is set within a reasonable range
|
|
|
|
|
g.throttle_mid = constrain_int16(g.throttle_mid,g.throttle_min+50,700); |
|
|
|
|
float thr_mid = MAX(0,g.throttle_mid-g.throttle_min) / (float)(1000-g.throttle_min); |
|
|
|
|
float thr_mid = constrain_float(motors.get_throttle_hover(), 0.1f, 0.9f); |
|
|
|
|
|
|
|
|
|
// check throttle is above, below or in the deadband
|
|
|
|
|
if (throttle_control < mid_stick) { |
|
|
|
@ -201,7 +205,7 @@ float Copter::get_non_takeoff_throttle()
@@ -201,7 +205,7 @@ float Copter::get_non_takeoff_throttle()
|
|
|
|
|
{ |
|
|
|
|
// ensure mid throttle is set within a reasonable range
|
|
|
|
|
g.throttle_mid = constrain_int16(g.throttle_mid,g.throttle_min+50,700); |
|
|
|
|
return MAX(0,g.throttle_mid-g.throttle_min) / ((float)(1000-g.throttle_min) * 2.0f); |
|
|
|
|
return MAX(0,motors.get_throttle_hover()/2.0f); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float Copter::get_takeoff_trigger_throttle() |
|
|
|
@ -285,7 +289,7 @@ float Copter::get_surface_tracking_climb_rate(int16_t target_rate, float current
@@ -285,7 +289,7 @@ float Copter::get_surface_tracking_climb_rate(int16_t target_rate, float current
|
|
|
|
|
void Copter::set_accel_throttle_I_from_pilot_throttle(float pilot_throttle) |
|
|
|
|
{ |
|
|
|
|
// shift difference between pilot's throttle and hover throttle into accelerometer I
|
|
|
|
|
g.pid_accel_z.set_integrator((pilot_throttle-throttle_average) * 1000.0f); |
|
|
|
|
g.pid_accel_z.set_integrator((pilot_throttle-motors.get_throttle_hover()) * 1000.0f); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// updates position controller's maximum altitude using fence and EKF limits
|
|
|
|
|