Skip to content

Commit 4277dba

Browse files
Williangalvanipeterbarker
authored andcommitted
Sub: allow surface mode to operate with no baro
Co-authored-by: Peter Barker <pb-gh@barker.dropbear.id.au>
1 parent da8b168 commit 4277dba

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

ArduSub/Parameters.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,14 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = {
775775
// @User: Standard
776776
AP_GROUPINFO("ORIGIN_ALT", 21, ParametersG2, backup_origin_alt, 0),
777777

778+
// @Param: SFC_NOBARO_THST
779+
// @DisplayName: Surface mode throttle output when no barometer is available
780+
// @Description: Surface mode throttle output when no borometer is available. 100% is full throttle. -100% is maximum throttle downwards
781+
// @Units: %
782+
// @User: Standard
783+
// @Range: -100 100
784+
AP_GROUPINFO("SFC_NOBARO_THST", 22, ParametersG2, surface_nobaro_thrust, 10),
785+
778786
AP_GROUPEND
779787
};
780788

ArduSub/Parameters.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class Parameters {
209209
k_param_cam_tilt_center, // deprecated
210210
k_param_frame_configuration,
211211
k_param_surface_max_throttle,
212-
212+
k_param_surface_nobaro_thrust,
213213
// 200: flight modes
214214
k_param_flight_mode1 = 200,
215215
k_param_flight_mode2,
@@ -404,6 +404,7 @@ class ParametersG2 {
404404
AP_Float backup_origin_lat;
405405
AP_Float backup_origin_lon;
406406
AP_Float backup_origin_alt;
407+
AP_Float surface_nobaro_thrust;
407408
};
408409

409410
extern const AP_Param::Info var_info[];

ArduSub/mode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,16 @@ class ModeSurface : public Mode
469469
virtual void run() override;
470470

471471
bool init(bool ignore_checks) override;
472-
bool requires_GPS() const override { return true; }
472+
bool requires_GPS() const override { return false; }
473473
bool has_manual_throttle() const override { return false; }
474474
bool allows_arming(bool from_gcs) const override { return true; }
475475
bool is_autopilot() const override { return true; }
476476

477477
protected:
478-
479478
const char *name() const override { return "SURFACE"; }
480479
const char *name4() const override { return "SURF"; }
481480
Mode::Number number() const override { return Mode::Number::SURFACE; }
481+
bool sensorless_mode;
482482
};
483483

484484

ArduSub/mode_surface.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
bool ModeSurface::init(bool ignore_checks)
55
{
6-
if(!sub.control_check_barometer()) {
7-
return false;
8-
}
6+
sensorless_mode = !sub.control_check_barometer();
97

108
// initialize vertical speeds and acceleration
119
position_control->set_max_speed_accel_U_cm(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
@@ -32,28 +30,32 @@ void ModeSurface::run()
3230
return;
3331
}
3432

35-
// Already at surface, hold depth at surface
36-
if (sub.ap.at_surface) {
37-
set_mode(Mode::Number::ALT_HOLD, ModeReason::SURFACE_COMPLETE);
38-
}
39-
40-
// convert pilot input to lean angles
41-
// To-Do: convert sub.get_pilot_desired_lean_angles to return angles as floats
42-
sub.get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, sub.aparm.angle_max);
33+
if (sensorless_mode) {
34+
float thrust_output = 0.5f + g2.surface_sensorless_thrust * 0.005f; // map -100, 100 to 0, 1
35+
attitude_control->set_throttle_out(thrust_output, true, g.throttle_filt);
36+
} else {
37+
// Already at surface, hold depth at surface
38+
if (sub.ap.at_surface) {
39+
set_mode(Mode::Number::ALT_HOLD, ModeReason::SURFACE_COMPLETE);
40+
}
4341

44-
// get pilot's desired yaw rate
45-
float target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
42+
// convert pilot input to lean angles
43+
// To-Do: convert sub.get_pilot_desired_lean_angles to return angles as floats
44+
sub.get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, sub.aparm.angle_max);
4645

47-
// call attitude controller
48-
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw_cd(target_roll, target_pitch, target_yaw_rate);
46+
// get pilot's desired yaw rate
47+
float target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
4948

50-
// set target climb rate
51-
float cmb_rate_cms = constrain_float(fabsf(sub.wp_nav.get_default_speed_up_cms()), 1, position_control->get_max_speed_up_cms());
49+
// call attitude controller
50+
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw_cd(target_roll, target_pitch, target_yaw_rate);
5251

53-
// update altitude target and call position controller
54-
position_control->set_pos_target_U_from_climb_rate_cm(cmb_rate_cms);
55-
position_control->update_U_controller();
52+
// set target climb rate
53+
float cmb_rate_cms = constrain_float(fabsf(sub.wp_nav.get_default_speed_up_cms()), 1, position_control->get_max_speed_up_cms());
5654

55+
// update altitude target and call position controller
56+
position_control->set_pos_target_U_from_climb_rate_cm(cmb_rate_cms);
57+
position_control->update_U_controller();
58+
}
5759
// pilot has control for repositioning
5860
motors.set_forward(channel_forward->norm_input());
5961
motors.set_lateral(channel_lateral->norm_input());

0 commit comments

Comments
 (0)