From 5ef098f2893b453bf0d7eec1fcef35a7819f7e0f Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Thu, 11 Jul 2024 11:35:07 +0200 Subject: [PATCH 1/3] Add support for ControllerTypeOot in controllerInit function --- src/modules/src/controller/controller.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/src/controller/controller.c b/src/modules/src/controller/controller.c index 62aefed00..b2c968917 100644 --- a/src/modules/src/controller/controller.c +++ b/src/modules/src/controller/controller.c @@ -57,6 +57,8 @@ void controllerInit(ControllerType controller) { #define CONTROLLER ControllerTypeBrescianini #elif defined(CONFIG_CONTROLLER_LEE) #define CONTROLLER ControllerTypeLee + #elif defined(CONFIG_CONTROLLER_OOT) + #define CONTROLLER ControllerTypeOot #else #define CONTROLLER ControllerTypeAutoSelect #endif From 0179bed328807d0cf1a432a5c74ee5b4945449df Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Thu, 11 Jul 2024 11:54:06 +0200 Subject: [PATCH 2/3] Include out of tree controller example Co-authored-by: Kristoffer Richardsson --- .../app_out_of_tree_controller/.gitignore | 2 + examples/app_out_of_tree_controller/Kbuild | 1 + examples/app_out_of_tree_controller/Makefile | 23 ++++++ examples/app_out_of_tree_controller/README.md | 5 ++ .../app_out_of_tree_controller/app-config | 4 + .../app_out_of_tree_controller/src/Kbuild | 1 + .../src/out_of_tree_controller.c | 79 +++++++++++++++++++ 7 files changed, 115 insertions(+) create mode 100644 examples/app_out_of_tree_controller/.gitignore create mode 100644 examples/app_out_of_tree_controller/Kbuild create mode 100644 examples/app_out_of_tree_controller/Makefile create mode 100644 examples/app_out_of_tree_controller/README.md create mode 100644 examples/app_out_of_tree_controller/app-config create mode 100644 examples/app_out_of_tree_controller/src/Kbuild create mode 100644 examples/app_out_of_tree_controller/src/out_of_tree_controller.c diff --git a/examples/app_out_of_tree_controller/.gitignore b/examples/app_out_of_tree_controller/.gitignore new file mode 100644 index 000000000..a743f37a7 --- /dev/null +++ b/examples/app_out_of_tree_controller/.gitignore @@ -0,0 +1,2 @@ +bin/* +cf2.* diff --git a/examples/app_out_of_tree_controller/Kbuild b/examples/app_out_of_tree_controller/Kbuild new file mode 100644 index 000000000..9d804337a --- /dev/null +++ b/examples/app_out_of_tree_controller/Kbuild @@ -0,0 +1 @@ +obj-y += src/ diff --git a/examples/app_out_of_tree_controller/Makefile b/examples/app_out_of_tree_controller/Makefile new file mode 100644 index 000000000..d0a76e2ac --- /dev/null +++ b/examples/app_out_of_tree_controller/Makefile @@ -0,0 +1,23 @@ +# The firmware uses the Kbuild build system. There are 'Kbuild' files in this +# example that outlays what needs to be built. (check src/Kbuild). +# +# The firmware is configured using options in Kconfig files, the +# values of these end up in the .config file in the firmware directory. +# +# By setting the OOT_CONFIG (it is '$(PWD)/oot-config' by default) environment +# variable you can provide a custom configuration. It is important that you +# enable the app-layer. See app-config in this directory for example. + +# +# We want to execute the main Makefile for the firmware project, +# it will handle the build for us. +# +CRAZYFLIE_BASE := ../.. + +# +# We override the default OOT_CONFIG here, we could also name our config +# to oot-config and that would be the default. +# +OOT_CONFIG := $(PWD)/app-config + +include $(CRAZYFLIE_BASE)/tools/make/oot.mk diff --git a/examples/app_out_of_tree_controller/README.md b/examples/app_out_of_tree_controller/README.md new file mode 100644 index 000000000..7d851201f --- /dev/null +++ b/examples/app_out_of_tree_controller/README.md @@ -0,0 +1,5 @@ +# Out of tree controller app for Crazyflie 2.X + +This folder contains an out of tree controller implementation for the Crazyflie. Instead of using a custom controller, this example uses the built-in PID controller. + +Check out [the OOT build documentation](https://www.bitcraze.io/documentation/repository/crazyflie-firmware/master/development/oot/) and [this blog post](https://www.bitcraze.io/2023/02/adding-an-estimator-or-controller/) for more information. \ No newline at end of file diff --git a/examples/app_out_of_tree_controller/app-config b/examples/app_out_of_tree_controller/app-config new file mode 100644 index 000000000..28e393749 --- /dev/null +++ b/examples/app_out_of_tree_controller/app-config @@ -0,0 +1,4 @@ +CONFIG_APP_ENABLE=y +CONFIG_APP_PRIORITY=1 +CONFIG_APP_STACKSIZE=350 +CONFIG_CONTROLLER_OOT=y \ No newline at end of file diff --git a/examples/app_out_of_tree_controller/src/Kbuild b/examples/app_out_of_tree_controller/src/Kbuild new file mode 100644 index 000000000..cd14b3a2c --- /dev/null +++ b/examples/app_out_of_tree_controller/src/Kbuild @@ -0,0 +1 @@ +obj-y += out_of_tree_controller.o diff --git a/examples/app_out_of_tree_controller/src/out_of_tree_controller.c b/examples/app_out_of_tree_controller/src/out_of_tree_controller.c new file mode 100644 index 000000000..ae9f385dd --- /dev/null +++ b/examples/app_out_of_tree_controller/src/out_of_tree_controller.c @@ -0,0 +1,79 @@ +/** + * ,---------, ____ _ __ + * | ,-^-, | / __ )(_) /_______________ _____ ___ + * | ( O ) | / __ / / __/ ___/ ___/ __ `/_ / / _ \ + * | / ,--ยด | / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ + * +------` /_____/_/\__/\___/_/ \__,_/ /___/\___/ + * + * Crazyflie control firmware + * + * Copyright (C) 2024 Bitcraze AB + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, in version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * + * out_of_tree_controller.c - App layer application of an out of tree controller. + */ + +#include +#include +#include + +#include "app.h" + +#include "FreeRTOS.h" +#include "task.h" + +// Edit the debug name to get nice debug prints +#define DEBUG_MODULE "MYCONTROLLER" +#include "debug.h" + + +// We still need an appMain() function, but we will not really use it. Just let it quietly sleep. +void appMain() { + DEBUG_PRINT("Waiting for activation ...\n"); + + while(1) { + vTaskDelay(M2T(2000)); + + // Remove the DEBUG_PRINT. + // DEBUG_PRINT("Hello World!\n"); + } +} + +// The new controller goes here -------------------------------------------- +// Move the includes to the the top of the file if you want to +#include "controller.h" + +// Call the PID controller in this example to make it possible to fly. When you implement you own controller, there is +// no need to include the pid controller. +#include "controller_pid.h" + +void controllerOutOfTreeInit() { + // Initialize your controller data here... + + // Call the PID controller instead in this example to make it possible to fly + controllerPidInit(); +} + +bool controllerOutOfTreeTest() { + // Always return true + return true; +} + +void controllerOutOfTree(control_t *control, const setpoint_t *setpoint, const sensorData_t *sensors, const state_t *state, const uint32_t tick) { + // Implement your controller here... + + // Call the PID controller instead in this example to make it possible to fly + controllerPid(control, setpoint, sensors, state, tick); +} From ff6e42607de69a1d2b079aedc4254f123eec1725 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Thu, 11 Jul 2024 13:55:37 +0200 Subject: [PATCH 3/3] Clean up commented out OOT example code --- .../app_out_of_tree_controller/src/out_of_tree_controller.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/app_out_of_tree_controller/src/out_of_tree_controller.c b/examples/app_out_of_tree_controller/src/out_of_tree_controller.c index ae9f385dd..8d1759016 100644 --- a/examples/app_out_of_tree_controller/src/out_of_tree_controller.c +++ b/examples/app_out_of_tree_controller/src/out_of_tree_controller.c @@ -45,9 +45,6 @@ void appMain() { while(1) { vTaskDelay(M2T(2000)); - - // Remove the DEBUG_PRINT. - // DEBUG_PRINT("Hello World!\n"); } }