Sub: Improve althold to handle small inputs with payload/buyoancy better

This commit is contained in:
Willian Galvani 2020-09-04 00:31:33 -03:00
parent d149602742
commit 0b6ae3e5d4

View File

@ -37,7 +37,7 @@ void Sub::althold_run()
if (!motors.armed()) { if (!motors.armed()) {
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE); motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
// Sub vehicles do not stabilize roll/pitch/yaw when not auto-armed (i.e. on the ground, pilot has never raised throttle) // Sub vehicles do not stabilize roll/pitch/yaw when not auto-armed (i.e. on the ground, pilot has never raised throttle)
attitude_control.set_throttle_out(0,true,g.throttle_filt); attitude_control.set_throttle_out(0.5,true,g.throttle_filt);
attitude_control.relax_attitude_controllers(); attitude_control.relax_attitude_controllers();
pos_control.relax_z_controller(motors.get_throttle_hover()); pos_control.relax_z_controller(motors.get_throttle_hover());
last_pilot_heading = ahrs.yaw_sensor; last_pilot_heading = ahrs.yaw_sensor;
@ -101,33 +101,20 @@ void Sub::althold_run()
} }
void Sub::control_depth() { void Sub::control_depth() {
// Hold actual position until zero derivative is detected float target_climb_rate_cm_s = get_pilot_desired_climb_rate(channel_throttle->get_control_in());
static bool engageStopZ = true; target_climb_rate_cm_s = constrain_float(target_climb_rate_cm_s, -get_pilot_speed_dn(), g.pilot_speed_up);
// Get last user velocity direction to check for zero derivative points
static bool lastVelocityZWasNegative = false;
if (fabsf(channel_throttle->norm_input()-0.5f) > 0.05f) { // Throttle input above 5%
// output pilot's throttle
attitude_control.set_throttle_out(channel_throttle->norm_input(), false, g.throttle_filt);
// reset z targets to current values
pos_control.relax_z_controller(channel_throttle->norm_input());
engageStopZ = true;
lastVelocityZWasNegative = is_negative(inertial_nav.get_velocity_z());
} else { // hold z
if (ap.at_bottom) { // desired_climb_rate returns 0 when within the deadzone.
pos_control.init_z_controller(); //we allow full control to the pilot, but as soon as there's no input, we handle being at surface/bottom
pos_control.set_pos_target_z_cm(inertial_nav.get_altitude() + 10.0f); // set target to 10 cm above bottom if (fabsf(target_climb_rate_cm_s) < 0.05f) {
} if (ap.at_surface) {
pos_control.set_pos_target_z_cm(MIN(pos_control.get_pos_target_z_cm(), g.surface_depth - 5.0f)); // set target to 5 cm below surface level
// Detects a zero derivative } else if (ap.at_bottom) {
// When detected, move the altitude set point to the actual position pos_control.set_pos_target_z_cm(MAX(inertial_nav.get_altitude() + 10.0f, pos_control.get_pos_target_z_cm())); // set target to 10 cm above bottom
// This will avoid any problem related to joystick delays }
// or smaller input signals
if(engageStopZ && (lastVelocityZWasNegative ^ is_negative(inertial_nav.get_velocity_z()))) {
engageStopZ = false;
pos_control.init_z_controller();
} }
pos_control.set_pos_target_z_from_climb_rate_cm(target_climb_rate_cm_s);
pos_control.update_z_controller(); pos_control.update_z_controller();
}
} }