Skip to content

Commit

Permalink
Sub: lthall updates for offset handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lthall authored and rmackay9 committed Sep 28, 2024
1 parent 08233b4 commit 0cd349f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ void GCS_MAVLINK_Sub::handle_message(const mavlink_message_t &msg)
*/

if (!z_ignore && sub.control_mode == Mode::Number::ALT_HOLD) { // Control only target depth when in ALT_HOLD
sub.pos_control.set_pos_target_z_cm(packet.alt*100);
sub.pos_control.set_pos_desired_z_cm(packet.alt*100);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion ArduSub/mode_acro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

bool ModeAcro::init(bool ignore_checks) {
// set target altitude to zero for reporting
position_control->set_pos_target_z_cm(0);
position_control->set_pos_desired_z_cm(0);

// attitude hold inputs become thrust inputs in acro mode
// set to neutral to prevent chaotic behavior (esp. roll/pitch)
Expand Down
4 changes: 2 additions & 2 deletions ArduSub/mode_althold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ void ModeAlthold::control_depth() {
//we allow full control to the pilot, but as soon as there's no input, we handle being at surface/bottom
if (fabsf(target_climb_rate_cm_s) < 0.05f) {
if (sub.ap.at_surface) {
position_control->set_pos_target_z_cm(MIN(position_control->get_pos_target_z_cm(), g.surface_depth - 5.0f)); // set target to 5 cm below surface level
position_control->set_pos_desired_z_cm(MIN(position_control->get_pos_desired_z_cm(), g.surface_depth - 5.0f)); // set target to 5 cm below surface level
} else if (sub.ap.at_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())); // set target to 10 cm above bottom
position_control->set_pos_desired_z_cm(MAX(inertial_nav.get_position_z_up_cm() + 10.0f, position_control->get_pos_desired_z_cm())); // set target to 10 cm above bottom
}
}

Expand Down
2 changes: 1 addition & 1 deletion ArduSub/mode_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

bool ModeManual::init(bool ignore_checks) {
// set target altitude to zero for reporting
position_control->set_pos_target_z_cm(0);
position_control->set_pos_desired_z_cm(0);

// attitude hold inputs become thrust inputs in manual mode
// set to neutral to prevent chaotic behavior (esp. roll/pitch)
Expand Down
2 changes: 1 addition & 1 deletion ArduSub/mode_stabilize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

bool ModeStabilize::init(bool ignore_checks) {
// set target altitude to zero for reporting
position_control->set_pos_target_z_cm(0);
position_control->set_pos_desired_z_cm(0);
sub.last_pilot_heading = ahrs.yaw_sensor;

return true;
Expand Down
12 changes: 5 additions & 7 deletions ArduSub/mode_surftrak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ bool ModeSurftrak::set_rangefinder_target_cm(float target_cm)

// Initialize the terrain offset
auto terrain_offset_cm = sub.inertial_nav.get_position_z_up_cm() - rangefinder_target_cm;
sub.pos_control.set_pos_offset_z_cm(terrain_offset_cm);
sub.pos_control.set_pos_offset_target_z_cm(terrain_offset_cm);
sub.pos_control.init_pos_terrain_cm(terrain_offset_cm);

} else {
reset();
Expand All @@ -97,8 +96,7 @@ void ModeSurftrak::reset()
rangefinder_target_cm = INVALID_TARGET;

// Reset the terrain offset
sub.pos_control.set_pos_offset_z_cm(0);
sub.pos_control.set_pos_offset_target_z_cm(0);
sub.pos_control.init_pos_terrain_cm(0);
}

/*
Expand All @@ -117,11 +115,11 @@ void ModeSurftrak::control_range() {
}
if (sub.ap.at_surface) {
// Set target depth to 5 cm below SURFACE_DEPTH and reset
position_control->set_pos_target_z_cm(MIN(position_control->get_pos_target_z_cm(), g.surface_depth - 5.0f));
position_control->set_pos_desired_z_cm(MIN(position_control->get_pos_desired_z_cm(), g.surface_depth - 5.0f));
reset();
} else if (sub.ap.at_bottom) {
// Set target depth to 10 cm above bottom and reset
position_control->set_pos_target_z_cm(MAX(inertial_nav.get_position_z_up_cm() + 10.0f, position_control->get_pos_target_z_cm()));
position_control->set_pos_desired_z_cm(MAX(inertial_nav.get_position_z_up_cm() + 10.0f, position_control->get_pos_desired_z_cm()));
reset();
} else {
// Typical operation
Expand Down Expand Up @@ -164,7 +162,7 @@ void ModeSurftrak::update_surface_offset()
}

// Set the offset target, AC_PosControl will do the rest
sub.pos_control.set_pos_offset_target_z_cm(rangefinder_terrain_offset_cm);
sub.pos_control.set_pos_terrain_target_cm(rangefinder_terrain_offset_cm);
}
}
#endif // AP_RANGEFINDER_ENABLED
Expand Down

0 comments on commit 0cd349f

Please sign in to comment.