add DShotRMT library. add gps file. working example using mot1

This commit is contained in:
franchioping 2026-03-23 11:01:23 +00:00
parent 88679cd618
commit 36ea82a13c
6 changed files with 61 additions and 29 deletions

3
.gitmodules vendored
View File

@ -17,3 +17,6 @@
[submodule "components/esp32_Adafruit_Sensor"]
path = components/esp32_Adafruit_Sensor
url = ssh://git@forgejo.galard.uk:222/Cansat/esp32_Adafruit_Sensor.git
[submodule "components/DShotRMT"]
path = components/DShotRMT
url = https://github.com/derdoktor667/DShotRMT

1
components/DShotRMT Submodule

@ -0,0 +1 @@
Subproject commit 6e80e6ad3c3f6abd40e5c99e75436fb920869f84

View File

@ -1,5 +1,5 @@
idf_component_register(SRCS "main.cpp" "imu.cpp" "env_sens.cpp"
INCLUDE_DIRS "" REQUIRES drone_controller esp32_Adafruit_BME280_Library esp32_Adafruit_GPS esp32_BNO08x eigen)
idf_component_register(SRCS "main.cpp" "imu.cpp" "env_sens.cpp"
INCLUDE_DIRS "" REQUIRES drone_controller esp32_Adafruit_BME280_Library esp32_Adafruit_GPS esp32_BNO08x eigen DShotRMT)
target_compile_options(${COMPONENT_LIB} PRIVATE
"-Wno-gnu-array-member-paren-init"

24
main/gps.h Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include "Wire.h"
#include <Adafruit_GPS.h>
struct GPS {
Adafruit_GPS gps;
GPS(TwoWire *theWire) {
gps = Adafruit_GPS(theWire);
gps.begin(0x10);
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
gps.sendCommand(PMTK_API_SET_FIX_CTL_5HZ);
gps.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
}
void poll() {
this->gps.read();
if (this->gps.newNMEAreceived()) {
if (!this->gps.parse(this->gps.lastNMEA()))
return;
}
}
};

View File

@ -1,10 +1,12 @@
#pragma once
#include <cmath>
#include <cstdint>
#include "BNO08x.hpp"
#include "BNO08xGlobalTypes.hpp"
#include "drone_controller.h"
#include <cmath>
#include <cstdint>
#include "freertos/idf_additions.h"
struct imu_state {
Vec3C accel = {0, 0, 0};

View File

@ -1,36 +1,38 @@
#include "esp_log.h"
#include "esp_timer.h"
#include <cmath>
#include <cstdint>
#include <stdio.h>
#include "HardwareSerial.h"
#include "dshot_utils.h"
#include "esp32-hal.h"
#include "esp_log.h"
#include <cmath>
#include <iostream>
#include "DShotRMT.h"
#include "env_sens.h"
#include "freertos/idf_additions.h"
#include "imu.h"
static const constexpr char *TAG = "Main";
const gpio_num_t MOTOR_PIN = GPIO_NUM_16;
DShotRMT motor(MOTOR_PIN, DSHOT300, false);
extern "C" void app_main(void) {
env_sens::setup();
initArduino();
motor.begin();
imu_state imu_state;
BNO08x *imu = setup_imu(&imu_state);
if (imu == nullptr) {
ESP_LOGE(TAG, "IMU setup failed.");
return;
ESP_LOGI(TAG, "Arming ESC...");
// Send 0 throttle for 4 seconds to arm
unsigned long armTime = millis();
while (millis() - armTime < 4000) {
motor.sendThrottlePercent(0);
}
ESP_LOGE(TAG, "IMU setup sucess.");
while (1) {
vTaskDelay(pdMS_TO_TICKS(300));
if (xSemaphoreTake(imuStateMutex, pdMS_TO_TICKS(5)) == pdTRUE) {
ESP_LOGI(TAG, "accel - %f, %f, %f", imu_state.accel.x, imu_state.accel.y,
imu_state.accel.z);
ESP_LOGI(TAG, "; euler - %f, %f, %f\n", imu_state.euler_ang.x,
imu_state.euler_ang.y, imu_state.euler_ang.z);
xSemaphoreGive(imuStateMutex);
}
env_sens::dbg_sens();
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);
// printf("%d, %d\n", res.result_code, res.erpm);
}
ESP_LOGI(TAG, "Stopping motor");
motor.sendThrottlePercent(0);
}