20 Commits

Author SHA1 Message Date
jonny_ji7
f8415655c2 Create class 'automatedArmchair', Add AUTO mode
- Create class automatedArmchair in new files auto.hpp and auto.cpp
  This class currently makes it possible to queue up and run commands
  (motorstate, duty for certaion duration),

- add new file to cmakelists
- create automatedArmchair instance 'armchair' in config.cpp
- add loglevel configuration to main.cpp
- add AUTO mode to control.cpp (no way to change to mode yet)
2022-08-10 22:01:50 +02:00
jonny_ji7
66756b9b75 Fix bug: massage stick freeze not resetting
When switching mode from MASSAGE to other mode while joystick input
frozen (button). It was still frozen when switching back to MASSAGE mode
later. This is confusing and is seen as a bug

-> reset locked input variable to false on mode change
2022-07-28 17:54:44 +02:00
jonny_ji7
bbe26a3823 Add button cmd x12: alternative joystick mapping
New command and feature also made some  general changes to control and button necessary

joystick.cpp:
  - add optional parameter to joystick_CommandsDriving function
    bool altStickMapping (default false)
    if true this currently swaps BOTTOM_LEFT with BOTTOM_RIGHT for experimental
    different joystick mapping

button.cpp:
  - fix/move variable declaration outside of switch
  - add 12x case: send count to control task

control.cpp:
  - create new section in handle loop for button events
  - move x1 commands from JOYSTICK and MASSAGE case to new button
    section
  - remove unnecessary variable buttonEvent (only using buttonCount now)
  - add functionality to 12x button event -> toggle alternative stick
    mapping

readme.md:
  - add new x12 button command
2022-07-26 09:53:37 +02:00
jonny_l480
3fa2f17a72 Fix Bug unexpected movement MASSAGE; Adjustments
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
2022-07-25 12:54:05 +02:00
jonny_ji7
fea8c94a73 Modify fading when switching from/to MASSAGE mode
In massage mode it is required that the motors react quicker, Added the
following functionality to control.cpp:

- when changing to MASSAGE mode the downfading is disabled and upfading is
reduced
- when changing from MASSAGE mode downfading is enabled and upfading reset
to default value
2022-07-24 17:13:12 +02:00
jonny_ji7
cac22ca4e1 Add functions to send button-event to control task
- control.cpp:  - Add method sendButtonEvent to control class
                - joystick mode: define joystick center at button event
                - massage mode: toggle freezing of joystick input at
                  button event
- button.cpp: remove reboot command (1x press)
- button.cpp: add command sendButtonEvent to control task (1x press)
2022-07-24 13:25:43 +02:00
jonny_ji7
77a32c15f7 Optimize control: use reference to joystick object
Use reference to joystick object in control class instead of accessing
the global evaluatedJoystick object

control.hpp:
  - add joystick reference to constructor
  - add local joystick pointer variable

control.cpp:
  - constructor: copy pointer to joystick object
  - use methods of joystick reference instead of global object
  - update log output of timeout check

config.cpp:
  - add joystick object to control object construction
2022-07-08 18:49:17 +02:00
jonny_ji7
b460a52181 Add linear scaling of stick coordinates
- joystick.hpp/cpp
  - add function joystick_scaleCoordinatesLinear(joystickData_t * data, float pointX, float pointY)
    that scales the coordinates with 2 different slopes before and
    after certain point

- control.cpp
  - scale coordinates linear with new function instead of exponential in JOYSTICK mode
  - scale coordinates linear with new function instead of exponential in HTTP mode

- config.cpp
  - adjust / decrease http joystick tolerances

Note: tested the armchair in http and joystick mode briefly and
      optimized the scaling point slightly
2022-07-06 17:23:54 +02:00
jonny_l480
1c6586c29e Add exponential scaling of stick coordinates
- joystick.hpp/cpp
  - add function joystick_scaleCoordinatesExp(joystickData_t * data, float exponent)
    which updates joystick data with its scaled coordinates and
    re-calculated radius

- control.cpp
  - scale coordinates exponential (pow 2) in JOYSTICK mode
  - scale coordinates exponential (pow 2) in HTTP mode

- config.cpp
  - fixed swapped x/y zero tolerances for hardware joystick

Note: tested armchair with scaling exponents 1.5; 2; 3 and noticed that
2 works best
2022-07-05 18:38:08 +02:00
jonny_ji7
9db5736f77 Create shake mode (basic functionality)
- add function joystick_generateCommandsShaking that generates motor
commands from joystick data
- pulses motors:
   - intervals depend on joystick radius
   - direction depends on joystick position (currently only on-x-axis and on-y-axis
     supported)
2022-06-25 21:52:49 +02:00
jonny_ji7
06d0fda8ee Create httpJoystick class
create new class for http mode -> move code for http mode from control.cpp to http.cpp
this makes control.cpp and config.cpp more clear
2022-06-22 12:29:08 +02:00
jonny_l480
73325e08ce Fix bug in scaling, Fix http cmd gen, Fix overflow
Fix several bugs noticed while testing the preceding commits in dev
branch:

- Fix bug in function scaleCoordinate
  - scaling was wrong resulting in negative/inverted values at start of axis

- Adjust timeout value from 30s to 5min

- Fix http joystick behaivor
  - calculate angle, radius and evaluate position AFTER the coordinates
    have been scaled in control.cpp (bug introduced when switching applying tolerance
    on controller instead of in the app)

- Add independent toleranceZero for X and Y axis -> unnecessary to have
  large tolerance for x axis... makes turning more sensitive

- Fix stack overflow in control task
  - controller crashed repeatedly when logging output was enabled in
    control task
  - -> doubled stack size at task creation in main.cpp

currently works, position hast to be evaluated AFTER coordinate scaling
2022-06-22 09:09:40 +02:00
jonny_ji7
f38940b7bf Move config parameters from control to config
- create new struct control_config_t with several variables previously
  hardcoded in control.cpp
- modified constructor: add config parameter
- add definition of config struct in config.cpp

typedef struct control_config_t {
    controlMode_t defaultMode;  //default mode after startup and toggling IDLE
    //--- timeout ---
    uint32_t timeoutMs;         //time of inactivity after which the mode gets switched to IDLE
    float timeoutTolerancePer;  //percentage the duty can vary between timeout checks considered still inactive
    //--- http mode ---
    float http_toleranceZeroPer;//percentage around joystick axis the coordinate snaps to 0
    float http_toleranceEndPer; //percentage before joystick end the coordinate snaps to 1/-1
    uint32_t http_timeoutMs;    //time no new data was received before the motors get turned off
2022-06-21 10:32:08 +02:00
jonny_ji7
d32b0c5671 Add timeout feature to control
Add feature that switches to mode IDLE when duty of both motors did not
change over certain time.

control.cpp/hpp:
 - add private function that handles timeout
 - add public function that resets timeout
 - add slow loop with timeout handle inside control handle loop
2022-06-20 22:42:11 +02:00
jonny_ji7
20873b4175 Move coordinate scaling from app to controller
- joystick.cpp/hpp:
  - move method scaleCoordinate from joystick class to public function
  - modify scaleCoordinate function to accept float values instead of
    ADC pin, change tolerance parameters to percent instead of absolute
    number
  - change method getData to use the public function now

- control.cpp:
  - use scaleCoordinate function in http mode
  - calculate radius in http mode

- config.cpp
  - adjust tolerance thresholds for joystick to percent

- App.js
  - disable "snap to zero" feature -> just scale joystick output to
    value of -1 to 1
2022-06-19 15:37:42 +02:00
jonny_ji7
d0b3b6fb78 Add timeout to HTTP mode, Change Queue size
- control.cpp: Add feature to HTTP mode, that turns motors off when at least one motor is still on
  but no data was received for more than 3 seconds (e.g. wifi connection
  lost)

- change queue size from 20 to 1 - no need to store multiple joystick
  data since only the latest one is relevant

- add "preset command" to control.hpp to set both motors to IDLE
2022-06-17 21:10:20 +02:00
jonny_ji7
3cb5bc410b Create http server, Add HTTP mode
- Create http.cpp and http.hpp
  - functions for initializing a http server
  - function for URL api/joystick
    - receive joystick data from http post request
    - parse json, define joystick position (function from joystick.hpp)
    - send data to control task via queue

- control.hpp/cpp:
  - add HTTP mode to handle loop
    - receive joystick commands from queue, generate commands, send to
      motorctl
  - upgrade changeMode function with ability to run functions at switch
    FROM and TO certain modes
    - add code to start/stop wifi and webserver when switching to/from
      HTTP mode
  - change toggleModes and toggleIdle to use the changeMode function

- main.cpp:
  - add several sections with code for testing new functions (commented
    out)
  - add http loglevel

- buzzer.cpp:
  - add command (press 4 times) to toggle between HTTP and JOYSTICK mode

FIXME: moved initialization of wifi to main.cpp at startup because of an
error -> resolve this and place wifi start and stop functions into
mode-change as intended

currently works best in accesspoint mode with laptop connected using the
react-webapp
2022-06-17 18:24:11 +02:00
jonny_ji7
cc5226647b Move joystick pos-definition to separate function
Move section that defines joystick position enum to a separate function
(outside of joystick class), this makes it usable for other inputs as
well
- create new function joystick_evaluatePosition
- call the new function in joystickgetData (where code was initially)
- change function joystick_generateCommandsDriving to accept joystick
  data struct instead of joystick object as parameter -> makes the
  function usable with other input than hardware joystick too
2022-06-17 10:43:00 +02:00
jonny_ji7
5e2962302d Move control to class, Add toggleIdle, toggleModes
- Move all separately declared functions in control.hpp to a new class
  'controlledArmchair'
    - now passing other objects only one time with constructor instead
      of accessing them globally
- Create control instance in config.hpp, and passing objects in
  config.cpp

- Add functions to new control class
  - toggleIdle(): toggle between last mode and idle
  - toggleModes(mode1, mode2): toggle between two modes

- Add commands to button.cpp
  - 2x button press: call toggleIdle()
  - 6x button press: toggleModes  MASSAGE -> JOYSTICK

- Define control task in main.cpp
- Adjust button files and main.cpp to use the new command object instead
  of the previus functions
2022-06-11 13:07:42 +02:00
jonny_ji7
adb517c7ed Create 'control.hpp/cpp', Create 'button.hpp/cpp'
Add control.hpp and control.cpp
 - task that repeatedly generates motor commands depending on the current mode
 - function to change to a specified control mode

Add button.hpp and button.cpp
  - class which runs commands depending on the count a button was pressed

Update main.cpp
  - create button task
  - create control task
  - comment out previous testing code
  - remove unnecessary includes (already included in config.hpp)

Add control.cpp and button.cpp to CMakeLists

Notes: Tested this state on the armchair: All currently implemented features
work. You can switch between IDLE and JOYSTICK by pressing the button 2
or 3 times. Also driving works well (limited to 60% duty, with no fans
yet).
2022-06-10 23:09:23 +02:00