Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/mode_circle.cpp
9402 views
1
#include "Sub.h"
2
3
/*
4
* control_circle.pde - init and run calls for circle flight mode
5
*/
6
7
// circle_init - initialise circle controller flight mode
8
bool ModeCircle::init(bool ignore_checks)
9
{
10
if (!sub.position_ok()) {
11
return false;
12
}
13
14
sub.circle_pilot_yaw_override = false;
15
16
// initialize speeds and accelerations
17
// All limits must be positive
18
position_control->NE_set_max_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
19
position_control->NE_set_correction_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
20
position_control->D_set_max_speed_accel_cm(sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
21
position_control->D_set_correction_speed_accel_cm(sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
22
23
// initialise circle controller including setting the circle center based on vehicle speed
24
sub.circle_nav.init();
25
26
return true;
27
}
28
29
// circle_run - runs the circle flight mode
30
// should be called at 100hz or more
31
void ModeCircle::run()
32
{
33
float target_yaw_rate = 0;
34
float target_climb_rate = 0;
35
36
// update parameters, to allow changing at runtime
37
// All limits must be positive
38
position_control->NE_set_max_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
39
position_control->D_set_max_speed_accel_cm(sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
40
41
// check for any change in params and update in real time
42
sub.circle_nav.check_param_change();
43
44
// if not armed set throttle to zero and exit immediately
45
if (!motors.armed()) {
46
// To-Do: add some initialisation of position controllers
47
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
48
// Sub vehicles do not stabilize roll/pitch/yaw when disarmed
49
attitude_control->set_throttle_out(NEUTRAL_THROTTLE,true,g.throttle_filt);
50
attitude_control->relax_attitude_controllers();
51
sub.circle_nav.init();
52
return;
53
}
54
55
// process pilot inputs
56
// get pilot's desired yaw rate
57
target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
58
if (!is_zero(target_yaw_rate)) {
59
sub.circle_pilot_yaw_override = true;
60
}
61
62
// get pilot desired climb rate
63
target_climb_rate = sub.get_pilot_desired_climb_rate(channel_throttle->get_control_in());
64
65
// set motors to full range
66
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
67
68
// run circle controller
69
sub.failsafe_terrain_set_status(sub.circle_nav.update_cms());
70
71
///////////////////////
72
// update xy outputs //
73
74
float lateral_out, forward_out;
75
sub.translate_circle_nav_rp(lateral_out, forward_out);
76
77
// Send to forward/lateral outputs
78
motors.set_lateral(lateral_out);
79
motors.set_forward(forward_out);
80
81
// call attitude controller
82
if (sub.circle_pilot_yaw_override) {
83
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw_cd(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_yaw_rate);
84
} else {
85
attitude_control->input_euler_angle_roll_pitch_yaw_cd(channel_roll->get_control_in(), channel_pitch->get_control_in(), sub.circle_nav.get_yaw_cd(), true);
86
}
87
88
// update altitude target and call position controller
89
position_control->D_set_pos_target_from_climb_rate_cms(target_climb_rate);
90
position_control->D_update_controller();
91
}
92
93