HAL_PX4: cope with brushed motors in read_last_sent()

we need the value before scaling is applied, so slew rates can work
This commit is contained in:
Andrew Tridgell 2017-05-16 13:55:35 +10:00
parent a42c09d27a
commit 17893958bf
2 changed files with 11 additions and 1 deletions

View File

@ -73,6 +73,7 @@ void PX4RCOutput::init()
// ensure not to write zeros to disabled channels
for (uint8_t i=0; i < PX4_NUM_OUTPUT_CHANNELS; i++) {
_period[i] = PWM_IGNORE_THIS_CHANNEL;
_last_sent[i] = PWM_IGNORE_THIS_CHANNEL;
}
}
@ -229,6 +230,7 @@ void PX4RCOutput::enable_ch(uint8_t ch)
_enabled_channels |= (1U<<ch);
if (_period[ch] == PWM_IGNORE_THIS_CHANNEL) {
_period[ch] = 0;
_last_sent[ch] = 0;
}
}
@ -329,7 +331,12 @@ void PX4RCOutput::write(uint8_t ch, uint16_t period_us)
_max_channel = ch + 1;
}
if (_output_mode == MODE_PWM_BRUSHED) {
// keep unscaled value
_last_sent[ch] = period_us;
// map from the PWM range to 0 t0 100% duty cycle. For 16kHz
// this ends up being 0 to 500 pulse width in units of
// 125usec.
@ -386,7 +393,7 @@ uint16_t PX4RCOutput::read_last_sent(uint8_t ch)
return 0;
}
return _period[ch];
return _last_sent[ch];
}
void PX4RCOutput::read_last_sent(uint16_t* period_us, uint8_t len)

View File

@ -45,6 +45,9 @@ private:
int _alt_fd;
uint16_t _freq_hz;
uint16_t _period[PX4_NUM_OUTPUT_CHANNELS];
// we keep the last_sent value separately, as we need to keep the unscaled
// value for systems with brushed motors which scale outputs
uint16_t _last_sent[PX4_NUM_OUTPUT_CHANNELS];
volatile uint8_t _max_channel;
volatile bool _need_update;
bool _sbus_enabled:1;