ardupilot/ArduCopter/control_brake.cpp

93 lines
3.0 KiB
C++
Raw Normal View History

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
#include "Copter.h"
/*
2015-05-17 00:22:20 -03:00
* control_brake.pde - init and run calls for brake flight mode
*/
2015-05-17 00:22:20 -03:00
// brake_init - initialise brake controller
bool Copter::brake_init(bool ignore_checks)
{
if (position_ok() || ignore_checks) {
// set desired acceleration to zero
wp_nav.clear_pilot_desired_acceleration();
// set target to current position
2015-05-17 00:22:20 -03:00
wp_nav.init_brake_target(BRAKE_MODE_DECEL_RATE);
// initialize vertical speed and acceleration
2015-06-05 03:29:00 -03:00
pos_control.set_speed_z(BRAKE_MODE_SPEED_Z, BRAKE_MODE_SPEED_Z);
2015-05-17 00:22:20 -03:00
pos_control.set_accel_z(BRAKE_MODE_DECEL_RATE);
// 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());
2016-01-05 02:12:25 -04:00
brake_timeout_ms = 0;
return true;
}else{
return false;
}
}
2015-05-17 00:22:20 -03:00
// brake_run - runs the brake controller
// should be called at 100hz or more
void Copter::brake_run()
{
// if not auto armed set throttle to zero and exit immediately
2016-01-13 03:09:42 -04:00
if (!motors.armed() || !ap.auto_armed || !motors.get_interlock()) {
2015-05-17 00:22:20 -03:00
wp_nav.init_brake_target(BRAKE_MODE_DECEL_RATE);
#if FRAME_CONFIG == HELI_FRAME // Helicopters always stabilize roll/pitch/yaw
// call attitude controller
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(0, 0, 0, get_smoothing_gain());
attitude_control.set_throttle_out(0,false,g.throttle_filt);
2016-01-13 03:09:42 -04:00
#else
motors.set_desired_spool_state(AP_Motors::DESIRED_SPIN_WHEN_ARMED);
2016-01-13 03:09:42 -04:00
// multicopters do not stabilize roll/pitch/yaw when disarmed
attitude_control.set_throttle_out_unstabilized(0,true,g.throttle_filt);
#endif
pos_control.relax_alt_hold_controllers(get_throttle_pre_takeoff(0)-motors.get_throttle_hover());
return;
}
// relax stop target if we might be landed
2015-05-06 01:38:38 -03:00
if (ap.land_complete_maybe) {
2015-05-17 02:28:55 -03:00
wp_nav.loiter_soften_for_landing();
}
// if landed immediately disarm
if (ap.land_complete) {
init_disarm_motors();
}
2016-01-13 03:09:42 -04:00
// set motors to full range
motors.set_desired_spool_state(AP_Motors::DESIRED_THROTTLE_UNLIMITED);
2016-01-13 03:09:42 -04:00
2015-05-17 00:22:20 -03:00
// run brake controller
wp_nav.update_brake(ekfGndSpdLimit, ekfNavVelGainScaler);
// call attitude controller
attitude_control.input_euler_angle_roll_pitch_euler_rate_yaw(wp_nav.get_roll(), wp_nav.get_pitch(), 0.0f, get_smoothing_gain());
// body-frame rate controller is run directly from 100hz loop
// update altitude target and call position controller
pos_control.set_alt_target_from_climb_rate_ff(0.0f, G_Dt, false);
pos_control.update_z_controller();
2016-01-05 02:12:25 -04:00
if (brake_timeout_ms != 0 && millis()-brake_timeout_start >= brake_timeout_ms) {
if (!set_mode(LOITER, MODE_REASON_BRAKE_TIMEOUT)) {
set_mode(ALT_HOLD, MODE_REASON_BRAKE_TIMEOUT);
2016-01-05 02:12:25 -04:00
}
}
}
void Copter::brake_timeout_to_loiter_ms(uint32_t timeout_ms)
{
brake_timeout_start = millis();
brake_timeout_ms = timeout_ms;
}