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

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : 
      16             : /*
      17             :     Rover Sailboat functionality
      18             : */
      19             : class Sailboat
      20             : {
      21             : public:
      22             : 
      23             :     // constructor
      24             :     Sailboat();
      25             : 
      26             :     // enabled
      27     1920776 :     bool sail_enabled() const { return enable > 0;}
      28             : 
      29             :     // true if sailboat navigation (aka tacking) is enabled
      30             :     bool tack_enabled() const;
      31             : 
      32             :     // setup
      33             :     void init();
      34             : 
      35             :     // initialise rc input (channel_mainsail)
      36             :     void init_rc_in();
      37             : 
      38             :     // calculate throttle and set sail
      39             :     void get_throttle_and_set_mainsail(float desired_speed, float &throttle_out);
      40             : 
      41             :     // Velocity Made Good, this is the speed we are traveling towards the desired destination
      42             :     float get_VMG() const;
      43             : 
      44             :     // handle user initiated tack while in acro mode
      45             :     void handle_tack_request_acro();
      46             : 
      47             :     // return target heading in radians when tacking (only used in acro)
      48             :     float get_tack_heading_rad();
      49             : 
      50             :     // handle user initiated tack while in autonomous modes (Auto, Guided, RTL, SmartRTL, etc)
      51             :     void handle_tack_request_auto();
      52             : 
      53             :     // clear tacking state variables
      54             :     void clear_tack();
      55             : 
      56             :     // returns true if boat is currently tacking
      57             :     bool tacking() const;
      58             : 
      59             :     // returns true if sailboat should take a indirect navigation route to go upwind
      60             :     bool use_indirect_route(float desired_heading_cd) const;
      61             : 
      62             :     // calculate the heading to sail on if we can't go upwind
      63             :     float calc_heading(float desired_heading_cd);
      64             : 
      65             :     // states of USE_MOTOR parameter and motor_state variable
      66             :     enum class UseMotor {
      67             :         USE_MOTOR_NEVER  = 0,
      68             :         USE_MOTOR_ASSIST = 1,
      69             :         USE_MOTOR_ALWAYS = 2
      70             :     };
      71             : 
      72             :     // set state of motor
      73             :     // if report_failure is true a message will be sent to all GCSs
      74             :     void set_motor_state(UseMotor state, bool report_failure = true);
      75             : 
      76             :     // var_info for holding Parameter information
      77             :     static const struct AP_Param::GroupInfo var_info[];
      78             : 
      79             :     // return sailboat loiter radius
      80         839 :     float get_loiter_radius() const {return loit_radius;}
      81             : 
      82             :     // set mainsail according to pilot input
      83             :     void set_pilot_desired_mainsail();
      84             : 
      85             :     // set mainsail in auto modes
      86             :     void set_auto_mainsail(float desired_speed);
      87             : 
      88             :     // as far as possible stop sails driving the boat
      89             :     // by feathering or sheeting right out
      90             :     void relax_sails();
      91             : 
      92             : private:
      93             : 
      94             :     // true if motor is on to assist with slow tack
      95             :     bool motor_assist_tack() const;
      96             : 
      97             :     // true if motor should be on to assist with low wind
      98             :     bool motor_assist_low_wind() const;
      99             : 
     100             :     // parameters
     101             :     AP_Int8 enable;
     102             :     AP_Float sail_angle_min;
     103             :     AP_Float sail_angle_max;
     104             :     AP_Float sail_angle_ideal;
     105             :     AP_Float sail_heel_angle_max;
     106             :     AP_Float sail_no_go;
     107             :     AP_Float sail_windspeed_min;
     108             :     AP_Float xtrack_max;
     109             :     AP_Float loit_radius;
     110             : 
     111             :     RC_Channel *channel_mainsail;   // rc input channel for controlling mainsail
     112             :     bool currently_tacking;         // true when sailboat is in the process of tacking to a new heading
     113             :     float tack_heading_rad;         // target heading in radians while tacking in either acro or autonomous modes
     114             :     uint32_t tack_request_ms;       // system time user requested tack
     115             :     uint32_t auto_tack_start_ms;    // system time when tack was started in autonomous mode
     116             :     uint32_t tack_clear_ms;         // system time when tack was cleared
     117             :     bool tack_assist;               // true if we should use some throttle to assist tack
     118             :     UseMotor motor_state;           // current state of motor output
     119             : };

Generated by: LCOV version 1.14