MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.06k stars 403 forks source link

S-Curve for Steering instead of linear approach #196

Closed laubfrosch42 closed 2 years ago

laubfrosch42 commented 3 years ago

Hi, I am about starting to build a steering tiller for my FSLABS A320 based on this joystick-library. An s-curve would be a nice improvement versus a standard linear approch coming from the potentiometer. It would give more sensibility in the middle area where most of the steering action will take place.

Here is my proposal to convert the linear value (0 to 1023) into a smooth s-curve (0 to 1023): steering = analogRead(joySteering); steering = ((0.4*(2*steering/1023-1)+0.6*(2*steering/1023-1)^3)/(2/1023))+511.5; //convert into s-curve Joystick.setSteering(steering);

It might be mapped to 0/255 afterwards to make it smoother.

Ole

MHeironimus commented 2 years ago

This library does not focus on how to read values from input devices. It only focuses on making the Arduino appear to the host device as a game controller / joystick. It is up to the caller of this library to read and interpret (in this case convert) values read in from devices before sending them to the library.

Your suggestion on how to implement a smooth s-curve is a good reference for others on how to implement this in their sketch files. Thanks.