This commit is contained in:
franchioping 2026-04-12 16:52:29 +01:00
parent dcd6b2aeb9
commit 5f9bb289cd
7 changed files with 68 additions and 39 deletions

View File

@ -148,21 +148,23 @@ void drone_controller_task(void *params) {
} }
} }
const gpio_num_t motor_pins[4] = {GPIO_NUM_15, GPIO_NUM_NC, GPIO_NUM_NC, const gpio_num_t motor_pins[4] = {GPIO_NUM_14, GPIO_NUM_15, GPIO_NUM_16,
GPIO_NUM_NC}; GPIO_NUM_46};
void motor_throttles_task(void *params) { void motor_throttles_task(void *params) {
DShotRMT *motors[4]; DShotRMT *motors[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
motors[i] = new DShotRMT(motor_pins[i], DSHOT150, false); motors[i] = new DShotRMT(motor_pins[i], DSHOT150, false);
} }
motors[0]->sendCommand(3);
// ARM // ARM
unsigned long armTime = millis(); unsigned long armTime = millis();
while (millis() - armTime < 4000) { while (millis() - armTime < 5000) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
motors[i]->sendThrottlePercent(0); motors[i]->sendThrottlePercent(0);
} }
vTaskDelay(1);
} }
uint8_t wait_ms = 1000.0 / CONTROLLER_TASK_FREQUENCY; uint8_t wait_ms = 1000.0 / CONTROLLER_TASK_FREQUENCY;

View File

@ -24,5 +24,5 @@ void drone_controller_task(void *params);
void motor_throttles_task(void *params); void motor_throttles_task(void *params);
inline float motor_throttles[4] = {0.5, 0.5, 0.5, 0.5}; inline float motor_throttles[4] = {0.05, 0.05, 0.05, 0.05};
inline bool killswitch_active; inline bool killswitch_active = false;

View File

@ -18,12 +18,19 @@ Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
static const constexpr char *TAG = "BARO"; static const constexpr char *TAG = "BARO";
#define BARO_SDA GPIO_NUM_47
#define BARO_SCL GPIO_NUM_48
namespace env_sens { namespace env_sens {
void setup() { void setup() {
baro_mutex = xSemaphoreCreateMutex(); baro_mutex = xSemaphoreCreateMutex();
if (!bme.begin()) { TwoWire *wire = new TwoWire(0);
wire->begin(BARO_SDA, BARO_SCL);
if (!bme.begin(119, wire)) {
ESP_LOGE(TAG, "Couldn't find a valid sensor"); ESP_LOGE(TAG, "Couldn't find a valid sensor");
@ -43,14 +50,23 @@ void setup() {
float get_temperature() { float get_temperature() {
sensors_event_t temp_event; sensors_event_t temp_event;
if (baro_mutex && xSemaphoreTake(baro_mutex, 30)) {
bme_temp->getEvent(&temp_event); bme_temp->getEvent(&temp_event);
xSemaphoreGive(baro_mutex);
}
return temp_event.temperature; return temp_event.temperature;
} }
float get_pressure() { float get_pressure() {
sensors_event_t e; sensors_event_t e;
if (baro_mutex && xSemaphoreTake(baro_mutex, 30)) {
bme_pressure->getEvent(&e); bme_pressure->getEvent(&e);
xSemaphoreGive(baro_mutex);
}
return e.pressure; return e.pressure;
} }

View File

@ -21,7 +21,7 @@ const float TO_RAD = M_PI / 180.0f;
const float KNOTS_TO_M_SEC = 0.5144444f; const float KNOTS_TO_M_SEC = 0.5144444f;
const float earth_radius = 6371000.0f; const float earth_radius = 6371000.0f;
#define GPS_RX_PIN 16 #define GPS_RX_PIN 18
#define GPS_TX_PIN 17 #define GPS_TX_PIN 17
struct GPS { struct GPS {
@ -94,7 +94,7 @@ struct GPS {
char c = this->gps->read(); char c = this->gps->read();
if (this->gps->newNMEAreceived()) { if (this->gps->newNMEAreceived()) {
char *line = this->gps->lastNMEA(); char *line = this->gps->lastNMEA();
// ESP_LOGI("GPS", "NMEA LINE: %s", line); ESP_LOGI("GPS", "NMEA LINE: %s", line);
this->gps->parse(line); this->gps->parse(line);
} }
} }

View File

@ -20,13 +20,21 @@
static const char *TAG = "IMU"; static const char *TAG = "IMU";
#define IMU_CS GPIO_NUM_3
#define IMU_MOSI GPIO_NUM_2 // DI
#define IMU_RST GPIO_NUM_1
#define IMU_INT GPIO_NUM_4
#define IMU_MISO GPIO_NUM_5 // SDA
#define IMU_SCLK GPIO_NUM_6 // SCL
void setup_imu() { void setup_imu() {
imu_state *local_state = new imu_state; imu_state *local_state = new imu_state;
imu_state_mutex = xSemaphoreCreateMutex(); imu_state_mutex = xSemaphoreCreateMutex();
BNO08x *imu = new BNO08x(bno08x_config_t( BNO08x *imu =
SPI2_HOST, GPIO_NUM_26, GPIO_NUM_27, GPIO_NUM_25, // TODO: FIX new BNO08x(bno08x_config_t(SPI2_HOST, IMU_MOSI, IMU_MISO, IMU_SCLK,
GPIO_NUM_33, GPIO_NUM_36, GPIO_NUM_32, 2000000, false)); IMU_CS, IMU_INT, IMU_RST, 2000000, false));
if (!imu->initialize()) { if (!imu->initialize()) {
ESP_LOGE(TAG, "BNO08x Init failure."); ESP_LOGE(TAG, "BNO08x Init failure.");

View File

@ -30,15 +30,15 @@ extern "C" void app_main(void) {
gpio_install_isr_service(0); gpio_install_isr_service(0);
Serial.begin(115200); Serial.begin(115200);
xTaskCreatePinnedToCore(radio_task, // Function name // xTaskCreatePinnedToCore(radio_task, // Function name
"radio_rxtx", // Name for debugging // "radio_rxtx", // Name for debugging
4096, // Stack size in bytes // 4096, // Stack size in bytes
NULL, // Parameters // NULL, // Parameters
5, // Priority (higher = more urgent) // 5, // Priority (higher = more urgent)
NULL, // Task handle // NULL, // Task handle
0 // Core ID // 0 // Core ID
); // );
// // //
xTaskCreate(env_sens::baro_poll_task, "baro_poll", 8192, NULL, 1, NULL); xTaskCreate(env_sens::baro_poll_task, "baro_poll", 8192, NULL, 1, NULL);
// //
xTaskCreate(gps_poll_task, "gps_poll", 8192, NULL, 5, NULL); xTaskCreate(gps_poll_task, "gps_poll", 8192, NULL, 5, NULL);
@ -52,14 +52,14 @@ extern "C" void app_main(void) {
// 1 // Core ID // 1 // Core ID
// ); // );
// xTaskCreatePinnedToCore(motor_throttles_task, // Function name xTaskCreatePinnedToCore(motor_throttles_task, // Function name
// "motor_throttles_task", // Name for debugging "motor_throttles_task", // Name for debugging
// 1024 * 4, // Stack size in bytes 1024 * 4, // Stack size in bytes
// NULL, // Parameters NULL, // Parameters
// 30, // Priority (higher = more urgent) 30, // Priority (higher = more urgent)
// NULL, // Task handle NULL, // Task handle
// 1 // Core ID 1 // Core ID
// ); );
ESP_LOGI("MAIN", "All tasks spawned. Main loop free."); ESP_LOGI("MAIN", "All tasks spawned. Main loop free.");

View File

@ -2,6 +2,7 @@
#include "Esp.h" #include "Esp.h"
#include "esp32-hal-gpio.h" #include "esp32-hal-gpio.h"
#include "esp32-hal-spi.h"
#include "esp_log.h" #include "esp_log.h"
#include "freertos/idf_additions.h" #include "freertos/idf_additions.h"
#include "packet_handler.h" #include "packet_handler.h"
@ -12,12 +13,14 @@
#include <drone_comms.h> #include <drone_comms.h>
#define RFM69_RST 14 // Right to left on hardware.
#define RFM69_CS 12
#define RFM69_INT 39 #define RFM69_MOSI GPIO_NUM_11
#define SPI_SCLK 18 #define RFM69_SCLK GPIO_NUM_12
#define SPI_MISO 19 #define RFM69_MISO GPIO_NUM_13
#define SPI_MOSI 23 #define RFM69_CS GPIO_NUM_10
#define RFM69_INT GPIO_NUM_9
#define RFM69_RST GPIO_NUM_8
#define FREQUENCY RF69_433MHZ #define FREQUENCY RF69_433MHZ
#define NODEID 1 #define NODEID 1
@ -43,8 +46,8 @@ void radio_task(void *pvParameters) {
pinMode(RFM69_CS, OUTPUT); pinMode(RFM69_CS, OUTPUT);
pinMode(RFM69_INT, INPUT); pinMode(RFM69_INT, INPUT);
SPIClass vspi(VSPI); SPIClass hspi(HSPI);
vspi.begin(SPI_SCLK, SPI_MISO, SPI_MOSI, 34); hspi.begin(RFM69_SCLK, RFM69_MISO, RFM69_MOSI, RFM69_CS);
pinMode(RFM69_RST, OUTPUT); pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, HIGH); digitalWrite(RFM69_RST, HIGH);
@ -52,7 +55,7 @@ void radio_task(void *pvParameters) {
digitalWrite(RFM69_RST, LOW); digitalWrite(RFM69_RST, LOW);
vTaskDelay(pdMS_TO_TICKS(50)); vTaskDelay(pdMS_TO_TICKS(50));
RFM69 radio(RFM69_CS, RFM69_INT, true, &vspi); RFM69 radio(RFM69_CS, RFM69_INT, true, &hspi);
if (radio.initialize(FREQUENCY, NODEID, NETWORKID)) { if (radio.initialize(FREQUENCY, NODEID, NETWORKID)) {
radio.setHighPower(true); radio.setHighPower(true);