diff --git a/Kconfig b/Kconfig index 61444e9f2c..34139f7f54 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 MOTORS_REQUIRE_ARMING + 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"; +}