2019-01-15 13:46:13 -04:00
|
|
|
#include "mode.h"
|
|
|
|
#include "Plane.h"
|
|
|
|
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
bool ModeQAcro::_enter()
|
2021-08-14 15:52:04 -03:00
|
|
|
{
|
|
|
|
quadplane.throttle_wait = false;
|
2022-06-29 09:35:55 -03:00
|
|
|
quadplane.transition->force_transition_complete();
|
2021-08-14 15:52:04 -03:00
|
|
|
attitude_control->relax_attitude_controllers();
|
2022-07-03 19:39:05 -03:00
|
|
|
|
|
|
|
// disable yaw rate time contant to mantain old behaviour
|
|
|
|
quadplane.disable_yaw_rate_time_constant();
|
|
|
|
|
2022-10-31 08:09:41 -03:00
|
|
|
IGNORE_RETURN(plane.ahrs.get_quaternion(plane.acro_state.q));
|
|
|
|
|
2021-09-04 16:20:12 -03:00
|
|
|
return true;
|
2021-08-14 15:52:04 -03:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
void ModeQAcro::update()
|
|
|
|
{
|
2019-05-03 20:37:10 -03:00
|
|
|
// get nav_roll and nav_pitch from multicopter attitude controller
|
|
|
|
Vector3f att_target = plane.quadplane.attitude_control->get_att_target_euler_cd();
|
|
|
|
plane.nav_pitch_cd = att_target.y;
|
|
|
|
plane.nav_roll_cd = att_target.x;
|
|
|
|
return;
|
2019-01-15 13:46:13 -04:00
|
|
|
}
|
|
|
|
|
2021-08-14 15:52:04 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
control QACRO mode
|
|
|
|
*/
|
|
|
|
void ModeQAcro::run()
|
|
|
|
{
|
|
|
|
if (quadplane.throttle_wait) {
|
|
|
|
quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
|
|
|
|
attitude_control->set_throttle_out(0, true, 0);
|
|
|
|
quadplane.relax_attitude_control();
|
|
|
|
} else {
|
|
|
|
quadplane.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
|
|
|
|
|
|
|
|
// convert the input to the desired body frame rate
|
|
|
|
float target_roll = 0;
|
|
|
|
float target_pitch = plane.channel_pitch->norm_input() * quadplane.acro_pitch_rate * 100.0f;
|
|
|
|
float target_yaw = 0;
|
|
|
|
if (quadplane.tailsitter.enabled()) {
|
|
|
|
// Note that the 90 degree Y rotation for copter mode swaps body-frame roll and yaw
|
|
|
|
target_roll = plane.channel_rudder->norm_input() * quadplane.acro_yaw_rate * 100.0f;
|
|
|
|
target_yaw = -plane.channel_roll->norm_input() * quadplane.acro_roll_rate * 100.0f;
|
|
|
|
} else {
|
|
|
|
target_roll = plane.channel_roll->norm_input() * quadplane.acro_roll_rate * 100.0f;
|
|
|
|
target_yaw = plane.channel_rudder->norm_input() * quadplane.acro_yaw_rate * 100.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float throttle_out = quadplane.get_pilot_throttle();
|
|
|
|
|
|
|
|
// run attitude controller
|
|
|
|
if (plane.g.acro_locking) {
|
|
|
|
attitude_control->input_rate_bf_roll_pitch_yaw_3(target_roll, target_pitch, target_yaw);
|
|
|
|
} else {
|
|
|
|
attitude_control->input_rate_bf_roll_pitch_yaw_2(target_roll, target_pitch, target_yaw);
|
|
|
|
}
|
|
|
|
|
|
|
|
// output pilot's throttle without angle boost
|
|
|
|
attitude_control->set_throttle_out(throttle_out, false, 10.0f);
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
|
|
|
|
#endif
|