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 : simple model of a servo. Model is: 17 : 18 : - time delay for transport protocol delay 19 : - slew limit 20 : - 2-pole butterworth 21 : */ 22 : 23 : #include <Filter/LowPassFilter2p.h> 24 : #include <Filter/LowPassFilter.h> 25 : #include <AP_HAL/utility/RingBuffer.h> 26 : #include <AP_Param/AP_Param.h> 27 : 28 : 29 : class ServoModel { 30 : public: 31 7023871 : float angle() const { return filter1p.get(); } 32 : float filter_angle(uint16_t pwm, float dt); 33 : float filter_range(uint16_t pwm, float dt); 34 : void set_pwm_range(uint16_t _pwm_min, uint16_t _pwm_max); 35 : void set_deflection(float _angle_deg); 36 : 37 : static const struct AP_Param::GroupInfo var_info[]; 38 : 39 : // return pwm required for current angle 40 : float angle_pwm() const; 41 : 42 : private: 43 : float apply_filter(float v, float dt); 44 : float apply_simple_filter(float v, float dt); 45 : 46 : LowPassFilter2pFloat filter; 47 : LowPassFilterFloat filter1p; 48 : ObjectBuffer<float> *delay; 49 : float last_v; 50 : float delta_max; 51 : uint16_t pwm_min = 1000; 52 : uint16_t pwm_max = 2000; 53 : float angle_deg = 45.0; 54 : }; 55 :