Sub: Fix overshoot from joystick input

This approach waits for a zero derivative point and to set the new actual position
Such method is necessary since the inertia of the ROV will cause overshoot

Fix #9797

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
This commit is contained in:
Patrick José Pereira 2019-03-06 10:47:35 -08:00 committed by Jacob Walser
parent ad81760bfd
commit 0e3d852150

View File

@ -78,11 +78,17 @@ void Sub::althold_run()
}
}
if (fabsf(channel_throttle->norm_input()-0.5) > 0.05) { // Throttle input above 5%
// Hold actual position until zero derivative is detected
static bool engageStopZ = true;
// 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_alt_hold_controllers(motors.get_throttle_hover());
engageStopZ = true;
lastVelocityZWasNegative = inertial_nav.get_velocity_z() < 0;
} else { // hold z
if (ap.at_bottom) {
@ -93,6 +99,16 @@ void Sub::althold_run()
float target_climb_rate = get_surface_tracking_climb_rate(0, pos_control.get_alt_target(), G_Dt);
pos_control.set_alt_target_from_climb_rate_ff(target_climb_rate, G_Dt, false);
}
// Detects a zero derivative
// When detected, move the altitude set point to the actual position
// This will avoid any problem related to joystick delays
// or smaller input signals
if(engageStopZ && (lastVelocityZWasNegative ^ (inertial_nav.get_velocity_z() < 0) )) {
engageStopZ = false;
pos_control.relax_alt_hold_controllers(motors.get_throttle_hover());
}
pos_control.update_z_controller();
}