Line data Source code
1 : #pragma once 2 : #if AP_SCRIPTING_ENABLED 3 : 4 : #include "AP_MotorsMatrix.h" 5 : 6 : class AP_MotorsMatrix_Scripting_Dynamic : public AP_MotorsMatrix { 7 : public: 8 : 9 : // Constructor 10 0 : AP_MotorsMatrix_Scripting_Dynamic(uint16_t speed_hz = AP_MOTORS_SPEED_DEFAULT) : 11 0 : AP_MotorsMatrix(speed_hz) 12 : { 13 0 : if (_singleton != nullptr) { 14 0 : AP_HAL::panic("AP_MotorsMatrix_Scripting_Dynamic must be singleton"); 15 : } 16 0 : _singleton = this; 17 0 : }; 18 : 19 : // get singleton instance 20 0 : static AP_MotorsMatrix_Scripting_Dynamic *get_singleton() { 21 0 : return _singleton; 22 : } 23 : 24 : struct factor_table { 25 : float roll[AP_MOTORS_MAX_NUM_MOTORS]; 26 : float pitch[AP_MOTORS_MAX_NUM_MOTORS]; 27 : float yaw[AP_MOTORS_MAX_NUM_MOTORS]; 28 : float throttle[AP_MOTORS_MAX_NUM_MOTORS]; 29 : }; 30 : 31 : // base class method must not be used 32 0 : void init(motor_frame_class frame_class, motor_frame_type frame_type) override {}; 33 : 34 : // Init to be called from scripting 35 : bool init(uint8_t expected_num_motors) override; 36 : 37 : // add a motor and give its testing order 38 : bool add_motor(uint8_t motor_num, uint8_t testing_order); 39 : 40 : // add a interpolation point table 41 : void load_factors(const factor_table &table); 42 : 43 : // output - sends commands to the motors 44 : void output_to_motors() override; 45 : 46 : protected: 47 : 48 : // Do not apply thrust compensation, this is used by Quadplane tiltrotors 49 : // assume the compensation is done in the mixer and should not be done by quadplane 50 0 : void thrust_compensation(void) override {}; 51 : 52 0 : const char* _get_frame_string() const override { return "Dynamic Matrix"; } 53 : 54 : private: 55 : 56 : // True when received a factors table, will only init having received a table 57 : bool had_table; 58 : 59 : // For loading of new factors, cannot load while in use 60 : HAL_Semaphore _sem; 61 : 62 : static AP_MotorsMatrix_Scripting_Dynamic *_singleton; 63 : }; 64 : 65 : #endif // AP_SCRIPTING_ENABLED