3
3
4
4
bool ModeSurface::init (bool ignore_checks)
5
5
{
6
- if (!sub.control_check_barometer ()) {
7
- return false ;
8
- }
6
+ sensorless_mode = !sub.control_check_barometer ();
9
7
10
8
// initialize vertical speeds and acceleration
11
9
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()
32
30
return ;
33
31
}
34
32
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
+ }
43
41
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 );
46
45
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 () );
49
48
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 );
52
51
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 ());
56
54
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
+ }
57
59
// pilot has control for repositioning
58
60
motors.set_forward (channel_forward->norm_input ());
59
61
motors.set_lateral (channel_lateral->norm_input ());
0 commit comments