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/AP_Winch.h> 19 : 20 : #if AP_WINCH_ENABLED 21 : 22 : #include <AP_Logger/AP_Logger_config.h> 23 : 24 : class AP_Winch_Backend { 25 : public: 26 2 : AP_Winch_Backend(struct AP_Winch::Backend_Config &_config) : 27 2 : config(_config) { } 28 : 29 : // true if winch is healthy 30 : virtual bool healthy() const = 0; 31 : 32 : // initialise the backend 33 : virtual void init(); 34 : 35 : // update - should be called at at least 10hz 36 : virtual void update() = 0; 37 : 38 : // returns current length of line deployed 39 : virtual float get_current_length() const = 0; 40 : 41 : // send status to ground station 42 : virtual void send_status(const GCS_MAVLINK &channel) = 0; 43 : 44 : #if HAL_LOGGING_ENABLED 45 : // write log 46 : virtual void write_log() = 0; 47 : #endif 48 : 49 : // helper to check if option enabled 50 4 : bool option_enabled(AP_Winch::Options option) const { 51 4 : return (config.options & uint16_t(option)) != 0; 52 : } 53 : 54 : protected: 55 : 56 : // calculate the pilot desired rate (+ve deploys line, -ve retracts line, 0 stops) from rc input 57 : // may change the state to RATE and update config.rate_desired 58 : void read_pilot_desired_rate(); 59 : 60 : // returns the rate limited by the maximum acceleration 61 : // this also updates the previous rate so should not be called more than once per loop 62 : float get_rate_limited_by_accel(float rate, float dt) WARN_IF_UNUSED; 63 : 64 : // set the rate used for acceleration limiting 65 5120 : void set_previous_rate(float rate) { previous_rate = rate; } 66 : 67 : struct AP_Winch::Backend_Config &config; 68 : 69 : int16_t previous_radio_in = -1; // previous RC input from pilot, used to ignore small changes 70 : float previous_rate; // previous rate used for acceleration limiting 71 : }; 72 : 73 : #endif // AP_WINCH_ENABLED