forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmode_qacro.cpp
69 lines (56 loc) · 2.33 KB
/
mode_qacro.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "mode.h"
#include "Plane.h"
#if HAL_QUADPLANE_ENABLED
bool ModeQAcro::_enter()
{
quadplane.throttle_wait = false;
quadplane.transition->force_transition_complete();
attitude_control->relax_attitude_controllers();
// disable yaw rate time contant to mantain old behaviour
quadplane.disable_yaw_rate_time_constant();
IGNORE_RETURN(ahrs.get_quaternion(plane.mode_acro.acro_state.q));
return true;
}
void ModeQAcro::update()
{
// 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;
}
/*
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);
}
}
#endif