From 7dbccfd59aa0dff47a65ca660c17c71afacf820f Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Tue, 11 Jun 2024 10:15:12 +0200 Subject: [PATCH 1/2] Stop building a FW that has both arming set to off, and idle_thrust higher than 0. Will only stop build time misconfiguration --- src/modules/src/power_distribution_quadrotor.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/src/power_distribution_quadrotor.c b/src/modules/src/power_distribution_quadrotor.c index a58e1e415..5c963328d 100644 --- a/src/modules/src/power_distribution_quadrotor.c +++ b/src/modules/src/power_distribution_quadrotor.c @@ -35,6 +35,9 @@ #include "math.h" #include "platform_defaults.h" +#if (!defined(CONFIG_MOTORS_REQUIRE_ARMING) || (CONFIG_MOTORS_REQUIRE_ARMING == 0)) && defined(CONFIG_MOTORS_DEFAULT_IDLE_THRUST) && (CONFIG_MOTORS_DEFAULT_IDLE_THRUST > 0) + #error "CONFIG_MOTORS_REQUIRE_ARMING must be defined and not set to 0 if CONFIG_MOTORS_DEFAULT_IDLE_THRUST is greater than 0" +#endif #ifndef CONFIG_MOTORS_DEFAULT_IDLE_THRUST # define DEFAULT_IDLE_THRUST 0 #else From aa03faad1a96e0c0ccb31261074cc308dca4f9bc Mon Sep 17 00:00:00 2001 From: Tove Rumar Date: Tue, 11 Jun 2024 11:04:54 +0200 Subject: [PATCH 2/2] Block idlethtrust and unarmed feature at run time. We need to override the idleThrust param stored in eeprom with 0 if arming is not on The (brushless) motors needs to be fed a 0 signal after they started up and we do not know exactly when that is. These two features are mutually eclusive and can not be used together --- src/modules/src/power_distribution_quadrotor.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/src/power_distribution_quadrotor.c b/src/modules/src/power_distribution_quadrotor.c index 5c963328d..7fd2dc5da 100644 --- a/src/modules/src/power_distribution_quadrotor.c +++ b/src/modules/src/power_distribution_quadrotor.c @@ -24,9 +24,11 @@ * power_distribution_quadrotor.c - Crazyflie stock power distribution code */ + #include "power_distribution.h" #include +#include "debug.h" #include "log.h" #include "param.h" #include "num.h" @@ -66,6 +68,11 @@ uint16_t powerDistributionStopRatio(uint32_t id) void powerDistributionInit(void) { + #if (!defined(CONFIG_MOTORS_REQUIRE_ARMING) || (CONFIG_MOTORS_REQUIRE_ARMING == 0)) + if(idleThrust > 0) { + DEBUG_PRINT("WARNING: idle thrust will be overridden with value 0. Autoarming can not be on while idle thrust is higher than 0. If you want to use idle thust please use use arming\n"); + } + #endif } bool powerDistributionTest(void) @@ -166,14 +173,19 @@ bool powerDistributionCap(const motors_thrust_uncapped_t* motorThrustBatCompUnca for (int motorIndex = 0; motorIndex < STABILIZER_NR_OF_MOTORS; motorIndex++) { int32_t thrustCappedUpper = motorThrustBatCompUncapped->list[motorIndex] - reduction; - motorPwm->list[motorIndex] = capMinThrust(thrustCappedUpper, idleThrust); + motorPwm->list[motorIndex] = capMinThrust(thrustCappedUpper, powerDistributionGetIdleThrust()); } return isCapped; } -uint32_t powerDistributionGetIdleThrust() { - return idleThrust; +uint32_t powerDistributionGetIdleThrust() +{ + int32_t thrust = idleThrust; + #if (!defined(CONFIG_MOTORS_REQUIRE_ARMING) || (CONFIG_MOTORS_REQUIRE_ARMING == 0)) + thrust = 0; + #endif + return thrust; } float powerDistributionGetMaxThrust() {