2026-03-30 22:09:23 +01:00
|
|
|
#pragma once
|
2026-04-03 17:52:02 +01:00
|
|
|
|
2026-03-30 22:09:23 +01:00
|
|
|
#ifdef PS
|
|
|
|
|
#undef PS
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef F
|
|
|
|
|
#undef F
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
|
|
2026-04-06 03:39:08 +01:00
|
|
|
#include "freertos/idf_additions.h"
|
|
|
|
|
#include "gps.h"
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
2026-04-03 17:52:02 +01:00
|
|
|
#define WAYPOINT_COUNT 8
|
2026-03-30 22:09:23 +01:00
|
|
|
|
2026-04-03 17:52:02 +01:00
|
|
|
struct waypoint {
|
2026-04-06 00:27:32 +01:00
|
|
|
Eigen::Vector3f coords; // lat, lon, alt
|
|
|
|
|
std::optional<Eigen::Vector3f> coords_in_axis = std::nullopt;
|
|
|
|
|
bool active = false; // active or to be skipped
|
2026-04-03 17:52:02 +01:00
|
|
|
};
|
2026-03-30 22:09:23 +01:00
|
|
|
|
2026-04-03 17:52:02 +01:00
|
|
|
struct drone_nav {
|
|
|
|
|
waypoint waypoints[WAYPOINT_COUNT];
|
|
|
|
|
uint8_t current_waypoint;
|
2026-03-30 22:09:23 +01:00
|
|
|
|
2026-04-03 17:52:02 +01:00
|
|
|
void set_active_mask(uint8_t mask) {
|
|
|
|
|
for (int i = 0; i < WAYPOINT_COUNT; i++) {
|
|
|
|
|
this->waypoints[i].active = (mask & (1 << i)) != 0;
|
2026-03-30 22:09:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 17:52:02 +01:00
|
|
|
uint8_t get_active_mask() {
|
|
|
|
|
uint8_t mask = 0;
|
|
|
|
|
for (int i = 0; i < WAYPOINT_COUNT; i++) {
|
|
|
|
|
if (waypoints[i].active) {
|
|
|
|
|
mask |= (1 << i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return mask;
|
2026-03-30 22:09:23 +01:00
|
|
|
}
|
2026-04-06 00:27:32 +01:00
|
|
|
|
|
|
|
|
waypoint get_current_waypoint() {
|
|
|
|
|
waypoint wayp = this->waypoints[this->current_waypoint];
|
|
|
|
|
if (!wayp.coords_in_axis.has_value()) {
|
|
|
|
|
auto axis =
|
|
|
|
|
gps->waypoint_to_xyz(wayp.coords[0], wayp.coords[1], wayp.coords[2]);
|
|
|
|
|
wayp.coords_in_axis = axis;
|
|
|
|
|
}
|
|
|
|
|
return wayp;
|
|
|
|
|
}
|
2026-03-30 22:09:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline SemaphoreHandle_t nav_mutex = NULL;
|
2026-04-03 17:52:02 +01:00
|
|
|
inline drone_nav nav_man;
|