From 35f5092a5dd985f4a77a676466c20d18535e7a41 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Tue, 4 Jun 2024 13:53:59 +0200 Subject: [PATCH 1/3] Add platform configuration for CF2.1 brushless - Platform comes with modified defaults for PID tuning, idle thrust, platform mass, and battery limit compared to CF2.1. - The brushless defconfig enables manual arming and the DSHOT ESC protocol. - Moved idle thrust configuration out of kbuild. --- Kconfig | 5 + Makefile | 4 + configs/cf21bl_defconfig | 4 + configs/cfbl_defconfig | 4 - docs/building-and-flashing/build.md | 1 + docs/development/create_platform.md | 8 ++ src/modules/src/Kconfig | 12 +- src/platform/interface/platform_defaults.h | 5 +- .../interface/platform_defaults_cf21bl.h | 134 ++++++++++++++++++ src/platform/src/Kbuild | 1 + src/platform/src/platform_cf21bl.c | 66 +++++++++ 11 files changed, 228 insertions(+), 16 deletions(-) create mode 100644 configs/cf21bl_defconfig delete mode 100644 configs/cfbl_defconfig create mode 100644 src/platform/interface/platform_defaults_cf21bl.h create mode 100644 src/platform/src/platform_cf21bl.c diff --git a/Kconfig b/Kconfig index 61444e9f2c..b5d0b3fa31 100644 --- a/Kconfig +++ b/Kconfig @@ -69,6 +69,11 @@ config PLATFORM_CF2 select SENSORS_BMI088_BMP3XX select SENSORS_MPU9250_LPS25H +config PLATFORM_CF21BL + bool "Build for CF2.1 brushless" + select SENSORS_BMI088_BMP3XX + select SENSORS_MPU9250_LPS25H + config PLATFORM_BOLT bool "Build for Bolt" select SENSORS_BMI088_BMP3XX diff --git a/Makefile b/Makefile index cea681b70b..8b5ae0a04c 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,10 @@ unquoted = $(patsubst "%",%,$(CONFIG_DECK_LOCO_2D_POSITION_HEIGHT)) ARCH_CFLAGS += -DDECK_LOCO_2D_POSITION_HEIGHT=$(unquoted) endif +ifeq ($(CONFIG_PLATFORM_CF21BL), y) +PLATFORM = cf21bl +endif + ifeq ($(CONFIG_PLATFORM_TAG),y) PLATFORM = tag endif diff --git a/configs/cf21bl_defconfig b/configs/cf21bl_defconfig new file mode 100644 index 0000000000..4df3978746 --- /dev/null +++ b/configs/cf21bl_defconfig @@ -0,0 +1,4 @@ +CONFIG_PLATFORM_CF21BL=y + +CONFIG_MOTORS_REQUIRE_ARMING=y +CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y diff --git a/configs/cfbl_defconfig b/configs/cfbl_defconfig deleted file mode 100644 index 809b104a12..0000000000 --- a/configs/cfbl_defconfig +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y - -CONFIG_ESTIMATOR_AUTO_SELECT=y -CONFIG_CONTROLLER_AUTO_SELECT=y diff --git a/docs/building-and-flashing/build.md b/docs/building-and-flashing/build.md index 24b6be9483..eee92b8586 100644 --- a/docs/building-and-flashing/build.md +++ b/docs/building-and-flashing/build.md @@ -171,6 +171,7 @@ bindings_python : Build the python bindings for firmware wrappers menuconfig : Open up a terminal user interface to set configuration options defconfig : Generate a `.config` with the default configuration options cf2_defconfig : Merge configuration options from `configs/cf2_defconfig` with default +cf21bl_defconfig: Merge configuration options from `configs/cf21bl_defconfig` with default tag_defconfig : Merge configuration options from `configs/tag_defconfig` with default bolt_defconfig : Merge configuration options from `configs/bolt_defconfig` with default allyesconfig : Generate a `.config` with the all configuration options enabled diff --git a/docs/development/create_platform.md b/docs/development/create_platform.md index 441bd76ea0..219e1b6cce 100644 --- a/docs/development/create_platform.md +++ b/docs/development/create_platform.md @@ -81,6 +81,7 @@ We need to add a entry point for your platform. The way the build system determi ```Makefile obj-$(CONFIG_PLATFORM_BOLT) += platform_bolt.o obj-$(CONFIG_PLATFORM_CF2) += platform_cf2.o +obj-$(CONFIG_PLATFORM_CF21BL) += platform_cf21bl.o obj-$(CONFIG_PLATFORM_TAG) += platform_tag.o obj-y += platform.o obj-y += platform_stm32f4.o @@ -92,6 +93,7 @@ Let's add `RINCEWIND`: ```Makefile obj-$(CONFIG_PLATFORM_BOLT) += platform_bolt.o obj-$(CONFIG_PLATFORM_CF2) += platform_cf2.o +obj-$(CONFIG_PLATFORM_CF21BL) += platform_cf21bl.o obj-$(CONFIG_PLATFORM_TAG) += platform_tag.o obj-$(CONFIG_PLATFORM_RINCEWIND) += platform_rincewind.o obj-y += platform.o @@ -156,6 +158,9 @@ Your platform need to define suitable default values to (persistent) parameters. #ifdef CONFIG_PLATFORM_CF2 #include "platform_defaults_cf2.h" #endif +#ifdef CONFIG_PLATFORM_CF21BL + #include "platform_defaults_cf21bl.h" +#endif #ifdef CONFIG_PLATFORM_BOLT #include "platform_defaults_bolt.h" #endif @@ -175,6 +180,9 @@ Becomes: #ifdef CONFIG_PLATFORM_CF2 #include "platform_defaults_cf2.h" #endif +#ifdef CONFIG_PLATFORM_CF21BL + #include "platform_defaults_cf21bl.h" +#endif #ifdef CONFIG_PLATFORM_BOLT #include "platform_defaults_bolt.h" #endif diff --git a/src/modules/src/Kconfig b/src/modules/src/Kconfig index bd3aecaa93..30fb37edb1 100644 --- a/src/modules/src/Kconfig +++ b/src/modules/src/Kconfig @@ -150,16 +150,6 @@ config MOTORS_REQUIRE_ARMING When enabled, system must be armed to be able to take off. Arming can be done in several ways, e.g. though cfclient or external transmitter. -config MOTORS_DEFAULT_IDLE_THRUST - int "Default idle thrust for motors in armed state" - range 0 65535 - default 0 - depends on MOTORS_REQUIRE_ARMING - help - Default thrust for motors when idling in armed state, expressed as an - integer in the range 0 to 65535. This can be overridden with parameters; - the value specified here applies to the case when the persistent storage - does not contain an idle thrust value. config MOTORS_DEFAULT_PROP_TEST_PWM_RATIO int "Override default PWM ratio to use during motor tests" @@ -192,7 +182,7 @@ choice config POWER_DISTRIBUTION_QUADROTOR bool "Quadrotor power distribution" - depends on PLATFORM_CF2 || PLATFORM_BOLT || PLATFORM_TAG + depends on PLATFORM_CF2 || PLATFORM_CF21BL|| PLATFORM_BOLT || PLATFORM_TAG help Power distribution function for quadrotors config POWER_DISTRIBUTION_FLAPPER diff --git a/src/platform/interface/platform_defaults.h b/src/platform/interface/platform_defaults.h index e85abfb7de..6798e10dcd 100644 --- a/src/platform/interface/platform_defaults.h +++ b/src/platform/interface/platform_defaults.h @@ -7,7 +7,7 @@ * * Crazyflie control firmware * - * Copyright (C) 2022 Bitcraze AB + * Copyright (C) 2022-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 @@ -34,6 +34,9 @@ #ifdef CONFIG_PLATFORM_CF2 #include "platform_defaults_cf2.h" #endif +#ifdef CONFIG_PLATFORM_CF21BL + #include "platform_defaults_cf21bl.h" +#endif #ifdef CONFIG_PLATFORM_BOLT #include "platform_defaults_bolt.h" #endif diff --git a/src/platform/interface/platform_defaults_cf21bl.h b/src/platform/interface/platform_defaults_cf21bl.h new file mode 100644 index 0000000000..81e207968f --- /dev/null +++ b/src/platform/interface/platform_defaults_cf21bl.h @@ -0,0 +1,134 @@ +/** + * ,---------, ____ _ __ + * | ,-^-, | / __ )(_) /_______________ _____ ___ + * | ( 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 . + * + * + * platform_defaults_cf21bl.h - platform specific default values for the cf2.1 brushless platform + */ + +#pragma once + +#ifndef __INCLUDED_FROM_PLATFORM_DEFAULTS__ +#pragma GCC error "Do not include this file directly, include platform_defaults.h instead." +#endif + +// Defines for default values in the cf2 platform + +// Default values for battery limits +#define DEFAULT_BAT_LOW_VOLTAGE 3.35f +#define DEFAULT_BAT_CRITICAL_LOW_VOLTAGE 3.3f +#define DEFAULT_BAT_LOW_DURATION_TO_TRIGGER_SEC 5 + +// Default value for system shutdown in minutes after radio silence. +// Requires kbuild config ENABLE_AUTO_SHUTDOWN to be activated. +#define DEFAULT_SYSTEM_SHUTDOWN_TIMEOUT_MIN 5 + +// Drone physical constants +// m +#define ARM_LENGTH 0.046f +// kg +#define CF_MASS 0.030f + +// Default PID gains +#define PID_ROLL_RATE_KP 200.0 +#define PID_ROLL_RATE_KI 400.0 +#define PID_ROLL_RATE_KD 2.5 +#define PID_ROLL_RATE_KFF 0.0 +#define PID_ROLL_RATE_INTEGRATION_LIMIT 33.3 + +#define PID_PITCH_RATE_KP 200.0 +#define PID_PITCH_RATE_KI 400.0 +#define PID_PITCH_RATE_KD 2.5 +#define PID_PITCH_RATE_KFF 0.0 +#define PID_PITCH_RATE_INTEGRATION_LIMIT 33.3 + +#define PID_YAW_RATE_KP 120.0 +#define PID_YAW_RATE_KI 16.7 +#define PID_YAW_RATE_KD 0.0 +#define PID_YAW_RATE_KFF 0.0 +#define PID_YAW_RATE_INTEGRATION_LIMIT 166.7 + +#define PID_ROLL_KP 6.0 +#define PID_ROLL_KI 3.0 +#define PID_ROLL_KD 0.0 +#define PID_ROLL_KFF 0.0 +#define PID_ROLL_INTEGRATION_LIMIT 20.0 + +#define PID_PITCH_KP 6.0 +#define PID_PITCH_KI 3.0 +#define PID_PITCH_KD 0.0 +#define PID_PITCH_KFF 0.0 +#define PID_PITCH_INTEGRATION_LIMIT 20.0 + +#define PID_YAW_KP 6.0 +#define PID_YAW_KI 1.0 +#define PID_YAW_KD 0.35 +#define PID_YAW_KFF 0.0 +#define PID_YAW_INTEGRATION_LIMIT 360.0 + +#define PID_VEL_X_KP 25.0f +#define PID_VEL_X_KI 1.0f +#define PID_VEL_X_KD 0.0f +#define PID_VEL_X_KFF 0.0f + +#define PID_VEL_Y_KP 25.0f +#define PID_VEL_Y_KI 1.0f +#define PID_VEL_Y_KD 0.0f +#define PID_VEL_Y_KFF 0.0f + +#define PID_VEL_Z_KP 25.0f +#define PID_VEL_Z_KI 15.0f +#define PID_VEL_Z_KD 0.0f +#define PID_VEL_Z_KFF 0.0f + +#define PID_VEL_Z_KP_BARO_Z_HOLD 3.0f +#define PID_VEL_Z_KI_BARO_Z_HOLD 1.0f +#define PID_VEL_Z_KD_BARO_Z_HOLD 1.5f +#define PID_VEL_Z_KFF_BARO_Z_HOLD 0.0f + +#define PID_VEL_ROLL_MAX 20.0f +#define PID_VEL_PITCH_MAX 20.0f +#define PID_VEL_THRUST_BASE 30000.0f +#define PID_VEL_THRUST_BASE_BARO_Z_HOLD 38000.0f +#define PID_VEL_THRUST_MIN 20000.0f + +#define PID_POS_X_KP 2.0f +#define PID_POS_X_KI 0.0f +#define PID_POS_X_KD 0.0f +#define PID_POS_X_KFF 0.0f + +#define PID_POS_Y_KP 2.0f +#define PID_POS_Y_KI 0.0f +#define PID_POS_Y_KD 0.0f +#define PID_POS_Y_KFF 0.0f + +#define PID_POS_Z_KP 2.0f +#define PID_POS_Z_KI 0.5f +#define PID_POS_Z_KD 0.0f +#define PID_POS_Z_KFF 0.0f + +#define PID_POS_VEL_X_MAX 1.0f +#define PID_POS_VEL_Y_MAX 1.0f +#define PID_POS_VEL_Z_MAX 1.0f + +// Manual arming, default idle thrust +#define CONFIG_MOTORS_DEFAULT_IDLE_THRUST 7000 diff --git a/src/platform/src/Kbuild b/src/platform/src/Kbuild index 51fde8c2d9..ec6895c16f 100644 --- a/src/platform/src/Kbuild +++ b/src/platform/src/Kbuild @@ -1,5 +1,6 @@ obj-$(CONFIG_PLATFORM_BOLT) += platform_bolt.o obj-$(CONFIG_PLATFORM_CF2) += platform_cf2.o +obj-$(CONFIG_PLATFORM_CF21BL) += platform_cf21bl.o obj-$(CONFIG_PLATFORM_TAG) += platform_tag.o obj-$(CONFIG_PLATFORM_FLAPPER) += platform_flapper.o obj-y += platform.o diff --git a/src/platform/src/platform_cf21bl.c b/src/platform/src/platform_cf21bl.c new file mode 100644 index 0000000000..085ccd572c --- /dev/null +++ b/src/platform/src/platform_cf21bl.c @@ -0,0 +1,66 @@ +/** + * || ____ _ __ + * +------+ / __ )(_) /_______________ _____ ___ + * | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ + * +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ + * || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ + * + * 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 . + * + * Platform functionality for the CF2.1 brushless platform + */ + +#define DEBUG_MODULE "PLATFORM" + +#include + +#include "platform.h" +#include "exti.h" +#include "nvic.h" +#include "debug.h" + +static platformConfig_t configs[] = { +#ifdef CONFIG_SENSORS_BMI088_BMP3XX + { + .deviceType = "C21B", + .deviceTypeName = "Crazyflie 2.1 Brushless", + .sensorImplementation = SensorImplementation_bmi088_bmp3xx, + .physicalLayoutAntennasAreClose = true, + .motorMap = motorMapCF21Brushless, + }, +#endif +}; + +const platformConfig_t* platformGetListOfConfigurations(int* nrOfConfigs) { + *nrOfConfigs = sizeof(configs) / sizeof(platformConfig_t); + return configs; +} + +void platformInitHardware() { + //Low level init: Clock and Interrupt controller + nvicInit(); + + //EXTI interrupts + extiInit(); +} + + +// Config functions ------------------------ + +const char* platformConfigGetPlatformName() { + return "cf21bl"; +} From ebbc5bd91f99bf502c2d51538b2254b4c7320852 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Tue, 4 Jun 2024 14:47:01 +0200 Subject: [PATCH 2/3] Force manual arming for brushless This automatically forces manual arming if users manually select the brushless as the platform in kbuild instead of by loading the brushless defconfig. Without this, users could compile a flyable firmware and accidentally forget to enable manual arming. People that want autoarming on the brushless platform will have to modify the kbuild system. --- Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/Kconfig b/Kconfig index b5d0b3fa31..12d9375a2a 100644 --- a/Kconfig +++ b/Kconfig @@ -73,6 +73,7 @@ config PLATFORM_CF21BL bool "Build for CF2.1 brushless" select SENSORS_BMI088_BMP3XX select SENSORS_MPU9250_LPS25H + select MOTORS_REQUIRE_ARMING config PLATFORM_BOLT bool "Build for Bolt" From c9ec44cdebdbbce0a606c07dfe9dfeb4b1ffb111 Mon Sep 17 00:00:00 2001 From: Rik Bouwmeester Date: Wed, 5 Jun 2024 11:26:33 +0200 Subject: [PATCH 3/3] Remove unused sensor drivers for the CF21BL --- Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/Kconfig b/Kconfig index 12d9375a2a..34139f7f54 100644 --- a/Kconfig +++ b/Kconfig @@ -72,7 +72,6 @@ config PLATFORM_CF2 config PLATFORM_CF21BL bool "Build for CF2.1 brushless" select SENSORS_BMI088_BMP3XX - select SENSORS_MPU9250_LPS25H select MOTORS_REQUIRE_ARMING config PLATFORM_BOLT