submodule + initial momentum init?

This commit is contained in:
franchioping 2026-03-16 14:25:49 +00:00
parent e7855d0140
commit b3b1a7f009
6 changed files with 67 additions and 46 deletions

1
.gitignore vendored
View File

@ -12,4 +12,5 @@ Cargo.lock
**/*.rs.bk **/*.rs.bk
*.pdb *.pdb
.idea/ .idea/
.cache/
cmake-build-debug/ cmake-build-debug/

4
.gitmodules vendored
View File

@ -1,3 +1,7 @@
[submodule "components/drone_controller"] [submodule "components/drone_controller"]
path = components/drone_controller path = components/drone_controller
url = ssh://git@forgejo.galard.uk:222/Cansat/drone_controller.git url = ssh://git@forgejo.galard.uk:222/Cansat/drone_controller.git
[submodule "components/esp32_BNO08x"]
path = components/esp32_BNO08x
url = ssh://git@forgejo.galard.uk:222/Cansat/esp32_BNO08x.git

@ -1 +1 @@
Subproject commit 8ae1b54c6100a96a670255e35960f9372c2b4dfb Subproject commit c3a3a356edf2375bf5a7a7d93e3ed7cbc4c934f3

@ -0,0 +1 @@
Subproject commit ae2dd0bef1be8107fc0a9cc8825c60295432ca2d

View File

@ -1,2 +1,9 @@
idf_component_register(SRCS "main.cpp" idf_component_register(SRCS "main.cpp"
INCLUDE_DIRS "") INCLUDE_DIRS "")
target_compile_options(${COMPONENT_LIB} PRIVATE
"-Wno-gnu-array-member-paren-init"
"-Wno-parentheses-equality"
"-Wno-template-in-declaration-name"
)

View File

@ -1,52 +1,60 @@
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "esp_err.h"
#include "esp_flash.h"
#include "esp_idf_version.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "sdkconfig.h"
#include <inttypes.h>
#include <stdio.h>
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
#include "esp_chip_info.h"
#endif
#include "BNO08x.hpp"
#include "BNO08xGlobalTypes.hpp"
#include "drone_controller.h" #include "drone_controller.h"
#include "esp_timer.h"
#include <cstdint>
#include <stdio.h>
static const constexpr char *TAG = "Main";
static struct Vec3C accel = {0, 0, 0};
static struct QuatC rot = {0, 0, 0, 0};
static struct Vec3C pos = {0, 0, 0};
static struct Vec3C vel = {0, 0, 0};
static int64_t last_time = -1;
extern "C" void app_main(void) { extern "C" void app_main(void) {
uint32_t flash_size; BNO08x *imu = new BNO08x();
printf("Hello world!\n"); if (!imu->initialize()) {
ESP_LOGE(TAG, "Init failure");
/* Print chip information */ return;
esp_chip_info_t chip_info; }
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU cores, WiFi%s%s, ", CONFIG_IDF_TARGET, // Use the pointer in your lambdas
chip_info.cores, (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "", imu->rpt.rv_game.enable(2500UL);
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); imu->rpt.linear_accelerometer.enable(10000UL);
imu->dynamic_calibration_autosave_enable();
printf("silicon revision %d, ", chip_info.revision);
imu->register_cb([imu]() {
ESP_ERROR_CHECK(esp_flash_get_size(NULL, &flash_size)); if (imu->rpt.linear_accelerometer.has_new_data()) {
printf("%" PRIu32 "MB %s flash\n", flash_size / (1024 * 1024), auto sens_accel = imu->rpt.linear_accelerometer.get();
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" accel = {sens_accel.x, sens_accel.y, sens_accel.z};
: "external");
int64_t time = esp_timer_get_time();
printf("Free heap: %" PRIu32 "\n", esp_get_free_heap_size()); if (last_time != -1) {
float dt = (time - last_time) / 1000000.0;
for (int i = 10; i >= 0; i--) {
printf("Restarting in %d seconds...\n", i); Vec3C init_vel = vel;
vTaskDelay(1000 / portTICK_PERIOD_MS); Vec3C delta = apply_rot(&accel, &rot);
multiply_vec_by(&delta, dt);
add_to_vec(&vel, &delta);
delta = init_vel;
multiply_vec_by(&delta, dt);
add_to_vec(&pos, &delta);
}
last_time = time;
}
if (imu->rpt.rv_game.has_new_data()) {
auto sens_rot = imu->rpt.rv_game.get_quat();
rot = {sens_rot.i, sens_rot.j, sens_rot.k, sens_rot.real};
}
});
while (1) {
vTaskDelay(pdMS_TO_TICKS(100));
} }
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
} }