15 Commits

Author SHA1 Message Date
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
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
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
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
ad2dbb0ce0 Create class controlledFan, Add getStatus to motorctl
- Add class for controlling fans for cooling the motor drivers
- Add configuration for left and right fan to config.cpp
- Create fan task in main.cpp
- Add getStatus function to controlledMotor class
2022-06-11 16:47:13 +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
06451b47d0 Add 'buzzer.hpp, buzzer.cpp' Add instance 'button'
- Copy buzzer function from gate project
  this makes it possible to easily trigger and queue up buzzing events
  without having to worry about delaying the program
- Add instance buzzer to config
- Add code for testing the buzzer to main.cpp
2022-06-10 08:40:46 +02:00
jonny_ji7
fb90169fa4 Add evaluatedSwitch component, Add buttonJoystick
Copy gpio component from gate project
Add instance of evaluatedswitch for button next to joystick to config
Add code for testing the button to main.cpp
2022-06-10 08:30:07 +02:00
jonny_ji7
4109c6f239 Add 'motorRight' instance and configuration 2022-06-09 12:05:27 +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
jonny_ji7
84bfe211ac Create class 'controlledMotor', Create config
- Create class 'controlledMotor':
  - handles 'fading / ramp' of the pwm duty
  - handles current limit **not implemented yet**
  - has .handle function that is intended to be run very fast in another task
    commands are sent via queue

- Create config.hpp
  - Globally available instance motorLeft of controlledMotor class
- Create config.cpp
  - Configuration of motordriver and control parameters for motorLeft

- Add config.cpp and motorctl.cpp to cmakelists

- main.cpp:
  - create 'task_motorctl' which repeatedly runs motorLeft.handle()
  - modify testing code for testing the new class
  - comments

The fading/ramp capability of the new class was tested successfully
using a breakoutboard with an led.
2022-06-05 16:36:57 +02:00