-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca935ef
commit aa37855
Showing
16 changed files
with
259 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "Sub.h" | ||
|
||
/* | ||
* RNG_HOLD (rangefinder hold) -- a variation on ALT_HOLD (depth hold) | ||
* | ||
* The real work for ALT_HOLD and RNG_HOLD is handled by AC_PosControl, which provides 2 inputs for depth: | ||
* -- target depth (sub.pos_control._pos_target.z). This is the desired depth, plus an offset. | ||
* -- target offset (sub.pos_control._pos_offset_target_z). This is the desired offset. | ||
* | ||
* ALT_HOLD and RNG_HOLD set the target depth in these situations: | ||
* -- During initialization, we call pos_control.init_z_controller(). This sets target depth to the current depth. | ||
* -- If the sub hits the surface or bottom we call pos_control.set_pos_target_z_cm(). | ||
* -- If the pilot takes control we call pos_control.set_pos_target_z_from_climb_rate_cm(). | ||
* | ||
* At the end of the control loop ALT_HOLD and RNG_HOLD call pos_control.update_z_controller() to pass the buck. | ||
* | ||
* ALT_HOLD does not use the target offset. | ||
* | ||
* RNG_HOLD sets the target offset to implement surface tracking. This is handled by Sub::SurfaceTracking. We call | ||
* SurfaceTracking in these situations: | ||
* -- During initialization, we call surface_tracking.enable(). | ||
* -- During normal operation, we call surface_tracking.update_surface_offset(). | ||
* -- If the sub hits the surface or bottom, or the pilot takes control, we call surface_tracking.reset(). | ||
*/ | ||
|
||
bool ModeRnghold::init(bool ignore_checks) | ||
{ | ||
if (!ModeAlthold::init(ignore_checks)) { | ||
return false; | ||
} | ||
|
||
// enable surface tracking | ||
sub.surface_tracking.enable(true); | ||
|
||
return true; | ||
} | ||
|
||
void ModeRnghold::run() | ||
{ | ||
run_pre(); | ||
control_range(); | ||
run_post(); | ||
} | ||
|
||
void ModeRnghold::control_range() { | ||
float target_climb_rate_cm_s = sub.get_pilot_desired_climb_rate(channel_throttle->get_control_in()); | ||
target_climb_rate_cm_s = constrain_float(target_climb_rate_cm_s, -sub.get_pilot_speed_dn(), g.pilot_speed_up); | ||
|
||
// desired_climb_rate returns 0 when within the deadzone | ||
if (fabsf(target_climb_rate_cm_s) < 0.05f) { | ||
if (sub.ap.at_surface) { | ||
// set target depth to 5 cm below SURFACE_DEPTH | ||
position_control->set_pos_target_z_cm(MIN(position_control->get_pos_target_z_cm(), g.surface_depth - 5.0f)); | ||
sub.surface_tracking.reset(); | ||
} else if (sub.ap.at_bottom) { | ||
// set target depth to 10 cm above bottom | ||
position_control->set_pos_target_z_cm(MAX(inertial_nav.get_position_z_up_cm() + 10.0f, position_control->get_pos_target_z_cm())); | ||
sub.surface_tracking.reset(); | ||
} else { | ||
// normal operation | ||
sub.surface_tracking.update_surface_offset(); | ||
} | ||
} else { | ||
// pilot is in control | ||
sub.surface_tracking.reset(); | ||
} | ||
|
||
// set the target z from the climb rate and the z offset, and adjust the z vel and accel targets | ||
position_control->set_pos_target_z_from_climb_rate_cm(target_climb_rate_cm_s); | ||
|
||
// run the z vel and accel PID controllers | ||
position_control->update_z_controller(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.