Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/ArduSub/mode_circle.cpp
Views: 1798
#include "Sub.h"12/*3* control_circle.pde - init and run calls for circle flight mode4*/56// circle_init - initialise circle controller flight mode7bool ModeCircle::init(bool ignore_checks)8{9if (!sub.position_ok()) {10return false;11}1213sub.circle_pilot_yaw_override = false;1415// initialize speeds and accelerations16position_control->set_max_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());17position_control->set_correction_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());18position_control->set_max_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);19position_control->set_correction_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);2021// initialise circle controller including setting the circle center based on vehicle speed22sub.circle_nav.init();2324return true;25}2627// circle_run - runs the circle flight mode28// should be called at 100hz or more29void ModeCircle::run()30{31float target_yaw_rate = 0;32float target_climb_rate = 0;3334// update parameters, to allow changing at runtime35position_control->set_max_speed_accel_xy(sub.wp_nav.get_default_speed_xy(), sub.wp_nav.get_wp_acceleration());36position_control->set_max_speed_accel_z(-sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);3738// if not armed set throttle to zero and exit immediately39if (!motors.armed()) {40// To-Do: add some initialisation of position controllers41motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);42// Sub vehicles do not stabilize roll/pitch/yaw when disarmed43attitude_control->set_throttle_out(0,true,g.throttle_filt);44attitude_control->relax_attitude_controllers();45sub.circle_nav.init();46return;47}4849// process pilot inputs50// get pilot's desired yaw rate51target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());52if (!is_zero(target_yaw_rate)) {53sub.circle_pilot_yaw_override = true;54}5556// get pilot desired climb rate57target_climb_rate = sub.get_pilot_desired_climb_rate(channel_throttle->get_control_in());5859// set motors to full range60motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);6162// run circle controller63sub.failsafe_terrain_set_status(sub.circle_nav.update());6465///////////////////////66// update xy outputs //6768float lateral_out, forward_out;69sub.translate_circle_nav_rp(lateral_out, forward_out);7071// Send to forward/lateral outputs72motors.set_lateral(lateral_out);73motors.set_forward(forward_out);7475// call attitude controller76if (sub.circle_pilot_yaw_override) {77attitude_control->input_euler_angle_roll_pitch_euler_rate_yaw(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_yaw_rate);78} else {79attitude_control->input_euler_angle_roll_pitch_yaw(channel_roll->get_control_in(), channel_pitch->get_control_in(), sub.circle_nav.get_yaw(), true);80}8182// update altitude target and call position controller83position_control->set_pos_target_z_from_climb_rate_cm(target_climb_rate);84position_control->update_z_controller();85}868788