Rework brake (decel-boost): simplify, config option

Briefly tested this - brake works as intended

- Add config options brakeDecel and brakePauseBefureResume
- control: update brakeStartThresholdDuty at startup
    and maxDuty change for each motor
- motorctl: drop/simplify decel boost to brake
    (faster deceleration at certain threshold)
This commit is contained in:
jonny_l480
2024-05-18 23:32:52 +02:00
parent 967f2cd8b5
commit 3ebcd6ad3c
6 changed files with 69 additions and 25 deletions

View File

@@ -32,7 +32,7 @@ void setLoglevels(void)
// esp_log_level_set("motordriver", ESP_LOG_DEBUG);
esp_log_level_set("motor-control", ESP_LOG_WARN);
// esp_log_level_set("evaluatedJoystick", ESP_LOG_DEBUG);
esp_log_level_set("joystickCommands", ESP_LOG_DEBUG);
esp_log_level_set("joystickCommands", ESP_LOG_WARN);
esp_log_level_set("button", ESP_LOG_INFO);
esp_log_level_set("control", ESP_LOG_INFO);
// esp_log_level_set("fan-control", ESP_LOG_INFO);
@@ -108,7 +108,9 @@ motorctl_config_t configMotorControlLeft = {
.currentMax = 30,
.currentInverted = true,
.currentSnapToZeroThreshold = 0.15,
.deadTimeMs = 0 // minimum time motor is off between direction change
.deadTimeMs = 0, // minimum time motor is off between direction change
.brakePauseBeforeResume = 1500,
.brakeDecel = 400,
};
//--- configure right motor (contol) ---
@@ -124,7 +126,9 @@ motorctl_config_t configMotorControlRight = {
.currentMax = 30,
.currentInverted = false,
.currentSnapToZeroThreshold = 0.25,
.deadTimeMs = 0 // minimum time motor is off between direction change
.deadTimeMs = 0, // minimum time motor is off between direction change
.brakePauseBeforeResume = 1500,
.brakeDecel = 400,
};
//------------------------------

View File

@@ -59,6 +59,10 @@ controlledArmchair::controlledArmchair(
// override default config value if maxDuty is found in nvs
loadMaxDuty();
// update brake start threshold with actual max duty for motorctl
ESP_LOGW(TAG, "setting brake start threshold for both motors to %.0f", joystickGenerateCommands_config.maxDutyStraight * BRAKE_START_STICK_PERCENTAGE / 100);
motorLeft->setBrakeStartThresholdDuty(joystickGenerateCommands_config.maxDutyStraight * BRAKE_START_STICK_PERCENTAGE / 100);
motorRight->setBrakeStartThresholdDuty(joystickGenerateCommands_config.maxDutyStraight * BRAKE_START_STICK_PERCENTAGE / 100);
// create semaphore for preventing race condition: mode-change operations while currently still executing certain mode
handleIteration_mutex = xSemaphoreCreateMutex();

View File

@@ -13,6 +13,8 @@ extern "C"
#include "speedsensor.hpp"
#include "chairAdjust.hpp"
//percentage stick has to be moved in the opposite driving direction of current motor direction for braking to start
#define BRAKE_START_STICK_PERCENTAGE 95
//--------------------------------------------
//---- struct, enum, variable declarations ---
@@ -93,7 +95,11 @@ class controlledArmchair {
bool toggleAltStickMapping();
// configure max dutycycle (in joystick or http mode)
void setMaxDuty(float maxDutyNew) { writeMaxDuty(maxDutyNew); };
void setMaxDuty(float maxDutyNew) {
writeMaxDuty(maxDutyNew);
motorLeft->setBrakeStartThresholdDuty(joystickGenerateCommands_config.maxDutyStraight * BRAKE_START_STICK_PERCENTAGE/100);
motorRight->setBrakeStartThresholdDuty(joystickGenerateCommands_config.maxDutyStraight * BRAKE_START_STICK_PERCENTAGE/100);
};
float getMaxDuty() const {return joystickGenerateCommands_config.maxDutyStraight; };
// configure max boost (in joystick or http mode)
void setMaxRelativeBoostPer(float newValue) { joystickGenerateCommands_config.maxRelativeBoostPercentOfMaxDuty = newValue; };