CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/ArduSub/mode_circle.cpp
Views: 1798
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
position_control->set_max_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());
18
position_control->set_correction_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());
19
position_control->set_max_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
20
position_control->set_correction_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
21
22
// initialise circle controller including setting the circle center based on vehicle speed
23
sub.circle_nav.init();
24
25
return true;
26
}
27
28
// circle_run - runs the circle flight mode
29
// should be called at 100hz or more
30
void ModeCircle::run()
31
{
32
float target_yaw_rate = 0;
33
float target_climb_rate = 0;
34
35
// update parameters, to allow changing at runtime
36
position_control->set_max_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());
37
position_control->set_max_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
38
39
// if not armed set throttle to zero and exit immediately
40
if (!motors.armed()) {
41
// To-Do: add some initialisation of position controllers
42
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
43
// Sub vehicles do not stabilize roll/pitch/yaw when disarmed
44
attitude_control->set_throttle_out(0,true,g.throttle_filt);
45
attitude_control->relax_attitude_controllers();
46
sub.circle_nav.init();
47
return;
48
}
49
50
// process pilot inputs
51
// get pilot's desired yaw rate
52
target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
53
if (!is_zero(target_yaw_rate)) {
54
sub.circle_pilot_yaw_override = true;
55
}
56
57
// get pilot desired climb rate
58
target_climb_rate = sub.get_pilot_desired_climb_rate(channel_throttle->get_control_in());
59
60
// set motors to full range
61
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
62
63
// run circle controller
64
sub.failsafe_terrain_set_status(sub.circle_nav.update());
65
66
///////////////////////
67
// update xy outputs //
68
69
float lateral_out, forward_out;
70
sub.translate_circle_nav_rp(lateral_out, forward_out);
71
72
// Send to forward/lateral outputs
73
motors.set_lateral(lateral_out);
74
motors.set_forward(forward_out);
75
76
// call attitude controller
77
if (sub.circle_pilot_yaw_override) {
78
attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_yaw_rate);
79
} else {
80
attitude_control->input_euler_angle_roll_pitch_yaw(channel_roll->get_control_in(), channel_pitch->get_control_in(), sub.circle_nav.get_yaw(), true);
81
}
82
83
// update altitude target and call position controller
84
position_control->set_pos_target_z_from_climb_rate_cm(target_climb_rate);
85
position_control->update_z_controller();
86
}
87
88