Handle denials of power appropriately

This commit is contained in:
2025-02-12 22:59:13 +01:00
parent 21f7d9ae8a
commit c130026f00
19 changed files with 126 additions and 47 deletions

View File

@ -29,10 +29,24 @@ void Motor::begin(void){
void Motor::setSpeed(uint16_t duty){
const float dutyFactor = duty / static_cast<float>(1 << DUTY_RES);
const float current = PowerParameters::CurrentConsumptions::CURRENT_MOTOR_T_ON * dutyFactor;
if (this->pin == MOTOR_LEFT_PIN){
Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::MOTOR_LEFT, current, MOTOR_MAX_EXECUTION_DELAY_MS, NULL);
if (this->pin == MOTOR_LEFT_PIN) {
if (!Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::MOTOR_LEFT, current,
MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) {
ESP_LOGW(TAG,
"Power to set LEFT MOTOR to speed %d not granted in time. "
"Skipping.",
duty);
}
} else {
Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::MOTOR_RIGHT, current, MOTOR_MAX_EXECUTION_DELAY_MS, NULL);
if (!Power::waitForCurrentAllowance(
PowerParameters::PowerConsumers::MOTOR_RIGHT, current,
MOTOR_MAX_EXECUTION_DELAY_MS, NULL)) {
ESP_LOGW(TAG,
"Power to set RIGHT MOTOR to speed %d not granted in time. "
"Skipping.",
duty);
}
}
int difference = duty-this->getSpeed();
if (difference > 0){