LCOV - code coverage report
Current view: top level - AP_Winch - AP_Winch.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             : #pragma once
      17             : 
      18             : #include "AP_Winch_config.h"
      19             : 
      20             : #if AP_WINCH_ENABLED
      21             : 
      22             : #include <AP_Common/AP_Common.h>
      23             : #include <AP_Math/AP_Math.h>
      24             : #include <AP_Param/AP_Param.h>
      25             : #include <AC_PID/AC_PID.h>
      26             : #include <AP_Logger/AP_Logger_config.h>
      27             : 
      28             : class AP_Winch_Backend;
      29             : 
      30             : class AP_Winch {
      31             :     friend class AP_Winch_Backend;
      32             :     friend class AP_Winch_PWM;
      33             :     friend class AP_Winch_Daiwa;
      34             : 
      35             : public:
      36             :     AP_Winch();
      37             : 
      38             :     // Do not allow copies
      39             :     CLASS_NO_COPY(AP_Winch);
      40             : 
      41             :     // indicate whether this module is enabled
      42             :     bool enabled() const;
      43             : 
      44             :     // true if winch is healthy
      45             :     bool healthy() const;
      46             : 
      47             :     // initialise the winch
      48             :     void init();
      49             : 
      50             :     // update the winch
      51             :     void update();
      52             : 
      53             :     // relax the winch so it does not attempt to maintain length or rate
      54           6 :     void relax() { config.control_mode = ControlMode::RELAXED; }
      55             : 
      56             :     // release specified length of cable (in meters)
      57             :     void release_length(float length);
      58             : 
      59             :     // deploy line at specified speed in m/s (+ve deploys line, -ve retracts line, 0 stops)
      60             :     void set_desired_rate(float rate);
      61             : 
      62             :     // get rate maximum in m/s
      63           8 :     float get_rate_max() const { return MAX(config.rate_max, 0.0f); }
      64             : 
      65             :     // send status to ground station
      66             :     void send_status(const class GCS_MAVLINK &channel);
      67             : 
      68             : #if HAL_LOGGING_ENABLED
      69             :     // write log
      70             :     void write_log();
      71             : #endif
      72             : 
      73             :     // returns true if pre arm checks have passed
      74             :     bool pre_arm_check(char *failmsg, uint8_t failmsg_len) const;
      75             : 
      76             :     static AP_Winch *get_singleton();
      77             : 
      78             :     static const struct AP_Param::GroupInfo        var_info[];
      79             : 
      80             : private:
      81             : 
      82             :     enum class WinchType {
      83             :         NONE = 0,
      84             :         PWM = 1,
      85             :         DAIWA = 2
      86             :     };
      87             : 
      88             :     // enum for OPTIONS parameter
      89             :     enum class Options : int16_t {
      90             :         SpinFreelyOnStartup = (1U << 0),    // winch allows line to be manually pulled out soon after startup
      91             :         VerboseOutput = (1U << 1),          // verbose output of winch state sent to GCS
      92             :         RetryIfStuck = (1U << 2),           // retries to raise or lower if winch stops
      93             :     };
      94             : 
      95             :     // winch states
      96             :     enum class ControlMode : uint8_t {
      97             :         RELAXED = 0,    // winch is realxed
      98             :         POSITION,       // moving or maintaining a target length (from an external source)
      99             :         RATE,           // extending or retracting at a target rate (from an external source)
     100             :         RATE_FROM_RC    // extending or retracting at a target rate (from RC input)
     101             :     };
     102             : 
     103             :     struct Backend_Config {
     104             :         AP_Int8     type;               // winch type
     105             :         AP_Float    rate_max;           // deploy or retract rate maximum (in m/s).
     106             :         AP_Float    pos_p;              // position error P gain
     107             :         AP_Int16    options;            // options bitmask
     108             :         ControlMode control_mode;       // state of winch control (using target position or target rate)
     109             :         float       length_desired;     // target desired length (in meters)
     110             :         float       rate_desired;       // target deploy rate (in m/s, +ve = deploying, -ve = retracting)
     111             :     } config;
     112             : 
     113             :     AP_Winch_Backend *backend;
     114             : 
     115             :     static AP_Winch *_singleton;
     116             : };
     117             : 
     118             : namespace AP {
     119             :     AP_Winch *winch();
     120             : };
     121             : 
     122             : #endif  // AP_WINCH_ENABLED

Generated by: LCOV version 1.14