...biDir still not switching
This commit is contained in:
parent
ed9b8c539a
commit
089374d2bd
|
|
@ -91,6 +91,11 @@ uint32_t DShotRMT::getERPM()
|
|||
{
|
||||
if (_isBidirectional)
|
||||
{
|
||||
_receive_config.signal_range_min_ns = 1000;
|
||||
_receive_config.signal_range_max_ns = 15000;
|
||||
|
||||
rmt_enable(_rmt_rx_channel);
|
||||
|
||||
static size_t rx_size = sizeof(_rx_symbols);
|
||||
|
||||
if (_rmt_rx_channel == nullptr)
|
||||
|
|
@ -251,7 +256,7 @@ void DShotRMT::encodeDShotTX(uint16_t dshot_packet, rmt_symbol_word_t *symbols,
|
|||
|
||||
// Append the Pause Bits
|
||||
symbols[count].level0 = 0;
|
||||
symbols[count].duration0 = ticks_per_bit * PAUSE_BITS;
|
||||
symbols[count].duration0 = ticks_per_bit * (_isBidirectional ? SWITCH_PAUSE : PAUSE_BITS);
|
||||
symbols[count].level1 = 0;
|
||||
symbols[count].duration1 = 0;
|
||||
count++;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ static constexpr auto DSHOT_THROTTLE_MIN = 48;
|
|||
static constexpr auto DSHOT_THROTTLE_MAX = 2047;
|
||||
static constexpr auto DSHOT_BITS_PER_FRAME = 17;
|
||||
static constexpr auto PAUSE_BITS = 21;
|
||||
static constexpr auto SWITCH_PAUSE = 4;
|
||||
|
||||
static constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000;
|
||||
static constexpr auto DSHOT_FULL_PACKET = 0b1111111111111111;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <DShotRMT.h>
|
||||
|
||||
// USB serial port settings
|
||||
#define USB_Serial Serial0
|
||||
constexpr auto &USB_SERIAL = Serial0;
|
||||
constexpr auto USB_SERIAL_BAUD = 115200;
|
||||
|
||||
// Motor configuration
|
||||
|
|
@ -18,7 +18,7 @@ constexpr auto MOTOR01_PIN = GPIO_NUM_17;
|
|||
constexpr auto DSHOT_MODE = DSHOT300;
|
||||
|
||||
// BiDirectional DShot Support (default: false)
|
||||
constexpr auto IS_BIDIRECTIONAL = true;
|
||||
constexpr auto IS_BIDIRECTIONAL = false;
|
||||
|
||||
// Motor Magnet count for RPM calculation
|
||||
constexpr auto MOTOR01_MAGNET_COUNT = 14;
|
||||
|
|
@ -29,7 +29,7 @@ DShotRMT motor01(MOTOR01_PIN, DSHOT_MODE, IS_BIDIRECTIONAL);
|
|||
void setup()
|
||||
{
|
||||
// Start the USB Serial Port
|
||||
USB_Serial.begin(USB_SERIAL_BAUD);
|
||||
USB_SERIAL.begin(USB_SERIAL_BAUD);
|
||||
|
||||
// Initialize DShot Signal
|
||||
motor01.begin();
|
||||
|
|
@ -38,9 +38,9 @@ void setup()
|
|||
motor01.setThrottle(DSHOT_THROTTLE_MIN);
|
||||
|
||||
//
|
||||
USB_Serial.println("**********************");
|
||||
USB_Serial.println("DShotRMT Demo started.");
|
||||
USB_Serial.println("Enter a throttle value (48–2047):");
|
||||
USB_SERIAL.println("**********************");
|
||||
USB_SERIAL.println("DShotRMT Demo started.");
|
||||
USB_SERIAL.println("Enter a throttle value (48–2047):");
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
|
@ -63,10 +63,10 @@ void loop()
|
|||
|
||||
uint32_t rpm = motor01.getMotorRPM(MOTOR01_MAGNET_COUNT);
|
||||
|
||||
USB_Serial.print("Throttle: ");
|
||||
USB_Serial.print(throttle_input);
|
||||
USB_Serial.print(" | RPM: ");
|
||||
USB_Serial.println(rpm);
|
||||
USB_SERIAL.print("Throttle: ");
|
||||
USB_SERIAL.print(throttle_input);
|
||||
USB_SERIAL.print(" | RPM: ");
|
||||
USB_SERIAL.println(rpm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,19 +77,19 @@ int readSerialThrottle()
|
|||
//
|
||||
static int last_throttle = DSHOT_THROTTLE_MIN;
|
||||
|
||||
if (USB_Serial.available() > 0)
|
||||
if (USB_SERIAL.available() > 0)
|
||||
{
|
||||
String input = USB_Serial.readStringUntil('\n');
|
||||
String input = USB_SERIAL.readStringUntil('\n');
|
||||
int throttle_input = input.toInt();
|
||||
|
||||
// Clamp the value to the DShot range
|
||||
throttle_input = constrain(throttle_input, DSHOT_THROTTLE_MIN, DSHOT_THROTTLE_MAX);
|
||||
last_throttle = throttle_input;
|
||||
|
||||
USB_Serial.print("Throttle set to: ");
|
||||
USB_Serial.println(last_throttle);
|
||||
USB_Serial.println("***********************************");
|
||||
USB_Serial.println("Enter a throttle value (48–2047):");
|
||||
USB_SERIAL.print("Throttle set to: ");
|
||||
USB_SERIAL.println(last_throttle);
|
||||
USB_SERIAL.println("***********************************");
|
||||
USB_SERIAL.println("Enter a throttle value (48–2047):");
|
||||
}
|
||||
|
||||
return last_throttle;
|
||||
|
|
|
|||
Loading…
Reference in New Issue