Skip to content

Commit

Permalink
Fix Bug unexpected movement MASSAGE; Adjustments
Browse files Browse the repository at this point in the history
Fix bug where armchair moved too long every once in a while (especially
at start).
Minor adjustments of parameters.

main.cpp:
  - set individual task priorities for each task e.g. fan or buzzer task has very low priority (did not have any immediate effect though while testing)
  - increase handle interval of motorctl
    change from 20 to 10 (same frequency as generation of massage
    commands)
    -> this fixed the bug with unexpected movement (motorctl could not
    process every command from massage mode)

control.cpp:
  - decrease delay in massage mode for more detail/levels at joystick
    radius (from 20 to 10ms)
  - increase fading in massage mode (400ms to 500ms) for slightly less hard
    shaking

joystick.cpp:
  - reduce max shaking amount
  - swap modes
     - top left shake backward
     - top right shake forward
     - bottom left/right shake rotating
  • Loading branch information
Jonny999999 committed Jul 25, 2022
1 parent ad0723a commit 3fa2f17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions main/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void controlledArmchair::startHandleLoop() {


case controlMode_t::MASSAGE:
vTaskDelay(20 / portTICK_PERIOD_MS);
vTaskDelay(10 / portTICK_PERIOD_MS);
//--- read joystick ---
//only update joystick data when input not frozen
if (!freezeInput){
Expand Down Expand Up @@ -313,7 +313,7 @@ void controlledArmchair::changeMode(controlMode_t modeNew) {

case controlMode_t::MASSAGE:
ESP_LOGW(TAG, "switching to MASSAGE mode -> reducing fading");
uint32_t shake_msFadeAccel = 400; //TODO: move this to config
uint32_t shake_msFadeAccel = 500; //TODO: move this to config

//disable downfading (max. deceleration)
motorLeft->setFade(fadeType_t::DECEL, false);
Expand Down
8 changes: 4 additions & 4 deletions main/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ joystickPos_t lastStickPos = joystickPos_t::CENTER;
joystickPos_t stickQuadrant = joystickPos_t::CENTER;

//--- configure shake mode --- TODO: move this to config
uint32_t shake_msOffMax = 90;
uint32_t shake_msOnMax = 180;
uint32_t shake_msOffMax = 80;
uint32_t shake_msOnMax = 120;
float dutyShake = 60;

//function that generates commands for both motors from the joystick data
Expand Down Expand Up @@ -498,15 +498,15 @@ motorCommands_t joystick_generateCommandsShaking(joystickData_t data){
commands.right.state = motorstate_t::FWD;
break;
case joystickPos_t::TOP_LEFT:
commands.left.state = motorstate_t::FWD;
commands.left.state = motorstate_t::REV;
commands.right.state = motorstate_t::REV;
break;
case joystickPos_t::BOTTOM_LEFT:
commands.left.state = motorstate_t::REV;
commands.right.state = motorstate_t::FWD;
break;
case joystickPos_t::BOTTOM_RIGHT:
commands.left.state = motorstate_t::REV;
commands.left.state = motorstate_t::FWD;
commands.right.state = motorstate_t::REV;
break;
}
Expand Down
12 changes: 6 additions & 6 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void task_motorctl( void * pvParameters ){
motorRight.handle();
motorLeft.handle();
//10khz -> T=100us
vTaskDelay(20 / portTICK_PERIOD_MS);
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ extern "C" void app_main(void) {
//esp_log_level_set("evaluatedJoystick", ESP_LOG_DEBUG);
//esp_log_level_set("joystickCommands", ESP_LOG_DEBUG);
esp_log_level_set("button", ESP_LOG_INFO);
esp_log_level_set("control", ESP_LOG_DEBUG);
esp_log_level_set("control", ESP_LOG_INFO);
esp_log_level_set("fan-control", ESP_LOG_INFO);
esp_log_level_set("wifi", ESP_LOG_INFO);
esp_log_level_set("http", ESP_LOG_INFO);
Expand All @@ -158,12 +158,12 @@ extern "C" void app_main(void) {
//--- create task for controlling the motors ---
//----------------------------------------------
//task that receives commands, handles ramp and current limit and executes commands using the motordriver function
xTaskCreate(&task_motorctl, "task_motor-control", 2048, NULL, 5, NULL);
xTaskCreate(&task_motorctl, "task_motor-control", 2048, NULL, 6, NULL);

//------------------------------
//--- create task for buzzer ---
//------------------------------
xTaskCreate(&task_buzzer, "task_buzzer", 2048, NULL, 5, NULL);
xTaskCreate(&task_buzzer, "task_buzzer", 2048, NULL, 2, NULL);

//-------------------------------
//--- create task for control ---
Expand All @@ -175,13 +175,13 @@ extern "C" void app_main(void) {
//--- create task for button ---
//------------------------------
//task that evaluates and processes the button input and runs the configured commands
xTaskCreate(&task_button, "task_button", 2048, NULL, 5, NULL);
xTaskCreate(&task_button, "task_button", 2048, NULL, 4, NULL);

//-----------------------------------
//--- create task for fan control ---
//-----------------------------------
//task that evaluates and processes the button input and runs the configured commands
xTaskCreate(&task_fans, "task_fans", 2048, NULL, 5, NULL);
xTaskCreate(&task_fans, "task_fans", 2048, NULL, 1, NULL);


//beep at startup
Expand Down

0 comments on commit 3fa2f17

Please sign in to comment.