2026-03-23 11:01:23 +00:00
|
|
|
#include "HardwareSerial.h"
|
|
|
|
|
#include "dshot_utils.h"
|
|
|
|
|
|
|
|
|
|
#include "esp32-hal.h"
|
2026-03-18 21:43:28 +00:00
|
|
|
#include "esp_log.h"
|
2026-03-18 15:49:09 +00:00
|
|
|
#include <cmath>
|
2026-03-23 11:01:23 +00:00
|
|
|
#include <iostream>
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-23 11:01:23 +00:00
|
|
|
#include "DShotRMT.h"
|
2026-03-18 21:43:28 +00:00
|
|
|
#include "env_sens.h"
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-18 21:43:28 +00:00
|
|
|
static const constexpr char *TAG = "Main";
|
2026-03-25 18:26:56 +00:00
|
|
|
const gpio_num_t MOTOR_PIN = GPIO_NUM_22;
|
2026-03-23 11:01:23 +00:00
|
|
|
|
2026-03-25 18:26:56 +00:00
|
|
|
DShotRMT motor(MOTOR_PIN, DSHOT300, true);
|
2026-03-18 15:49:09 +00:00
|
|
|
|
2026-03-16 14:25:49 +00:00
|
|
|
extern "C" void app_main(void) {
|
2026-03-23 11:01:23 +00:00
|
|
|
initArduino();
|
2026-03-25 18:26:56 +00:00
|
|
|
printf("beg: %d", motor.begin().result_code);
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-23 11:01:23 +00:00
|
|
|
ESP_LOGI(TAG, "Arming ESC...");
|
|
|
|
|
// Send 0 throttle for 4 seconds to arm
|
|
|
|
|
unsigned long armTime = millis();
|
|
|
|
|
while (millis() - armTime < 4000) {
|
|
|
|
|
motor.sendThrottlePercent(0);
|
2026-03-25 18:26:56 +00:00
|
|
|
// delay(1);
|
2026-03-16 14:25:49 +00:00
|
|
|
}
|
2026-03-25 18:26:56 +00:00
|
|
|
delay(50);
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-23 11:01:23 +00:00
|
|
|
ESP_LOGI(TAG, "Motor Armed. Ramping up...");
|
|
|
|
|
// Send 10% throttle for 5 seconds
|
|
|
|
|
unsigned long runTime = millis();
|
|
|
|
|
while (millis() - runTime < 5000) {
|
|
|
|
|
auto res = motor.sendThrottlePercent(10);
|
2026-03-25 18:26:56 +00:00
|
|
|
printf("%d, %d\n", res.result_code, res.erpm);
|
|
|
|
|
//
|
|
|
|
|
// ESP_LOGI(TAG, "current: %d",
|
|
|
|
|
// motor.getTelemetry().telemetry_data.current);
|
|
|
|
|
// delay(1);
|
2026-03-16 00:49:02 +00:00
|
|
|
}
|
2026-03-23 11:01:23 +00:00
|
|
|
|
|
|
|
|
ESP_LOGI(TAG, "Stopping motor");
|
|
|
|
|
motor.sendThrottlePercent(0);
|
2026-03-16 00:49:02 +00:00
|
|
|
}
|