19 Commits

Author SHA1 Message Date
jonny_l480
d715f2e0f1 Fix bugged coordinate/radius scaling
- uncomment coordinate scaling which caused unwanted behaivor
    especially that radius never got to 1 when joystick diagonal
    resulting in loss of power/speed in curves
- now scaling radius only which is the desired functionality

- optimize debug logging
- fix joystick calibration config (invertion was mistaken)
2023-08-16 10:51:33 +02:00
jonny_l480
e017932db7 Adjust config: more fade, stick tolerance, less startDuty
turned out that higher voltage of new battery results in way more
responsive motors.
Adjust this with available settings (less shaking)
2023-08-15 23:14:44 +02:00
jonny_l480
73ad36bb2d Update joystick config, Add option JOYSTICK_LOG_IN_IDLE
- add more debug output in joystick getData function
- update joystick config with new min/max values while testing
    => fixed bugged movement (joystick unusable) after winter
- bump esp-idf version since successfully compiled with 4.4.4
2023-05-27 11:11:13 +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_ji7
1c3576206a Add button commands; Update Readme
button.cpp:
- Add command: reboot when long button press
- Add command: switch to mode JOYSTICK with 3x press

Readme:
 - rework table with switch functions
 - add new commands to table
 - add drink holder to planned features

joystick.cpp:
 - fix bug: missing 'break;' for switch case in function joystick_CommandsShaking
2022-07-25 22:45:59 +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
ad0723a766 Update MASSAGE: 4 modes (each quadrant) with hysteresis
Modified function that generates commands in massage mode (joystick.cpp)
- define variable stickQuadrant with axis as hysteresis from actual joystick data/pos
- prepare switch case for implementation of 4 modes (each quadrant)
- add basic content to modes for testing (different motor directions)

TODO: remove old code with pulsing shake variable and implement actual modes
2022-07-25 11:02:52 +02:00
jonny_ji7
d573cc5b24 Revert "Add hysteresis to joystick position X-Axis"
While testing this feature briefly that approach did not appear to be a good idea.
- noticed that the driving with joystick was a little unintuitive/unexpected (maybe just not used to it?)
- BUG that the state does not reset to center when previous state was
  X-AXIS? Resulting in the armchair to slightly shake randomly at
  joystick center
  -> this has to be fixed if this approach is tested again.

This reverts commit b2b12fe5de1e16ea2f25dfa4b0c3ac6845024c71.
2022-07-14 18:50:36 +02:00
jonny_ji7
b2b12fe5de Add hysteresis to joystick position X-Axis [WIP]
modified function
joystickPos_t joystick_evaluatePosition(float x, float y, joystickPos_t* prevPos)

because prevPos has to be stored http.cpp/hpp and joystick.cpp/hpp had
to be updated as well

TODO: add function without hysteresis again?
WIP this has to be tested
2022-07-08 19:38:29 +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
1da03e9429 Add different tolerances for X and Y coordinate
As already did for http joystick:
- Add different config options tolerance zero for X and Y axis for
normal/actual joystick.

This makes it possible to set Y tolerance to a lower value resulting in
a more responsive turning action, with still having a large range around
X axis for turning mode
2022-06-24 09:06:26 +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
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_l480
0165a88f1f Change dutyMax and fade, Add reboot cmd (1x press)
decrease ramp from 3000ms to 900ms (as in old project)
increase max duty from testing 60 to 94
Add reboot command (untested)
2022-06-19 09:34:14 +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
f7ce61c666 Add function 'joystick_generateCommandsDriving'
- add new function to joystick.hpp/cpp
  - reads data from joystick and generates commands for driving in
    "joystick" mode
  - returns struct with commands for both motors

- main.cpp
  - add code for testing the new function
  - enable 5v regulator (needed for pullups AB left motor)
  - add newly created motorRight to handle function

- add new struct with two motorcommands to motorctl.hpp
2022-06-09 21:42:01 +02:00
jonny_ji7
4eb1c5d43a Create class 'evaluatedJoystick'
- Create class 'evaluatedJoystick'
  - evaluates a joystick with 2 analog signals
  - scales the adc input to coordinates with detailed tolerances
  - calculates angle and radius
  - defines an enum with position information
- Add joystick configuration and class instance to config.cpp
- Add code for testing the new class to main.cpp
- Add joystick.cpp to cmakelists

now function `joystick.getData` can be used globally to obtain a struct with
current position data of the joystick
2022-06-08 19:50:17 +02:00