Skip to content

Commit

Permalink
Merge pull request #1392 from bitcraze/rik/ootcontrollerfix
Browse files Browse the repository at this point in the history
Fix out of tree controllers
  • Loading branch information
gemenerik committed Jul 11, 2024
2 parents ec6a792 + ff6e426 commit 9ee5607
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/app_out_of_tree_controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/*
cf2.*
1 change: 1 addition & 0 deletions examples/app_out_of_tree_controller/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += src/
23 changes: 23 additions & 0 deletions examples/app_out_of_tree_controller/Makefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/app_out_of_tree_controller/README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions examples/app_out_of_tree_controller/app-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_APP_ENABLE=y
CONFIG_APP_PRIORITY=1
CONFIG_APP_STACKSIZE=350
CONFIG_CONTROLLER_OOT=y
1 change: 1 addition & 0 deletions examples/app_out_of_tree_controller/src/Kbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
obj-y += out_of_tree_controller.o
76 changes: 76 additions & 0 deletions examples/app_out_of_tree_controller/src/out_of_tree_controller.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* ,---------, ____ _ __
* | ,-^-, | / __ )(_) /_______________ _____ ___
* | ( 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 <http://www.gnu.org/licenses/>.
*
*
* out_of_tree_controller.c - App layer application of an out of tree controller.
*/

#include <string.h>
#include <stdint.h>
#include <stdbool.h>

#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));
}
}

// 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);
}
2 changes: 2 additions & 0 deletions src/modules/src/controller/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ee5607

Please sign in to comment.