Skip to content

Commit

Permalink
Add ESC protocol and battery voltage threshold configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas authored and jonasdn committed Feb 25, 2022
1 parent 55bfc54 commit 7c72ef3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ config IMU_MAHONY_QUATERNION
endchoice

endmenu

menu "Sensor configuration"

config SENSORS_MPU9250_LPS25H
Expand Down Expand Up @@ -138,6 +139,8 @@ config SENSORS_BMI088_I2C

endmenu

source src/hal/src/Kconfig

menu "App layer configuration"

source "app_api/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ ifneq ($(CONFIG_DECK_LOCO_2D_POSITION_HEIGHT),)
unquoted = $(patsubst "%",%,$(CONFIG_DECK_LOCO_2D_POSITION_HEIGHT))
ARCH_CFLAGS += -DDECK_LOCO_2D_POSITION_HEIGHT=$(unquoted)
endif
unquoted = $(patsubst "%",%,$(CONFIG_PM_BAT_LOW_VOLTAGE))
ARCH_CFLAGS += -DPM_BAT_LOW_VOLTAGE=$(unquoted)f
unquoted = $(patsubst "%",%,$(CONFIG_PM_BAT_CRITICAL_LOW_VOLTAGE))
ARCH_CFLAGS += -DPM_BAT_CRITICAL_LOW_VOLTAGE=$(unquoted)f

ifeq ($(CONFIG_PLATFORM_TAG),y)
PLATFORM = tag
Expand Down
9 changes: 4 additions & 5 deletions src/drivers/interface/motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "config.h"
#include "autoconf.h"
/* ST includes */
#include "stm32fxxx.h"

Expand All @@ -62,9 +63,7 @@
// Not applied for brushless motor setup.
#define ENABLE_THRUST_BAT_COMPENSATED

//#define ENABLE_ONESHOT125

#ifdef ENABLE_ONESHOT125
#ifdef CONFIG_MOTORS_ESC_PROTOCOL_ONESHOT125
/**
* *VARNING* Make sure the brushless driver is configured correctly as on the Crazyflie with normal
* brushed motors connected they can turn on at full speed when it is powered on!
Expand All @@ -80,7 +79,7 @@
#define MOTORS_BL_PWM_PERIOD MOTORS_BL_PWM_CNT_FOR_PERIOD
#define MOTORS_BL_PWM_PRESCALE (uint16_t)(MOTORS_BL_PWM_PRESCALE_RAW - 1)
#define MOTORS_BL_POLARITY TIM_OCPolarity_Low
#elif defined(ENABLE_ONESHOT42)
#elif defined(CONFIG_MOTORS_ESC_PROTOCOL_ONESHOT42)
/**
* *VARNING* Make sure the brushless driver is configured correctly as on the Crazyflie with normal
* brushed motors connected they can turn on at full speed when it is powered on!
Expand All @@ -98,7 +97,7 @@
#define MOTORS_BL_POLARITY TIM_OCPolarity_Low
#else
/**
* *VARNING* Make sure the brushless driver is configured correctly as on the Crazyflie with normal
* *WARNING* Make sure the brushless driver is configured correctly as on the Crazyflie with normal
* brushed motors connected they can turn on at full speed when it is powered on!
*
* Generates a PWM wave (50 - 400 Hz update rate with 1-2 ms high pulse) using the timer. That way we can use the same
Expand Down
14 changes: 4 additions & 10 deletions src/hal/interface/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@
#include "syslink.h"
#include "deck.h"

#ifndef CRITICAL_LOW_VOLTAGE
#define PM_BAT_CRITICAL_LOW_VOLTAGE 3.0f
#else
#define PM_BAT_CRITICAL_LOW_VOLTAGE CRITICAL_LOW_VOLTAGE
#endif
// PM_BAT_LOW_VOLTAGE and PM_BAT_CRITICAL_LOW_VOLTAGE are now defined by the
// Makefile. Do not use CONFIG_PM_BAT_CRITICAL_LOW_VOLTAGE and
// CONFIG_PM_BAT_LOW_VOLTAGE as those are strings.

#ifndef CRITICAL_LOW_TIMEOUT
#define PM_BAT_CRITICAL_LOW_TIMEOUT M2T(1000 * 5) // 5 sec default
#else
#define PM_BAT_CRITICAL_LOW_TIMEOUT CRITICAL_LOW_TIMEOUT
#endif

#ifndef LOW_VOLTAGE
#define PM_BAT_LOW_VOLTAGE 3.2f
#else
#define PM_BAT_LOW_VOLTAGE LOW_VOLTAGE
#endif
#ifndef LOW_TIMEOUT
#define PM_BAT_LOW_TIMEOUT M2T(1000 * 5) // 5 sec default
#else
Expand Down
26 changes: 21 additions & 5 deletions src/hal/src/Kconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
menu "IMU sensor configuration"
menu "Power management configuration"

config SENSORS_BMI088_BMP388
bool "Support for bmi088 and bmp388 sensors"
#
# Kconfig does not support float, we use strings here and fix them up in the
# Makefile.
#
config PM_BAT_LOW_VOLTAGE
string "Low voltage threshold in volts"
default 3.2
help
Include support for the Bosch bmi088 inertial and bmp388
barometric sensors
The power management subsystem will enter the "low voltage" state when
the battery voltage is below this threshold for a prolonged period of
time. The length of this period is configured in the code; see
hal/interface/pm.h

config PM_BAT_CRITICAL_LOW_VOLTAGE
string "Critical low voltage threshold in volts"
default 3.0
help
The power management subsystem will shut the system down when the
battery voltage is below this threshold for a prolonged period of
time. The length of this period is configured in the code; see
hal/interface/pm.h

endmenu
15 changes: 15 additions & 0 deletions src/modules/src/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ endmenu

menu "Motor configuration"

choice
prompt "ESC protocol"
default MOTORS_ESC_PROTOCOL_STANDARD_PWM

config MOTORS_ESC_PROTOCOL_STANDARD_PWM
bool "Standard PWM"

config MOTORS_ESC_PROTOCOL_ONESHOT125
bool "OneShot125"

config MOTORS_ESC_PROTOCOL_ONESHOT42
bool "OneShot42"

endchoice

config MOTORS_START_DISARMED
bool "Set disarmed state after boot"
default n
Expand Down

0 comments on commit 7c72ef3

Please sign in to comment.