Skip to content

Commit 8aa3c36

Browse files
committed
Copter: trust control values from get_pilot_desired_lean_angles etc
this stops ArduCopter looking at the RC failsafe values before trusting return values from varios methods like get_pilot_target_climb_rate_cms Several other modes already make the assumption that if there's no good pilot input that these methods return 0
1 parent aed7d78 commit 8aa3c36

File tree

2 files changed

+48
-70
lines changed

2 files changed

+48
-70
lines changed

ArduCopter/mode_loiter.cpp

+21-31
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,16 @@
99
// loiter_init - initialise loiter controller
1010
bool ModeLoiter::init(bool ignore_checks)
1111
{
12-
if (!copter.failsafe.radio) {
13-
float target_roll, target_pitch;
14-
// apply SIMPLE mode transform to pilot inputs
15-
update_simple_mode();
16-
17-
// convert pilot input to lean angles
18-
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
19-
20-
// process pilot's roll and pitch input
21-
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
22-
} else {
23-
// clear out pilot desired acceleration in case radio failsafe event occurs and we do not switch to RTL for some reason
24-
loiter_nav->clear_pilot_desired_acceleration();
25-
}
12+
float target_roll, target_pitch;
13+
// apply SIMPLE mode transform to pilot inputs
14+
update_simple_mode();
15+
16+
// convert pilot input to lean angles
17+
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
18+
19+
// process pilot's roll and pitch input
20+
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
21+
2622
loiter_nav->init_target();
2723

2824
// initialise the vertical position controller
@@ -90,27 +86,21 @@ void ModeLoiter::run()
9086
// set vertical speed and acceleration limits
9187
pos_control->set_max_speed_accel_U_cm(-get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
9288

93-
// process pilot inputs unless we are in radio failsafe
94-
if (!copter.failsafe.radio) {
95-
// apply SIMPLE mode transform to pilot inputs
96-
update_simple_mode();
89+
// apply SIMPLE mode transform to pilot inputs
90+
update_simple_mode();
9791

98-
// convert pilot input to lean angles
99-
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
92+
// convert pilot input to lean angles
93+
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
10094

101-
// process pilot's roll and pitch input
102-
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
95+
// process pilot's roll and pitch input
96+
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
10397

104-
// get pilot's desired yaw rate
105-
target_yaw_rate = get_pilot_desired_yaw_rate();
98+
// get pilot's desired yaw rate
99+
target_yaw_rate = get_pilot_desired_yaw_rate();
106100

107-
// get pilot desired climb rate
108-
target_climb_rate = get_pilot_desired_climb_rate();
109-
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
110-
} else {
111-
// clear out pilot desired acceleration in case radio failsafe event occurs and we do not switch to RTL for some reason
112-
loiter_nav->clear_pilot_desired_acceleration();
113-
}
101+
// get pilot desired climb rate
102+
target_climb_rate = get_pilot_desired_climb_rate();
103+
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
114104

115105
// relax loiter target if we might be landed
116106
if (copter.ap.land_complete_maybe) {

ArduCopter/mode_zigzag.cpp

+27-39
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,16 @@ ModeZigZag::ModeZigZag(void) : Mode()
6767
// initialise zigzag controller
6868
bool ModeZigZag::init(bool ignore_checks)
6969
{
70-
if (!copter.failsafe.radio) {
71-
// apply simple mode transform to pilot inputs
72-
update_simple_mode();
70+
// apply simple mode transform to pilot inputs
71+
update_simple_mode();
7372

74-
// convert pilot input to lean angles
75-
float target_roll, target_pitch;
76-
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
73+
// convert pilot input to lean angles
74+
float target_roll, target_pitch;
75+
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
76+
77+
// process pilot's roll and pitch input
78+
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
7779

78-
// process pilot's roll and pitch input
79-
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
80-
} else {
81-
// clear out pilot desired acceleration in case radio failsafe event occurs and we do not switch to RTL for some reason
82-
loiter_nav->clear_pilot_desired_acceleration();
83-
}
8480
loiter_nav->init_target();
8581

8682
// set vertical speed and acceleration limits
@@ -261,11 +257,7 @@ void ModeZigZag::return_to_manual_control(bool maintain_target)
261257
void ModeZigZag::auto_control()
262258
{
263259
// process pilot's yaw input
264-
float target_yaw_rate = 0;
265-
if (!copter.failsafe.radio) {
266-
// get pilot's desired yaw rate
267-
target_yaw_rate = get_pilot_desired_yaw_rate();
268-
}
260+
const float target_yaw_rate = get_pilot_desired_yaw_rate();
269261

270262
// set motors to full range
271263
motors->set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
@@ -294,28 +286,24 @@ void ModeZigZag::manual_control()
294286
float target_climb_rate = 0.0f;
295287

296288
// process pilot inputs unless we are in radio failsafe
297-
if (!copter.failsafe.radio) {
298-
float target_roll, target_pitch;
299-
// apply SIMPLE mode transform to pilot inputs
300-
update_simple_mode();
301-
302-
// convert pilot input to lean angles
303-
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
304-
305-
// process pilot's roll and pitch input
306-
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
307-
// get pilot's desired yaw rate
308-
target_yaw_rate = get_pilot_desired_yaw_rate();
309-
310-
// get pilot desired climb rate
311-
target_climb_rate = get_pilot_desired_climb_rate();
312-
// make sure the climb rate is in the given range, prevent floating point errors
313-
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
314-
} else {
315-
// clear out pilot desired acceleration in case radio failsafe event occurs and we
316-
// do not switch to RTL for some reason
317-
loiter_nav->clear_pilot_desired_acceleration();
318-
}
289+
float target_roll, target_pitch;
290+
291+
// apply SIMPLE mode transform to pilot inputs
292+
update_simple_mode();
293+
294+
// convert pilot input to lean angles
295+
get_pilot_desired_lean_angles(target_roll, target_pitch, loiter_nav->get_angle_max_cd(), attitude_control->get_althold_lean_angle_max_cd());
296+
297+
// process pilot's roll and pitch input
298+
loiter_nav->set_pilot_desired_acceleration_cd(target_roll, target_pitch);
299+
300+
// get pilot's desired yaw rate
301+
target_yaw_rate = get_pilot_desired_yaw_rate();
302+
303+
// get pilot desired climb rate
304+
target_climb_rate = get_pilot_desired_climb_rate();
305+
// make sure the climb rate is in the given range, prevent floating point errors
306+
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
319307

320308
// relax loiter target if we might be landed
321309
if (copter.ap.land_complete_maybe) {

0 commit comments

Comments
 (0)