Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kconfig updates #1056

Merged
merged 3 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions configs/bolt_defconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONFIG_PLATFORM_BOLT=y

CONFIG_ESTIMATOR=any
CONFIG_CONTROLLER=Any
CONFIG_POWER_DISTRIBUTION=stock
CONFIG_ESTIMATOR_ANY=y
CONFIG_CONTROLLER_ANY=y
5 changes: 2 additions & 3 deletions configs/cfbl_defconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y

CONFIG_ESTIMATOR=any
CONFIG_CONTROLLER=Any
CONFIG_POWER_DISTRIBUTION=stock
CONFIG_ESTIMATOR_ANY=y
CONFIG_CONTROLLER_ANY=y
7 changes: 3 additions & 4 deletions configs/tag_defconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
CONFIG_PLATFORM_TAG=y

CONFIG_ESTIMATOR=any
CONFIG_CONTROLLER=Any
CONFIG_POWER_DISTRIBUTION=stock
CONFIG_ESTIMATOR_ANY=y
CONFIG_CONTROLLER_ANY=y

CONFIG_DECK_FORCE=bcDWM1000
CONFIG_DECK_FORCE="bcDWM1000"
CONFIG_SENSORS_IGNORE_BAROMETER_FAIL=y
65 changes: 59 additions & 6 deletions docs/development/create_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,17 @@ 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_POWER_DISTRIBUTION=stock
CONFIG_ESTIMATOR_ANY=y
CONFIG_CONTROLLER_ANY=y
```

Based on this a start of `rincewind_defconfig` could be:

```Makefile
CONFIG_PLATFORM_RINCEWIND=y

CONFIG_ESTIMATOR=any
CONFIG_CONTROLLER=Any
CONFIG_POWER_DISTRIBUTION=stock
CONFIG_ESTIMATOR_ANY=y
CONFIG_CONTROLLER_ANY=y
```

Then `RINCEWIND` platform could be built by:
Expand All @@ -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!
2 changes: 1 addition & 1 deletion docs/development/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/development/oot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
3 changes: 1 addition & 2 deletions docs/functional-areas/sensor-to-control/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.

Expand All @@ -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()`.

8 changes: 0 additions & 8 deletions docs/functional-areas/sensor-to-control/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +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_stock.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,



2 changes: 1 addition & 1 deletion docs/userguides/deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 12 additions & 16 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/modules/src/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/modules/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -141,4 +152,3 @@ config PARAM_SILENT_UPDATES
what you are doing.

endmenu

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* power_distribution_stock.c - Crazyflie stock power distribution code
* power_distribution_quadrotor.c - Crazyflie stock power distribution code
*/

#include "power_distribution.h"
Expand All @@ -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
Expand All @@ -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;
Expand Down