From ca9da09175e4b3a5a83f327b2fd7f2338cc65542 Mon Sep 17 00:00:00 2001 From: Kristoffer Richardsson Date: Wed, 8 Jun 2022 10:49:55 +0200 Subject: [PATCH 1/3] Corrected def configs and docs --- configs/bolt_defconfig | 4 ++-- configs/cfbl_defconfig | 4 ++-- configs/tag_defconfig | 6 +++--- docs/development/create_platform.md | 8 ++++---- docs/development/howto.md | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/configs/bolt_defconfig b/configs/bolt_defconfig index 330ba20351..ad5ccc1082 100644 --- a/configs/bolt_defconfig +++ b/configs/bolt_defconfig @@ -1,5 +1,5 @@ CONFIG_PLATFORM_BOLT=y -CONFIG_ESTIMATOR=any -CONFIG_CONTROLLER=Any +CONFIG_ESTIMATOR_ANY=y +CONFIG_CONTROLLER_ANY=y CONFIG_POWER_DISTRIBUTION=stock diff --git a/configs/cfbl_defconfig b/configs/cfbl_defconfig index 6e84aa38cd..ad4665858c 100644 --- a/configs/cfbl_defconfig +++ b/configs/cfbl_defconfig @@ -1,5 +1,5 @@ CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y -CONFIG_ESTIMATOR=any -CONFIG_CONTROLLER=Any +CONFIG_ESTIMATOR_ANY=y +CONFIG_CONTROLLER_ANY=y CONFIG_POWER_DISTRIBUTION=stock diff --git a/configs/tag_defconfig b/configs/tag_defconfig index 8d0ab8466c..30bac79888 100644 --- a/configs/tag_defconfig +++ b/configs/tag_defconfig @@ -1,8 +1,8 @@ CONFIG_PLATFORM_TAG=y -CONFIG_ESTIMATOR=any -CONFIG_CONTROLLER=Any +CONFIG_ESTIMATOR_ANY=y +CONFIG_CONTROLLER_ANY=y CONFIG_POWER_DISTRIBUTION=stock -CONFIG_DECK_FORCE=bcDWM1000 +CONFIG_DECK_FORCE="bcDWM1000" CONFIG_SENSORS_IGNORE_BAROMETER_FAIL=y diff --git a/docs/development/create_platform.md b/docs/development/create_platform.md index 4a00d72067..ceda09c131 100644 --- a/docs/development/create_platform.md +++ b/docs/development/create_platform.md @@ -195,8 +195,8 @@ To make it easier for people to build for `RINCEWIND` we can add a `defconfig` f ```Makefile CONFIG_PLATFORM_BOLT=y -CONFIG_ESTIMATOR=any -CONFIG_CONTROLLER=Any +CONFIG_ESTIMATOR_ANY=y +CONFIG_CONTROLLER_ANY=y CONFIG_POWER_DISTRIBUTION=stock ``` @@ -205,8 +205,8 @@ Based on this a start of `rincewind_defconfig` could be: ```Makefile CONFIG_PLATFORM_RINCEWIND=y -CONFIG_ESTIMATOR=any -CONFIG_CONTROLLER=Any +CONFIG_ESTIMATOR_ANY=y +CONFIG_CONTROLLER_ANY=y CONFIG_POWER_DISTRIBUTION=stock ``` diff --git a/docs/development/howto.md b/docs/development/howto.md index 442ad9f61e..46f75e2139 100644 --- a/docs/development/howto.md +++ b/docs/development/howto.md @@ -71,7 +71,7 @@ Decks can have a memory that contains its name. In our case the hello driver would be initialized only when a deck identified as \"myHello\" is installed on the Crazyflie. For development purpose it is possible to force enabling a deck driver with a compile flag. To do so set the -`CONFIG_DECK_FORCE` config option to `myHello` in your `.config` either +`CONFIG_DECK_FORCE` config option to `"myHello"` in your `.config` either by hand or using `make menuconfig`. `CONFIG_DEBUG=y` allows to get more information from the Crazyflie console when From 91d50da67e2b3b17a36fd799fb34f77b3b9ebd07 Mon Sep 17 00:00:00 2001 From: Kristoffer Richardsson Date: Wed, 8 Jun 2022 13:04:55 +0200 Subject: [PATCH 2/3] Updated power distribution config --- bindings/setup.py | 2 +- configs/bolt_defconfig | 1 - configs/cfbl_defconfig | 1 - configs/tag_defconfig | 1 - docs/development/create_platform.md | 57 ++++++++++++++++++- docs/development/oot.md | 2 +- .../sensor-to-control/controllers.md | 3 +- .../sensor-to-control/index.md | 7 +-- docs/userguides/deck.md | 2 +- src/modules/src/Kbuild | 2 +- src/modules/src/Kconfig | 14 ++++- ...stock.c => power_distribution_quadrotor.c} | 4 +- 12 files changed, 76 insertions(+), 20 deletions(-) rename src/modules/src/{power_distribution_stock.c => power_distribution_quadrotor.c} (96%) diff --git a/bindings/setup.py b/bindings/setup.py index d27fcae6b6..0e75ddefec 100644 --- a/bindings/setup.py +++ b/bindings/setup.py @@ -26,7 +26,7 @@ "src/utils/src/filter.c", "src/utils/src/num.c", "src/modules/src/controller_mellinger.c", - "src/modules/src/power_distribution_stock.c", + "src/modules/src/power_distribution_quadrotor.c", ] cffirmware = Extension( diff --git a/configs/bolt_defconfig b/configs/bolt_defconfig index ad5ccc1082..df91eda340 100644 --- a/configs/bolt_defconfig +++ b/configs/bolt_defconfig @@ -2,4 +2,3 @@ CONFIG_PLATFORM_BOLT=y CONFIG_ESTIMATOR_ANY=y CONFIG_CONTROLLER_ANY=y -CONFIG_POWER_DISTRIBUTION=stock diff --git a/configs/cfbl_defconfig b/configs/cfbl_defconfig index ad4665858c..fed15b5d3b 100644 --- a/configs/cfbl_defconfig +++ b/configs/cfbl_defconfig @@ -2,4 +2,3 @@ CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y CONFIG_ESTIMATOR_ANY=y CONFIG_CONTROLLER_ANY=y -CONFIG_POWER_DISTRIBUTION=stock diff --git a/configs/tag_defconfig b/configs/tag_defconfig index 30bac79888..885c90eaea 100644 --- a/configs/tag_defconfig +++ b/configs/tag_defconfig @@ -2,7 +2,6 @@ CONFIG_PLATFORM_TAG=y CONFIG_ESTIMATOR_ANY=y CONFIG_CONTROLLER_ANY=y -CONFIG_POWER_DISTRIBUTION=stock CONFIG_DECK_FORCE="bcDWM1000" CONFIG_SENSORS_IGNORE_BAROMETER_FAIL=y diff --git a/docs/development/create_platform.md b/docs/development/create_platform.md index ceda09c131..7c8a00d5f0 100644 --- a/docs/development/create_platform.md +++ b/docs/development/create_platform.md @@ -197,7 +197,6 @@ CONFIG_PLATFORM_BOLT=y CONFIG_ESTIMATOR_ANY=y CONFIG_CONTROLLER_ANY=y -CONFIG_POWER_DISTRIBUTION=stock ``` Based on this a start of `rincewind_defconfig` could be: @@ -207,7 +206,6 @@ CONFIG_PLATFORM_RINCEWIND=y CONFIG_ESTIMATOR_ANY=y CONFIG_CONTROLLER_ANY=y -CONFIG_POWER_DISTRIBUTION=stock ``` Then `RINCEWIND` platform could be built by: @@ -224,4 +222,59 @@ $ make -j 12 [...] ``` +## Need a different power distribution? + +Suppose our new platform is a car with 4 wheels, then we will need a new power distribution function, that is +the translation from roll, pitch and yaw to motor power. The default implementation can be found in +`src/modules/src/power_distribution_quadrotor.c` but now we need to write a new function that works for cars. + +The first step is to add a car power distrbution setting to the configuration. +In the standard configuration, the quadrotor power distribution is the only option and it is used by all platforms. +Edit `src/modules/src/Kconfig` and +find the location where the power distribution is configured + +```Makefile +choice + prompt "Type of power distribution" + default POWER_DISTRIBUTION_QUADROTOR + +config POWER_DISTRIBUTION_QUADROTOR + bool "Quadrotor power distribution" + depends on PLATFORM_CF2 || PLATFORM_BOLT || PLATFORM_TAG + help + Power distribution function for quadrotors + +endchoice +``` +Now add a new car distribution setting and make it available for your platform. + +```Makefile +choice + prompt "Type of power distribution" + default POWER_DISTRIBUTION_QUADROTOR + +config POWER_DISTRIBUTION_QUADROTOR + bool "Quadrotor power distribution" + depends on PLATFORM_CF2 || PLATFORM_BOLT || PLATFORM_TAG + help + Power distribution function for quadrotors + +config POWER_DISTRIBUTION_CAR + bool "Car power distribution" + depends on PLATFORM_RINCEWIND + help + Power distribution function for cars + +endchoice +``` + +The next step is to add an implementation of the power distribution function. Copy +`power_distribution_quadrotor.c` into a new file, `power_distribution_car.c` and modify the +`powerDistribution()` function to fit your needs. + +The final step is to add the c file to the build. Open `src/modules/src/Kbuild` and add your new file. +```Makefile +obj-$(CONFIG_POWER_DISTRIBUTION_CAR) += power_distribution_car.o +``` + And you are done! You have created your own platform, good job! diff --git a/docs/development/oot.md b/docs/development/oot.md index 5487c49d4e..ef25bfd6b6 100644 --- a/docs/development/oot.md +++ b/docs/development/oot.md @@ -38,7 +38,7 @@ The `Kbuild` file in the `$(OOT)` folder should point out your source files: obj-y += your_estimator_out_of_tree.o ``` -It can also add point out another folder where the code resides: +It can also point out another folder where the code resides: ```Makefile obj-y += src/ diff --git a/docs/functional-areas/sensor-to-control/controllers.md b/docs/functional-areas/sensor-to-control/controllers.md index 14a8c8cc4f..1608f4a203 100644 --- a/docs/functional-areas/sensor-to-control/controllers.md +++ b/docs/functional-areas/sensor-to-control/controllers.md @@ -40,7 +40,7 @@ Here are the different loops of the cascaded PID explained in more detail. ### Attitude Rate PID controller -The attitude rate PID controller is the one that directly controls the attitude rate. It receives almost directly the gyroscope rates (through a bit of filtering first) takes the error between the desired attitude rate as input. This output the commands that is send directly to the power distribution `power_distribution_stock.c`. The control loop runs at 500 Hz. +The attitude rate PID controller is the one that directly controls the attitude rate. It receives almost directly the gyroscope rates (through a bit of filtering first) takes the error between the desired attitude rate as input. This output the commands that is send directly to the power distribution `power_distribution_quadrotor.c`. The control loop runs at 500 Hz. Check the implementation details in `attitude_pid_controller.c` in `attitudeControllerCorrectRatePID()`. @@ -55,4 +55,3 @@ Check the implementation details in `attitude_pid_controller.c` in `attitudeCont The most outer-loop of the cascaded PID controller is the position and velocity controller. It receives position or velocity input from a commander which are handled, since it is possible to set in the variable `setpoint_t` which stabilization mode to use `stab_mode_t` (either position: `modeAbs` or `modeVelocity`). These can be found in `stabilizer_types.h`. The control loop runs at 100 Hz. Check the implementation details in `position_controller_pid.c` in `positionController()` and `velocityController()`. - diff --git a/docs/functional-areas/sensor-to-control/index.md b/docs/functional-areas/sensor-to-control/index.md index f76c62589a..16ed252216 100644 --- a/docs/functional-areas/sensor-to-control/index.md +++ b/docs/functional-areas/sensor-to-control/index.md @@ -81,7 +81,7 @@ Go to the [Commander page](commanders_setpoints.md), for more in-depth informati After the state controller has send out its commands, this is not the end of the line yet. The controllers send out their commands relating to their yaw, roll and pitch angles. How the motors should respond in order to adhere these attitude based commands depends on a few factors: - * Quadrotor configuration (found in: `power_distribution_stock.c`: + * Quadrotor configuration (found in: `power_distribution_quadrotor.c`: * x-configuration: The body fixed coordinate system's x-axis is pointed in between two propellors (Default) * +-configuration: The body fixed coordinate system's x-axis is pointed in one propellor * Motors: @@ -89,9 +89,6 @@ How the motors should respond in order to adhere these attitude based commands d * Brushless: The Bolt enables the control of brushless motors. Checkout the[ product page of the Bolt](https://www.bitcraze.io/products/crazyflie-bolt/) for more information. - + ## Configuring Controllers and Estimators Go to this [configuration page](configure_estimator_controller.md), if you would like to configure different controllers and estimators, - - - diff --git a/docs/userguides/deck.md b/docs/userguides/deck.md index bd9de1dc7e..94c4dcaeaa 100644 --- a/docs/userguides/deck.md +++ b/docs/userguides/deck.md @@ -73,7 +73,7 @@ obj-y += myled.o The deck driver will be initialized only if a deck is connected with the right OW memory content. During development it is possible to force the initialization of a deck by setting the `CONFIG_DECK_FORCE` config option -to `meMyled` in your `.config` either by hand or using `make menuconfig`. +to `"meMyled"` in your `.config` either by hand or using `make menuconfig`. ### Driver declaration API diff --git a/src/modules/src/Kbuild b/src/modules/src/Kbuild index aad4eba090..33ebcbcb54 100644 --- a/src/modules/src/Kbuild +++ b/src/modules/src/Kbuild @@ -39,7 +39,7 @@ obj-y += platformservice.o obj-y += position_controller_indi.o obj-y += position_controller_pid.o obj-y += position_estimator_altitude.o -obj-y += power_distribution_stock.o +obj-$(CONFIG_POWER_DISTRIBUTION_QUADROTOR) += power_distribution_quadrotor.o obj-y += pptraj_compressed.o obj-y += pptraj.o obj-y += queuemonitor.o diff --git a/src/modules/src/Kconfig b/src/modules/src/Kconfig index c8d484fffb..92d53335cf 100644 --- a/src/modules/src/Kconfig +++ b/src/modules/src/Kconfig @@ -124,9 +124,20 @@ config MOTORS_DEFAULT_PROP_TEST_PWM_RATIO drone uses full thrust for brushed motors and does not spin up brushless motors (for safety reasons). It is therefore advised to set this parameter explicitly for brushless builds to enable the motor test functionality. - + The value specified here can also be overridden with parameters. +choice + prompt "Type of power distribution" + default POWER_DISTRIBUTION_QUADROTOR + +config POWER_DISTRIBUTION_QUADROTOR + bool "Quadrotor power distribution" + depends on PLATFORM_CF2 || PLATFORM_BOLT || PLATFORM_TAG + help + Power distribution function for quadrotors +endchoice + endmenu menu "Parameter subsystem" @@ -141,4 +152,3 @@ config PARAM_SILENT_UPDATES what you are doing. endmenu - diff --git a/src/modules/src/power_distribution_stock.c b/src/modules/src/power_distribution_quadrotor.c similarity index 96% rename from src/modules/src/power_distribution_stock.c rename to src/modules/src/power_distribution_quadrotor.c index 98f516e142..a45a880e85 100644 --- a/src/modules/src/power_distribution_stock.c +++ b/src/modules/src/power_distribution_quadrotor.c @@ -7,7 +7,7 @@ * * Crazyflie control firmware * - * Copyright (C) 2011-2016 Bitcraze AB + * Copyright (C) 2011-2022 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 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * power_distribution_stock.c - Crazyflie stock power distribution code + * power_distribution_quadrotor.c - Crazyflie stock power distribution code */ #include "power_distribution.h" From b09987599170527c1c5df6e22dd3118e9a59c0d3 Mon Sep 17 00:00:00 2001 From: Kristoffer Richardsson Date: Wed, 8 Jun 2022 14:37:27 +0200 Subject: [PATCH 3/3] Removed old configs from CF1 --- .../sensor-to-control/index.md | 5 ---- src/config/config.h | 28 ++++++++----------- .../src/power_distribution_quadrotor.c | 25 +++++------------ 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/docs/functional-areas/sensor-to-control/index.md b/docs/functional-areas/sensor-to-control/index.md index 16ed252216..08e83bb833 100644 --- a/docs/functional-areas/sensor-to-control/index.md +++ b/docs/functional-areas/sensor-to-control/index.md @@ -81,14 +81,9 @@ Go to the [Commander page](commanders_setpoints.md), for more in-depth informati After the state controller has send out its commands, this is not the end of the line yet. The controllers send out their commands relating to their yaw, roll and pitch angles. How the motors should respond in order to adhere these attitude based commands depends on a few factors: - * Quadrotor configuration (found in: `power_distribution_quadrotor.c`: - * x-configuration: The body fixed coordinate system's x-axis is pointed in between two propellors (Default) - * +-configuration: The body fixed coordinate system's x-axis is pointed in one propellor * Motors: * Brushed: The Crazyflie has brushed motors, of which there is battery compensation function enabled. Check out `motors.c` to learn more. Also checkout the [PWM to Thrust investigations](/docs/functional-areas/pwm-to-thrust.md) of those same motors. * Brushless: The Bolt enables the control of brushless motors. Checkout the[ product page of the Bolt](https://www.bitcraze.io/products/crazyflie-bolt/) for more information. - - ## Configuring Controllers and Estimators Go to this [configuration page](configure_estimator_controller.md), if you would like to configure different controllers and estimators, diff --git a/src/config/config.h b/src/config/config.h index 0bd607190b..f05884f923 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -7,7 +7,7 @@ * * Crazyflie control firmware * - * Copyright (C) 2011-2012 Bitcraze AB + * Copyright (C) 2011-2022 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 @@ -48,22 +48,18 @@ #define PROTOCOL_VERSION 5 -#ifdef STM32F4XX - #define QUAD_FORMATION_X - - #define CONFIG_BLOCK_ADDRESS (2048 * (64-1)) - #define MCU_ID_ADDRESS 0x1FFF7A10 - #define MCU_FLASH_SIZE_ADDRESS 0x1FFF7A22 - #ifndef FREERTOS_HEAP_SIZE - #define FREERTOS_HEAP_SIZE 30000 - #endif - #define FREERTOS_MIN_STACK_SIZE 150 // M4-FPU register setup is bigger so stack needs to be bigger - #define FREERTOS_MCU_CLOCK_HZ 168000000 - - #define configGENERATE_RUN_TIME_STATS 1 - #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() initUsecTimer() - #define portGET_RUN_TIME_COUNTER_VALUE() usecTimestamp() +#define CONFIG_BLOCK_ADDRESS (2048 * (64-1)) +#define MCU_ID_ADDRESS 0x1FFF7A10 +#define MCU_FLASH_SIZE_ADDRESS 0x1FFF7A22 +#ifndef FREERTOS_HEAP_SIZE + #define FREERTOS_HEAP_SIZE 30000 #endif +#define FREERTOS_MIN_STACK_SIZE 150 // M4-FPU register setup is bigger so stack needs to be bigger +#define FREERTOS_MCU_CLOCK_HZ 168000000 + +#define configGENERATE_RUN_TIME_STATS 1 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() initUsecTimer() +#define portGET_RUN_TIME_COUNTER_VALUE() usecTimestamp() // Task priorities. Higher number higher priority diff --git a/src/modules/src/power_distribution_quadrotor.c b/src/modules/src/power_distribution_quadrotor.c index a45a880e85..b24110d19d 100644 --- a/src/modules/src/power_distribution_quadrotor.c +++ b/src/modules/src/power_distribution_quadrotor.c @@ -31,7 +31,7 @@ #include "param.h" #include "num.h" #include "autoconf.h" -#include "config.h" // Important, since this defines QUAD_FORMATION_X +#include "config.h" #ifndef CONFIG_MOTORS_DEFAULT_IDLE_THRUST # define DEFAULT_IDLE_THRUST 0 @@ -55,23 +55,12 @@ bool powerDistributionTest(void) void powerDistribution(motors_thrust_t* motorPower, const control_t *control) { - #ifdef QUAD_FORMATION_X - int16_t r = control->roll / 2.0f; - int16_t p = control->pitch / 2.0f; - motorPower->m1 = limitThrust(control->thrust - r + p + control->yaw); - motorPower->m2 = limitThrust(control->thrust - r - p - control->yaw); - motorPower->m3 = limitThrust(control->thrust + r - p + control->yaw); - motorPower->m4 = limitThrust(control->thrust + r + p - control->yaw); - #else // QUAD_FORMATION_NORMAL - motorPower->m1 = limitThrust(control->thrust + control->pitch + - control->yaw); - motorPower->m2 = limitThrust(control->thrust - control->roll - - control->yaw); - motorPower->m3 = limitThrust(control->thrust - control->pitch + - control->yaw); - motorPower->m4 = limitThrust(control->thrust + control->roll - - control->yaw); - #endif + int16_t r = control->roll / 2.0f; + int16_t p = control->pitch / 2.0f; + motorPower->m1 = limitThrust(control->thrust - r + p + control->yaw); + motorPower->m2 = limitThrust(control->thrust - r - p - control->yaw); + motorPower->m3 = limitThrust(control->thrust + r - p + control->yaw); + motorPower->m4 = limitThrust(control->thrust + r + p - control->yaw); if (motorPower->m1 < idleThrust) { motorPower->m1 = idleThrust;