Fix decel massage, Fix bugged pixels (clear), Less Fan
- fix deceleration being overwritten in nvs at massage mode change (as accel before) - handle deadlock when handle-loop does not give back mutex (rare but had that once -> restart) - clear display when changing to mode-select - clear display when switching status page - adjust fan time (less on) - slightly adjust accel/decel/max duty (needs testing)
This commit is contained in:
parent
c738ac96b1
commit
5fe970f60b
@ -99,8 +99,8 @@ sabertooth2x60_config_t sabertoothConfig = {
|
||||
motorctl_config_t configMotorControlLeft = {
|
||||
.name = "left",
|
||||
.loggingEnabled = true,
|
||||
.msFadeAccel = 1500, // acceleration of the motor (ms it takes from 0% to 100%)
|
||||
.msFadeDecel = 1000, // deceleration of the motor (ms it takes from 100% to 0%)
|
||||
.msFadeAccel = 1800, // acceleration of the motor (ms it takes from 0% to 100%)
|
||||
.msFadeDecel = 1600, // deceleration of the motor (ms it takes from 100% to 0%)
|
||||
.currentLimitEnabled = false,
|
||||
.tractionControlSystemEnabled = false,
|
||||
.currentSensor_adc = ADC1_CHANNEL_4, // GPIO32
|
||||
@ -117,8 +117,8 @@ motorctl_config_t configMotorControlLeft = {
|
||||
motorctl_config_t configMotorControlRight = {
|
||||
.name = "right",
|
||||
.loggingEnabled = false,
|
||||
.msFadeAccel = 1500, // acceleration of the motor (ms it takes from 0% to 100%)
|
||||
.msFadeDecel = 1000, // deceleration of the motor (ms it takes from 100% to 0%)
|
||||
.msFadeAccel = 1800, // acceleration of the motor (ms it takes from 0% to 100%)
|
||||
.msFadeDecel = 1600, // deceleration of the motor (ms it takes from 100% to 0%)
|
||||
.currentLimitEnabled = false,
|
||||
.tractionControlSystemEnabled = false,
|
||||
.currentSensor_adc = ADC1_CHANNEL_5, // GPIO33
|
||||
@ -179,10 +179,10 @@ joystick_config_t configJoystick = {
|
||||
//----------------------------
|
||||
fan_config_t configFans = {
|
||||
.gpio_fan = GPIO_NUM_13,
|
||||
.dutyThreshold = 40,
|
||||
.minOnMs = 1500,
|
||||
.minOffMs = 3000,
|
||||
.turnOffDelayMs = 5000,
|
||||
.dutyThreshold = 50,
|
||||
.minOnMs = 3500, // time motor duty has to be above the threshold for fans to turn on
|
||||
.minOffMs = 5000, // min time fans have to be off to be able to turn on again
|
||||
.turnOffDelayMs = 3000, // time fans continue to be on after duty is below threshold
|
||||
};
|
||||
|
||||
|
||||
@ -258,7 +258,7 @@ joystickGenerateCommands_config_t joystickGenerateCommands_config{
|
||||
//-- maxDuty --
|
||||
// max duty when both motors are at equal ratio e.g. driving straight forward
|
||||
// better to be set less than 100% to have some reserve for boosting the outer tire when turning
|
||||
.maxDutyStraight = 75,
|
||||
.maxDutyStraight = 65,
|
||||
//-- maxBoost --
|
||||
// boost is amount of duty added to maxDutyStraight to outer tire while turning
|
||||
// => turning: inner tire gets slower, outer tire gets faster
|
||||
|
@ -25,6 +25,7 @@ static const char * ERROR_STR = "ERR";
|
||||
|
||||
const char* controlModeStr[10] = {"IDLE", "JOYSTICK", "MASSAGE", "HTTP", "MQTT", "BLUETOOTH", "AUTO", "ADJUST_CHAIR", "MENU_SETTINGS", "MENU_MODE_SELECT"};
|
||||
const uint8_t controlModeMaxCount = sizeof(controlModeStr) / sizeof(char *);
|
||||
#define MUTEX_TIMEOUT 10000 // restart when stuck waiting for handle() mutex
|
||||
|
||||
|
||||
//==========================
|
||||
@ -113,7 +114,7 @@ void controlledArmchair::startHandleLoop()
|
||||
while (1)
|
||||
{
|
||||
// mutex to prevent race condition with actions beeing run at mode change and previous mode still beeing executed
|
||||
if (xSemaphoreTake(handleIteration_mutex, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTake(handleIteration_mutex, MUTEX_TIMEOUT / portTICK_PERIOD_MS) == pdTRUE)
|
||||
{
|
||||
//--- handle current mode ---
|
||||
ESP_LOGV(TAG, "control loop executing... mode='%s'", controlModeStr[(int)mode]);
|
||||
@ -121,6 +122,10 @@ void controlledArmchair::startHandleLoop()
|
||||
|
||||
xSemaphoreGive(handleIteration_mutex);
|
||||
} // end mutex
|
||||
else {
|
||||
ESP_LOGE(TAG, "mutex timeout - stuck in changeMode? -> RESTART");
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
//--- slow loop ---
|
||||
// this section is run approx every 5s (+500ms)
|
||||
@ -433,6 +438,7 @@ void controlledArmchair::changeMode(controlMode_t modeNew)
|
||||
{
|
||||
// variable to store configured accel limit before entering massage mode, to restore it later
|
||||
static uint32_t massagePreviousAccel = motorLeft->getFade(fadeType_t::ACCEL);
|
||||
static uint32_t massagePreviousDecel = motorLeft->getFade(fadeType_t::DECEL);
|
||||
|
||||
// exit if target mode is already active
|
||||
if (mode == modeNew)
|
||||
@ -444,7 +450,7 @@ void controlledArmchair::changeMode(controlMode_t modeNew)
|
||||
// mutex to wait for current handle iteration (control-task) to finish
|
||||
// prevents race conditions where operations when changing mode are run but old mode gets handled still
|
||||
ESP_LOGI(TAG, "changeMode: waiting for current handle() iteration to finish...");
|
||||
if (xSemaphoreTake(handleIteration_mutex, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTake(handleIteration_mutex, MUTEX_TIMEOUT / portTICK_PERIOD_MS) == pdTRUE)
|
||||
{
|
||||
// copy previous mode
|
||||
modePrevious = mode;
|
||||
@ -478,8 +484,8 @@ void controlledArmchair::changeMode(controlMode_t modeNew)
|
||||
ESP_LOGW(TAG, "switching from MASSAGE mode -> restoring fading, reset frozen input");
|
||||
// TODO: fix issue when downfading was disabled before switching to massage mode - currently it gets enabled again here...
|
||||
// enable downfading (set to default value)
|
||||
motorLeft->setFade(fadeType_t::DECEL, true);
|
||||
motorRight->setFade(fadeType_t::DECEL, true);
|
||||
motorLeft->setFade(fadeType_t::DECEL, massagePreviousDecel);
|
||||
motorRight->setFade(fadeType_t::DECEL, massagePreviousDecel);
|
||||
// restore previously set acceleration limit
|
||||
motorLeft->setFade(fadeType_t::ACCEL, massagePreviousAccel);
|
||||
motorRight->setFade(fadeType_t::ACCEL, massagePreviousAccel);
|
||||
@ -538,12 +544,14 @@ void controlledArmchair::changeMode(controlMode_t modeNew)
|
||||
case controlMode_t::MASSAGE:
|
||||
ESP_LOGW(TAG, "switching to MASSAGE mode -> reducing fading");
|
||||
uint32_t shake_msFadeAccel = 200; // TODO: move this to config
|
||||
uint32_t shake_msFadeDecel = 0; // TODO: move this to config
|
||||
|
||||
// save currently set normal acceleration config (for restore when leavinge MASSAGE again)
|
||||
massagePreviousAccel = motorLeft->getFade(fadeType_t::ACCEL);
|
||||
massagePreviousDecel = motorLeft->getFade(fadeType_t::DECEL);
|
||||
// disable downfading (max. deceleration)
|
||||
motorLeft->setFade(fadeType_t::DECEL, false);
|
||||
motorRight->setFade(fadeType_t::DECEL, false);
|
||||
motorLeft->setFade(fadeType_t::DECEL, shake_msFadeDecel, false);
|
||||
motorRight->setFade(fadeType_t::DECEL, shake_msFadeDecel, false);
|
||||
// reduce upfading (increase acceleration) but do not update nvs
|
||||
motorLeft->setFade(fadeType_t::ACCEL, shake_msFadeAccel, false);
|
||||
motorRight->setFade(fadeType_t::ACCEL, shake_msFadeAccel, false);
|
||||
@ -556,6 +564,11 @@ void controlledArmchair::changeMode(controlMode_t modeNew)
|
||||
// unlock mutex for control task to continue handling modes
|
||||
xSemaphoreGive(handleIteration_mutex);
|
||||
} // end mutex
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "mutex timeout - stuck in handle() loop? -> RESTART");
|
||||
esp_restart();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO simplify the following 3 functions? can be replaced by one?
|
||||
|
@ -498,6 +498,7 @@ void display_rotateStatusPage(bool reverseDirection, bool noRotate)
|
||||
else
|
||||
// select next screen
|
||||
display_selectStatusPage((displayStatusPage_t)((int)selectedStatusPage + 1));
|
||||
ssd1306_clear_screen(&dev, false); // clear screen when switching
|
||||
}
|
||||
else // rotate back
|
||||
{
|
||||
@ -510,6 +511,7 @@ void display_rotateStatusPage(bool reverseDirection, bool noRotate)
|
||||
else
|
||||
// select previous screen
|
||||
display_selectStatusPage((displayStatusPage_t)((int)selectedStatusPage - 1));
|
||||
ssd1306_clear_screen(&dev, false); // clear screen when switching
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1008,6 +1008,7 @@ void handleMenu_modeSelect(display_task_parameters_t *objects, SSD1306_t *displa
|
||||
if (firstRun)
|
||||
{
|
||||
firstRun = false;
|
||||
ssd1306_clear_screen(display, false); // clear screen initially (no artefacts of previous content)
|
||||
selectedMode = (int)objects->control->getPreviousMode(); // store previous mode (since current mode is MENU)
|
||||
ESP_LOGI(TAG, "started mode-select menu, previous active is %s", controlModeStr[(int)selectedMode]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user