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

Toverumar/mutual excl idlethrust #1384

Merged
merged 2 commits into from
Jun 11, 2024
Merged
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
21 changes: 18 additions & 3 deletions src/modules/src/power_distribution_quadrotor.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
* power_distribution_quadrotor.c - Crazyflie stock power distribution code
*/


#include "power_distribution.h"

#include <string.h>
#include "debug.h"
#include "log.h"
#include "param.h"
#include "num.h"
Expand All @@ -35,6 +37,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
Expand Down Expand Up @@ -63,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)
Expand Down Expand Up @@ -163,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() {
Expand Down
Loading