mirror of https://github.com/ArduPilot/ardupilot
66 lines
2.3 KiB
C++
66 lines
2.3 KiB
C++
#include "Sub.h"
|
|
|
|
|
|
bool Sub::surface_init(bool ignore_checks)
|
|
{
|
|
|
|
if (!ap.depth_sensor_present) { // can't hold depth without a depth sensor, exit immediately.
|
|
gcs_send_text(MAV_SEVERITY_WARNING, "Surface mode requires external pressure sensor.");
|
|
return false;
|
|
}
|
|
|
|
// initialize vertical speeds and leash lengths
|
|
pos_control.set_speed_z(wp_nav.get_speed_down(), wp_nav.get_speed_up());
|
|
pos_control.set_accel_z(wp_nav.get_accel_z());
|
|
|
|
// initialise position and desired velocity
|
|
pos_control.set_alt_target(inertial_nav.get_altitude());
|
|
pos_control.set_desired_velocity_z(inertial_nav.get_velocity_z());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void Sub::surface_run()
|
|
{
|
|
float target_roll, target_pitch;
|
|
float target_yaw_rate;
|
|
|
|
// if not armed set throttle to zero and exit immediately
|
|
if (!motors.armed() || !motors.get_interlock()) {
|
|
motors.output_min();
|
|
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
|
|
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
|
|
return;
|
|
}
|
|
|
|
// Already at surface, hold depth at surface
|
|
if (ap.at_surface) {
|
|
set_mode(ALT_HOLD, MODE_REASON_SURFACE_COMPLETE);
|
|
}
|
|
|
|
// convert pilot input to lean angles
|
|
// To-Do: convert get_pilot_desired_lean_angles to return angles as floats
|
|
get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, aparm.angle_max);
|
|
|
|
// get pilot's desired yaw rate
|
|
target_yaw_rate = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
|
|
|
// call attitude controller
|
|
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(target_roll, target_pitch, target_yaw_rate, get_smoothing_gain());
|
|
|
|
// set target climb rate
|
|
float cmb_rate = constrain_float(abs(wp_nav.get_speed_up()), 1, pos_control.get_speed_up());
|
|
|
|
// record desired climb rate for logging
|
|
desired_climb_rate = cmb_rate;
|
|
|
|
// update altitude target and call position controller
|
|
pos_control.set_alt_target_from_climb_rate_ff(cmb_rate, G_Dt, true);
|
|
pos_control.update_z_controller();
|
|
|
|
// pilot has control for repositioning
|
|
motors.set_forward(channel_forward->norm_input());
|
|
motors.set_lateral(channel_lateral->norm_input());
|
|
}
|