LCOV - code coverage report
Current view: top level - home/pbarker/rc/ardupilot/ArduSub - mode_circle.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 33 36 91.7 %
Date: 2026-09-09 11:02:08 Functions: 2 2 100.0 %

          Line data    Source code
       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           8 : bool ModeCircle::init(bool ignore_checks)
       9             : {
      10           8 :     if (!sub.position_ok()) {
      11           0 :         return false;
      12             :     }
      13             : 
      14           8 :     sub.circle_pilot_yaw_override = false;
      15             : 
      16             :     // initialize speeds and accelerations
      17             :     // All limits must be positive
      18           8 :     position_control->NE_set_max_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
      19           8 :     position_control->NE_set_correction_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
      20           8 :     position_control->D_set_max_speed_accel_cm(sub.get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
      21           8 :     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           8 :     sub.circle_nav.init();
      25             : 
      26           8 :     return true;
      27             : }
      28             : 
      29             : // circle_run - runs the circle flight mode
      30             : // should be called at 100hz or more
      31        2920 : void ModeCircle::run()
      32             : {
      33        2920 :     float target_yaw_rate = 0;
      34        2920 :     float target_climb_rate = 0;
      35             : 
      36             :     // update parameters, to allow changing at runtime
      37             :     // All limits must be positive
      38        2920 :     position_control->NE_set_max_speed_accel_cm(sub.wp_nav.get_default_speed_NE_cms(), sub.wp_nav.get_wp_acceleration_cmss());
      39        2920 :     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        2920 :     sub.circle_nav.check_param_change();
      43             : 
      44             :     // if not armed set throttle to zero and exit immediately
      45        2920 :     if (!motors.armed()) {
      46             :         // To-Do: add some initialisation of position controllers
      47        2240 :         motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
      48             :         // Sub vehicles do not stabilize roll/pitch/yaw when disarmed
      49        2240 :         attitude_control->set_throttle_out(NEUTRAL_THROTTLE,true,g.throttle_filt);
      50        2240 :         attitude_control->relax_attitude_controllers();
      51        2240 :         sub.circle_nav.init();
      52        2240 :         return;
      53             :     }
      54             : 
      55             :     // process pilot inputs
      56             :     // get pilot's desired yaw rate
      57         680 :     target_yaw_rate = sub.get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
      58         680 :     if (!is_zero(target_yaw_rate)) {
      59           0 :         sub.circle_pilot_yaw_override = true;
      60             :     }
      61             : 
      62             :     // get pilot desired climb rate
      63         680 :     target_climb_rate = sub.get_pilot_desired_climb_rate(channel_throttle->get_control_in());
      64             : 
      65             :     // set motors to full range
      66         680 :     motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
      67             : 
      68             :     // run circle controller
      69         680 :     sub.failsafe_terrain_set_status(sub.circle_nav.update_cms());
      70             : 
      71             :     ///////////////////////
      72             :     // update xy outputs //
      73             : 
      74             :     float lateral_out, forward_out;
      75         680 :     sub.translate_circle_nav_rp(lateral_out, forward_out);
      76             : 
      77             :     // Send to forward/lateral outputs
      78         680 :     motors.set_lateral(lateral_out);
      79         680 :     motors.set_forward(forward_out);
      80             : 
      81             :     // call attitude controller
      82         680 :     if (sub.circle_pilot_yaw_override) {
      83           0 :         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         680 :         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         680 :     position_control->D_set_pos_target_from_climb_rate_cms(target_climb_rate);
      90         680 :     position_control->D_update_controller();
      91             : }

Generated by: LCOV version 1.14