From 1e62b5d5c7facf83c465b655def92515f18f0b62 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Apr 2017 18:15:55 +1000 Subject: [PATCH] AP_Motors: many to one mapping of motors this allows multiple outputs for one motor number --- libraries/AP_Motors/AP_Motors_Class.cpp | 30 ++++++++++--------------- libraries/AP_Motors/AP_Motors_Class.h | 4 +--- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/libraries/AP_Motors/AP_Motors_Class.cpp b/libraries/AP_Motors/AP_Motors_Class.cpp index 8f37f5a9ca..d917b926a0 100644 --- a/libraries/AP_Motors/AP_Motors_Class.cpp +++ b/libraries/AP_Motors/AP_Motors_Class.cpp @@ -22,6 +22,7 @@ #include "AP_Motors_Class.h" #include #include +#include extern const AP_HAL::HAL& hal; @@ -39,7 +40,6 @@ AP_Motors::AP_Motors(uint16_t loop_rate, uint16_t speed_hz) : _batt_voltage(0.0f), _batt_current(0.0f), _air_density_ratio(1.0f), - _motor_map_mask(0), _motor_fast_mask(0) { // init other flags @@ -83,10 +83,6 @@ void AP_Motors::set_radio_passthrough(float roll_input, float pitch_input, float */ void AP_Motors::rc_write(uint8_t chan, uint16_t pwm) { - if (_motor_map_mask & (1U<write(chan, pwm); + SRV_Channel::Aux_servo_function_t function = (SRV_Channel::Aux_servo_function_t)((uint8_t)SRV_Channel::k_motor1 + chan); + SRV_Channels::set_output_pwm(function, pwm); } /* @@ -109,10 +106,10 @@ void AP_Motors::rc_write(uint8_t chan, uint16_t pwm) */ void AP_Motors::rc_set_freq(uint32_t mask, uint16_t freq_hz) { - mask = rc_map_mask(mask); if (freq_hz > 50) { _motor_fast_mask |= mask; } + mask = rc_map_mask(mask); hal.rcout->set_freq(mask, freq_hz); if ((_pwm_type == PWM_TYPE_ONESHOT || _pwm_type == PWM_TYPE_ONESHOT125) && @@ -126,7 +123,9 @@ void AP_Motors::rc_set_freq(uint32_t mask, uint16_t freq_hz) } /* - map an internal motor mask to real motor mask + map an internal motor mask to real motor mask, accounting for + SERVOn_FUNCTION mappings, and allowing for multiple outputs per + motor number */ uint32_t AP_Motors::rc_map_mask(uint32_t mask) const { @@ -134,12 +133,8 @@ uint32_t AP_Motors::rc_map_mask(uint32_t mask) const for (uint8_t i=0; i<32; i++) { uint32_t bit = 1UL<