81 Commits

Author SHA1 Message Date
jonny_jr9
e6e586e585 Fix broken http mode (crash at init)
revert changes from previous commit
2023-08-30 08:56:51 +02:00
jonny_l480
224ac47214 Merge branch 'dev' - new wiring, currentlimit, deadtime, fixes 2023-08-22 11:21:25 +02:00
jonny_l480
884c00e3d9 Add deadTime support (time off between dir change)
add config option for minimum time motor has to be in IDLE before
changing direction. Try to prevent drivers from obvious extreme
overload. At least prevent full speed switch

Untested but simulated via log output
2023-08-22 11:16:37 +02:00
jonny_l480
4731f9253e Cleanup: comments, structure, warnings
went trough all current files:
- remove old comments
- change structure / newlines

- main.cpp: outsource loglevel function
- http.cpp: FIX compiler warnings

	currentsensor.hpp
2023-08-22 11:16:37 +02:00
jonny_l480
a6de6c4c10 Add currentsensor support - current limit functional
- add currentsensor class
- add current limit to motorctl handle function
- add config options for curring limit for each motor
- update connection plan with more detailed driver-box overview
2023-08-22 11:16:25 +02:00
jonny_l480
d51e8ae006 evaluatedSwitch: avoid random trigger (increase threshold)
- with new hardware noticed that sometimes switch gets triggered x1
  randomly when driving forward (EMI ?)
- increased delay options (less responsive but more controlled)
2023-08-21 09:49:05 +02:00
jonny_l480
3ba37baeda Optimize turning: allow duty=0 for inner wheel, prepare ratio snap threshold
- joystick command generation:
    - also remove min duty offset with changing ratio
- prepare threshold where ratio snaps to max for easier turning
  -> issue with driver has to be fixed first

- minor motordriver optimization / add commented out debug mode
  (driver forward in idle)
2023-08-21 09:47:48 +02:00
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
be40a8c2d3 Rework fan control: single pin, more delay, config
- remove second fan instance since both fans are controlled via one pin
  now
- more config options so fans turn on less at short movements
  => less noise and less relay cycles
2023-08-15 19:39:37 +02:00
jonny_l480
3f73344b93 Update config with new pin assignment
- apply changed pins to config (according to new hardware configuration)
- calibrate joystick, more tolerance
2023-08-14 23:54:12 +02:00
jonny_l480
86638ff7c5 V2 - rework connection-plan: new pin assignment, wiring plan
Update connection plan with new wiring and pin assignment
  - add display
  - add temp sensors
  - single fan
  - add rotary encoder

Add wiring plan with details about hardware
2023-08-14 23:07:52 +02:00
jonny_l480
9550b387c9 Config: Replace abInverted with a- and bEnabledPinState
Changed config and code for motor driver:
Now its possible to configure whether a and b pins are inverted separately
e.g. a connected to mosfets (inverted) and b connected directly
2023-08-13 10:34:41 +02:00
jonny_l480
007b76b3a3 Merge branch 'dev' - auto/command mode 2023-08-04 19:16:17 +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_l480
f0e1a7d883 Merge branch 'auto-mode' into dev - eject support feature
functionality for creating command sequenes,
currently only auto eject leg support implemented (1 short, 1 long press)
2023-05-26 12:39:05 +02:00
jonny_l480
06d6138917 Update Readme: http usage, Connection-plan: add Date
Readme
- add todo section
- add http usage

Add date to connection plan
2023-05-14 12:30:45 +02:00
jonny_ji7
7b1b985a15 Add longPressed case to button class, rework cmds
- slightly decrease msFadeDecel by 100ms

- different approach in button.cpp for case last button press was long
  e.g. reworked commands:
   - 1x long press = restart
   - 1x short press = center stick, freeze
   - 1x short 1x long = run new auto commands
   - 2x short = toggle idle

- change default minOnMs / minOffMs for evaulated switch class -> fix
  button presses sometimes not recognized
2022-08-11 15:15:55 +02:00
jonny_l480
0148f69fab Pass joystick object to button class
the joystick object is now available in the button class/task
thus can be used to trigger commands with certain combinations of
joystick and button
- not used yet -
2022-08-11 13:32:16 +02:00
jonny_l480
fb9e9ede25 Add working command instructions, optimize control
auto.cpp:
  - forward instructions from commands to newly passed pointer
control.cpp:
  - handle instructions returned at generation of commands in auto mode
  - add method toggleMode
  - remove dupliate code in toggleIdle method
button.cpp:
  - optimize command for enabling leg support, add instruction
2022-08-11 13:13:05 +02:00
jonny_l480
6dfae934d5 Fix stack overflow, apply and restore fading [functional]
auto.cpp:
  apply fadeAccel and fadeDecel from commands to motors

main.cpp:
  double stack size of button task (crashed controller every time)

button.cpp:
 Modify test command to actually eject armchair leg support

control.cpp:
  apply generated motor commands to motors

rename some variables:
 typo: fadeAccel
 more specific: auto_instruction_t
2022-08-11 11:21:29 +02:00
jonny_ji7
24d89b96cc Add example command, Improvements
- automaticArmchair:
  - add method addCommands for adding an array of
    commands to queue
  - add keys to simpleCommand struct
    - fadeDecel (not used yet)
    - fadeAcel (not used yet)
    - instructions (new enum for running other commands in control task
      , not used yet)

- button.cpp
  - add example command to 1x button press (comment out previous cmd
    temporarily)

- control.cpp
  - update changeMode function: dont do anything when current mode is
    already target mode
2022-08-11 09:30:07 +02:00
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
78f14ca499 Merge branch 'dev' 2022-08-10 08:50:20 +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_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
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
ca41213e22 Merge branch 'dev' 2022-07-24 10:15:49 +02:00
jonny_l480
d1dcf726aa Merge branch 'fade-down' into dev
New fade-down feature (aka deceleration limit) works reliably and as
expected.
Continuing on dev branch.
2022-07-23 17:19:54 +02:00
jonny_l480
0b113eafb5 Add functions to modify/toggle fading (button x8)
- add 3 functions to controlledMotor class in motorctl.cpp/hpp
  - setFade: set specific msFade duration for acceleration or
    deceleration
  - setFade: disable or set to default ramp for acceleration or
    deceleration
  - toggleFade: toggle between fading enabled or disables for
    acceleration or deceleration

- button.cpp
  - add controlledMotor objects to constructor
  - add new command 8x press which now toggles fade-deceleration of both
    motors

- config.cpp
  - slightly decrease fading durations
2022-07-23 15:13:09 +02:00
jonny_l480
bcbd2578f6 Fix bug: fade stuck at zero; Adjust fade durations
- Fix bug where case duty=0 was not handled in fading if structure thus no
incrementing action happened anymore (stuck at duty = 0)

- Set fade duration (acceleration, deceleration) to realistic value in
config
2022-07-23 11:14:57 +02:00
jonny_ji7
0a2695f45f Fix fading: correctly use different accel, decel ramps
- Change fading algorithm to handle Acceleration and Deceleration for
  forward and reverse separately (4 different cases)

- rename variables to make fading direction more obvious
  e.g. msFadeUp -> msFadeAccel  or  dutyIncrementDon -> dutyIncrementDecel

TODO: fading needs optimization
2022-07-18 17:32:31 +02:00
jonny_l480
1360832f5e Fix bug no fwd downfade; Add BRAKE; cleanup; [bug]
- Fix bug where downfade did not work when driving forward
- Add BRAKE command functionality to motorctl (untested, since not used anywhere atm)
- Cleanup: Optimize code, add comments

!!!TODO: there is a fault in the current concept/logic:
fading up/down generally works, however when accelerating
REVERSE fade-down is utilized instead of fade-up.
=> Fix that bug, fade down should only be used when decelerating.
2022-07-17 17:55:57 +02:00
jonny_ji7
cd804452e4 Change motorctl.handle from STATE to duty -100-100
For fading-down and delay-between-state-change to work correctly when switching between motorstates
(e.g. FWD -> REV) the handle function was changed.

using a duty value -100 for reverse 100% and +100 for forward 100%
allows are more mathematical approach

changes to motorctl.cpp:
  - convert state and duty to duty -100 to 100 when receiving target
    command at start
  - convert duty -100-100 back to state and duty at the end for applying
    motor commands
2022-07-17 15:23:42 +02:00
jonny_l480
436c528eaf Add fade-down functionality to motorctl (bug)
With this changes the motors are faded down (same as already existing fading up)
when the target duty suddenly decreases.
It can be configured or disabled with setting msFadeDown to 0  in config struct of
motorctl object.

- Add new config parameter msFadeDown
- Change msFade to msFadeDown

- Add fade down functionality to motorctl instead of just setting the
  duty to lower value

!!!TODO: fix major  BUG when motor direction changes suddenly (before fade got to
0) the motor immediately starts in other direction with previous duty
   (no/less fading up happening)
2022-07-16 12:46:56 +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
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
fd90ca0bb2 Merge branch 'origin/dev' 2022-06-25 13:00:08 +02:00
jonny_ji7
b811f77c8e Update App: Dark theme, remove radius and angle
Update react web app:
  - add dark background color
  - change joystick colors
  - increase joystick size by 50px
  - change heading
  - remove angle and radius
    - not displaying anymore
    - not sending to api anymore

Update http.cpp:
  - remove radius and angle from json parsing
  - limit radius to 1
2022-06-24 21:38:40 +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_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