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

Add platform configuration for CF2.1 brushless #1383

Merged
merged 4 commits into from
Jun 10, 2024
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
5 changes: 5 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions configs/cf21bl_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_PLATFORM_CF21BL=y

CONFIG_MOTORS_REQUIRE_ARMING=y
CONFIG_MOTORS_ESC_PROTOCOL_DSHOT=y
4 changes: 0 additions & 4 deletions configs/cfbl_defconfig

This file was deleted.

1 change: 1 addition & 0 deletions docs/building-and-flashing/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/development/create_platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 1 addition & 11 deletions src/modules/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
tobbeanton marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/platform/interface/platform_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
134 changes: 134 additions & 0 deletions src/platform/interface/platform_defaults_cf21bl.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*
* 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
1 change: 1 addition & 0 deletions src/platform/src/Kbuild
Original file line number Diff line number Diff line change
@@ -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
Expand Down
66 changes: 66 additions & 0 deletions src/platform/src/platform_cf21bl.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
* Platform functionality for the CF2.1 brushless platform
*/

#define DEBUG_MODULE "PLATFORM"

#include <string.h>

#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";
}
Loading