HAL_ChibiOS: support reversible DShot motors

This commit is contained in:
Andrew Tridgell 2018-11-09 21:25:58 +11:00
parent f2cd6e9a05
commit 8dd58b4181
2 changed files with 31 additions and 4 deletions

View File

@ -917,14 +917,31 @@ void RCOutput::dshot_send(pwm_group &group, bool blocking)
pwm = safe_pwm[chan+chan_offset];
}
pwm = constrain_int16(pwm, _esc_pwm_min, _esc_pwm_max);
uint16_t value = 2000UL * uint32_t(pwm - _esc_pwm_min) / uint32_t(_esc_pwm_max - _esc_pwm_min);
//uint32_t value = (chan+1) * 3;
const uint16_t chan_mask = (1U<<chan);
if (pwm == 0) {
// no output
continue;
}
pwm = constrain_int16(pwm, 1000, 2000);
uint16_t value = 2 * (pwm - 1000);
if (chan_mask & (reversible_mask>>chan_offset)) {
// this is a DShot-3D output, map so that 1500 PWM is zero throttle reversed
if (value < 1000) {
value = 2000 - value;
} else if (value > 1000) {
value = value - 1000;
} else {
// mid-throttle is off
value = 0;
}
}
if (value != 0) {
// dshot values are from 48 to 2047. Zero means off.
value += 47;
}
uint16_t chan_mask = (1U<<chan);
bool request_telemetry = (telem_request_mask & chan_mask)?true:false;
uint16_t packet = create_dshot_packet(value, request_telemetry);
if (request_telemetry) {

View File

@ -146,6 +146,15 @@ public:
*/
void set_safety_mask(uint16_t mask) { safety_mask = mask; }
/*
* mark the channels in chanmask as reversible. This is needed for some ESC types (such as DShot)
* so that output scaling can be performed correctly. The chanmask passed is added (ORed) into
* any existing mask.
*/
void set_reversible_mask(uint16_t chanmask) override {
reversible_mask |= chanmask;
}
private:
struct pwm_group {
// only advanced timers can do high clocks needed for more than 400Hz
@ -252,6 +261,7 @@ private:
// mask of channels that are running in high speed
uint16_t fast_channel_mask;
uint16_t io_fast_channel_mask;
uint16_t reversible_mask;
// min time to trigger next pulse to prevent overlap
uint64_t min_pulse_trigger_us;