fix throttle

This commit is contained in:
Wastl Kraus 2025-06-10 21:40:45 +02:00
parent cca82f5e57
commit 78bc06344c
2 changed files with 13 additions and 7 deletions

View File

@ -23,7 +23,7 @@ constexpr auto DSHOT_THROTTLE_MAX = 2047;
constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000; constexpr auto DSHOT_NULL_PACKET = 0b0000000000000000;
constexpr auto DSHOT_PAUSE = 21; // 21-bit is recommended constexpr auto DSHOT_PAUSE = 21; // 21-bit is recommended
constexpr auto DSHOT_PAUSE_BIT = 16; constexpr auto DSHOT_PAUSE_BIT = 16;
constexpr auto F_CPU_RMT = ( 80*1000000 ); //unit: Hz constexpr auto F_CPU_RMT = (80 * 1000 * 1000); // unit: Hz
constexpr auto RMT_CYCLES_PER_SEC = (F_CPU_RMT / DSHOT_CLK_DIVIDER); constexpr auto RMT_CYCLES_PER_SEC = (F_CPU_RMT / DSHOT_CLK_DIVIDER);
constexpr auto RMT_CYCLES_PER_ESP_CYCLE = (F_CPU / RMT_CYCLES_PER_SEC); constexpr auto RMT_CYCLES_PER_ESP_CYCLE = (F_CPU / RMT_CYCLES_PER_SEC);

View File

@ -15,7 +15,7 @@ const auto USB_SERIAL_BAUD = 115200;
#define USB_Serial Serial #define USB_Serial Serial
// Define the GPIO pin connected to the motor and the DShot protocol used // Define the GPIO pin connected to the motor and the DShot protocol used
const auto MOTOR01_PIN = GPIO_NUM_4; const auto MOTOR01_PIN = GPIO_NUM_17;
const auto DSHOT_MODE = DSHOT300; const auto DSHOT_MODE = DSHOT300;
// Define the failsafe and initial throttle values // Define the failsafe and initial throttle values
@ -31,6 +31,9 @@ void setup()
// Start generating DShot signal for the motor // Start generating DShot signal for the motor
motor01.begin(DSHOT_MODE); motor01.begin(DSHOT_MODE);
Serial.println("DShotRMT Demo started.");
Serial.println("Enter a throttle value (02047):");
} }
void loop() void loop()
@ -46,13 +49,16 @@ void loop()
// Read the throttle value from the USB serial input // Read the throttle value from the USB serial input
int read_SerialThrottle() int read_SerialThrottle()
{ {
static int last_throttle = INITIAL_THROTTLE;
if (USB_Serial.available() > 0) if (USB_Serial.available() > 0)
{ {
auto throttle_input = (USB_Serial.readStringUntil('\n')).toInt(); auto throttle_input = (USB_Serial.readStringUntil('\n')).toInt();
return throttle_input; last_throttle = throttle_input;
} Serial.print("Throttle set to: ");
else Serial.println(last_throttle);
{ Serial.println(" ");
return FAILSAFE_THROTTLE; Serial.println("Enter a throttle value (02047):");
} }
return last_throttle;
} }