LCOV - code coverage report
Current view: top level - AP_WheelEncoder - AP_WheelRateControl.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 1 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 1 0.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_Common/AP_Common.h>
      19             : #include <AP_Math/AP_Math.h>
      20             : #include <AP_Param/AP_Param.h>
      21             : #include <AC_PID/AC_PID.h>
      22             : #include <AP_WheelEncoder/AP_WheelEncoder.h>
      23             : 
      24             : // wheel rate control defaults
      25             : #define AP_WHEEL_RATE_MAX_DEFAULT   12.0f  // maximum wheel rotation rate in rad/sec (about 115rpm, 687deg/sec)
      26             : #define AP_WHEEL_RATE_CONTROL_FF    8.00f
      27             : #define AP_WHEEL_RATE_CONTROL_P     2.00f
      28             : #define AP_WHEEL_RATE_CONTROL_I     2.00f
      29             : #define AP_WHEEL_RATE_CONTROL_IMAX  1.00f
      30             : #define AP_WHEEL_RATE_CONTROL_D     0.01f
      31             : #define AP_WHEEL_RATE_CONTROL_FILT  0.00f
      32             : #define AP_WHEEL_RATE_CONTROL_TIMEOUT_MS 200
      33             : 
      34             : class AP_WheelRateControl {
      35             : 
      36             : public:
      37             : 
      38             :     AP_WheelRateControl(const AP_WheelEncoder &wheel_encoder_ref);
      39             : 
      40             :     // returns true if a wheel encoder and rate control PID are available for this instance
      41             :     bool enabled(uint8_t instance);
      42             : 
      43             :     // get throttle output in the range -100 to +100 given a desired rate expressed as a percentage of the rate_max (-100 to +100)
      44             :     // instance can be 0 or 1
      45             :     float get_rate_controlled_throttle(uint8_t instance, float desired_rate_pct, float dt);
      46             : 
      47             :     // get rate maximum in radians/sec
      48           0 :     float get_rate_max_rads() const { return MAX(_rate_max, 0.0f); }
      49             : 
      50             :     // get pid objects for reporting
      51             :     AC_PID& get_pid(uint8_t instance);
      52             : 
      53             :     // set the PID notch sample rates
      54             :     void set_notch_sample_rate(float sample_rate);
      55             : 
      56             :     static const struct AP_Param::GroupInfo        var_info[];
      57             : 
      58             : private:
      59             : 
      60             :     // parameters
      61             :     AP_Int8         _enabled;   // top level enable/disable control
      62             :     AP_Float        _rate_max;  // wheel maximum rotation rate in rad/s
      63             : 
      64             :     const AC_PID::Defaults rate_pid_defaults {
      65             :         .p         = AP_WHEEL_RATE_CONTROL_P,
      66             :         .i         = AP_WHEEL_RATE_CONTROL_I,
      67             :         .d         = AP_WHEEL_RATE_CONTROL_D,
      68             :         .ff        = AP_WHEEL_RATE_CONTROL_FF,
      69             :         .imax      = AP_WHEEL_RATE_CONTROL_IMAX,
      70             :         .filt_T_hz = AP_WHEEL_RATE_CONTROL_FILT,
      71             :         .filt_E_hz = AP_WHEEL_RATE_CONTROL_FILT,
      72             :         .filt_D_hz = AP_WHEEL_RATE_CONTROL_FILT,
      73             :         .srmax     = 0,
      74             :         .srtau     = 1.0
      75             :     };
      76             : 
      77             :     AC_PID          _rate_pid0{rate_pid_defaults};
      78             :     AC_PID          _rate_pid1{rate_pid_defaults};
      79             : 
      80             :     // limit flags
      81             :     struct AP_MotorsUGV_limit {
      82             :         bool    lower;  // reached this instance's lower limit on last iteration
      83             :         bool    upper;  // reached this instance's upper limit on last iteration
      84             :     } _limit[2];
      85             : 
      86             :     // internal variables
      87             :     const AP_WheelEncoder&  _wheel_encoder;     // pointer to accompanying wheel encoder
      88             :     uint32_t                _last_update_ms;    // system time of last call to get_rate_controlled_throttle
      89             : };

Generated by: LCOV version 1.14