...fixed timing
Non -biDirectional DShot was too fast - fixed
This commit is contained in:
parent
bde3decb8e
commit
f0a95158ee
52
DShotRMT.cpp
52
DShotRMT.cpp
|
|
@ -71,10 +71,6 @@ void DShotRMT::setThrottle(uint16_t throttle)
|
||||||
// Safety first - double check input range and 11 bit "translation"
|
// Safety first - double check input range and 11 bit "translation"
|
||||||
throttle = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111;
|
throttle = constrain(throttle, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX) & 0b0000011111111111;
|
||||||
|
|
||||||
// Has Throttle really changed?
|
|
||||||
// if (throttle == _lastThrottle)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
_lastThrottle = throttle;
|
_lastThrottle = throttle;
|
||||||
|
|
||||||
// Convert throttle value to DShot Paket Format
|
// Convert throttle value to DShot Paket Format
|
||||||
|
|
@ -84,11 +80,11 @@ void DShotRMT::setThrottle(uint16_t throttle)
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
encodeDShotTX(_tx_packet, _tx_symbols, count);
|
encodeDShotTX(_tx_packet, _tx_symbols, count);
|
||||||
|
|
||||||
//
|
// Send the packet
|
||||||
rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config);
|
rmt_transmit(_rmt_tx_channel, _dshot_encoder, _tx_symbols, count * sizeof(rmt_symbol_word_t), &_transmit_config);
|
||||||
|
|
||||||
if (_isBidirectional)
|
// Take a break
|
||||||
esp_rom_delay_us(120);
|
esp_rom_delay_us(120);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Get eRPM from ESC ---
|
// --- Get eRPM from ESC ---
|
||||||
|
|
@ -107,46 +103,6 @@ uint32_t DShotRMT::getERPM()
|
||||||
//
|
//
|
||||||
_last_erpm = decodeDShotRX(_rx_symbols, DSHOT_BITS_PER_FRAME);
|
_last_erpm = decodeDShotRX(_rx_symbols, DSHOT_BITS_PER_FRAME);
|
||||||
return _last_erpm;
|
return _last_erpm;
|
||||||
|
|
||||||
// uint16_t received_bits = 0;
|
|
||||||
// _received_packet = 0;
|
|
||||||
|
|
||||||
// // Decode raw RMT encoded bits
|
|
||||||
// for (int i = 0; i < DSHOT_BITS_PER_FRAME && i < rx_size; ++i)
|
|
||||||
// {
|
|
||||||
// rmt_symbol_word_t symbols = _rx_symbols[i];
|
|
||||||
|
|
||||||
// // Validate signal polarity
|
|
||||||
// if (symbols.level0 != 1 || symbols.level1 != 0)
|
|
||||||
// break;
|
|
||||||
|
|
||||||
// uint32_t total_ticks = symbols.duration0 + symbols.duration1;
|
|
||||||
// bool bit = (symbols.duration0 > symbols.duration1);
|
|
||||||
|
|
||||||
// _received_packet <<= 1;
|
|
||||||
// _received_packet |= bit ? 1 : 0;
|
|
||||||
|
|
||||||
// received_bits++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Extract data & checksum from packet
|
|
||||||
// uint16_t packet_data = _received_packet >> 4;
|
|
||||||
// uint8_t recalc_packet_crc = (packet_data ^ (packet_data >> 4) ^ (packet_data >> 8)) & 0x0F;
|
|
||||||
// uint8_t packet_crc = _received_packet & 0x0F;
|
|
||||||
|
|
||||||
// if (recalc_packet_crc != packet_crc)
|
|
||||||
// return _last_erpm;
|
|
||||||
|
|
||||||
// // Assume received value is DShot eRPM
|
|
||||||
// uint16_t throttle = packet_data >> 1;
|
|
||||||
|
|
||||||
// // Filter noise values
|
|
||||||
// if (throttle < DSHOT_THROTTLE_MIN || throttle > DSHOT_THROTTLE_MAX)
|
|
||||||
// return _last_erpm;
|
|
||||||
|
|
||||||
// // Approximate eRPM (ESC dependent, scale factor can be tuned)
|
|
||||||
// _last_erpm = throttle * 100;
|
|
||||||
// return _last_erpm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
|
|
@ -300,4 +256,4 @@ uint16_t DShotRMT::decodeDShotRX(const rmt_symbol_word_t *symbols, uint32_t coun
|
||||||
uint16_t raw = _temp >> 1;
|
uint16_t raw = _temp >> 1;
|
||||||
|
|
||||||
return _last_erpm = raw;
|
return _last_erpm = raw;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public:
|
||||||
// Initializes the RMT TX and RX channels
|
// Initializes the RMT TX and RX channels
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
// Sets a new throttle value (48-2047) and sends it repeatedly
|
// Sets a new throttle value (48-2047) and sends it
|
||||||
void setThrottle(uint16_t throttle);
|
void setThrottle(uint16_t throttle);
|
||||||
|
|
||||||
// Receives and decodes the latest value from ESC, if available
|
// Receives and decodes the latest value from ESC, if available
|
||||||
|
|
@ -87,10 +87,10 @@ private:
|
||||||
bool _isBidirectional;
|
bool _isBidirectional;
|
||||||
|
|
||||||
// --- DShot Packets Container ---
|
// --- DShot Packets Container ---
|
||||||
uint16_t _lastThrottle = DSHOT_FULL_PACKET;
|
uint16_t _lastThrottle = DSHOT_NULL_PACKET;
|
||||||
uint16_t _received_packet = DSHOT_NULL_PACKET;
|
uint16_t _received_packet = DSHOT_NULL_PACKET;
|
||||||
uint16_t _tx_packet = DSHOT_NULL_PACKET;
|
uint16_t _tx_packet = DSHOT_NULL_PACKET;
|
||||||
uint16_t _packet_crc = 0;
|
uint8_t _packet_crc = 0;
|
||||||
|
|
||||||
// --- RMT Channel ---
|
// --- RMT Channel ---
|
||||||
rmt_channel_handle_t _rmt_rx_channel = nullptr;
|
rmt_channel_handle_t _rmt_rx_channel = nullptr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue