YukMingLaw / ArduinoJoystickWithFFBLibrary

An Arduino Joystick Library With Force Feedback Feature
GNU Lesser General Public License v3.0
208 stars 55 forks source link

Condition Effects Fix #24

Closed jonlidgard closed 2 years ago

jonlidgard commented 3 years ago

There is a problem in the effects calculator. It doesn't correctly implement the PID specification:

If the number of Condition report blocks is equal to the number of axes for the effect, then the first report block applies to the first axis, the second applies to the second axis, and so on. For example, a two-axis spring condition with CP Offset set to zero in both Condition report blocks would have the same effect as the joystick self-centering spring. When a condition is defined for each axis in this way, the effect must not be rotated.

If there is a single Condition report block for an effect with more than one axis, then the direction along which the parameters of the Condition report block are in effect is determined by the direction parameters passed in the Direction field of the Effect report block. For example, a friction condition rotated 45 degrees (in polar coordinates) would resist joystick motion in the northeast-southwest direction but would have no effect on joystick motion in the northwest-southeast direction.

The spring effect is being sent with the DIRECTION_ENABLE flag set (not individual axis enable bits) but with 2 parameter blocks (X & Y). The code is seeing DIRECTION_ENABLE & setting condition var to zero so it's only applying the first parameter block, regardless of the axis i.e. the Y axis is using the X axis parameter block. The code needs to count the number of parameter blocks set (as the effect get's built from the HID reports) & if more than one block, apply the relevant parameter block to each axis. If there is only one parameter block, then the effect needs to be scaled by the angle_ratio. (paragraph 2) I had the same problem developing multi-axis code for OpenFFBoard &, after studying the HID reports using USBlyzer & the output from FEdit.exe, this is the fix. Now in XPlane, when I trim the cpOffset moves the pitch (Y) axis correctly. Luckily, it's an easy fix.

On branch conditionEffect Changes to be committed: modified: src/DynamicHID/PIDReportHandler.cpp modified: src/DynamicHID/PIDReportType.h modified: src/Joystick.cpp

yuvalsegev commented 3 years ago

Brilliant work! You saved the day for me

YukMingLaw commented 3 years ago

Hi, Thank you for your correction! I will test it as soon as possible.

YukMingLaw commented 2 years ago

I have already tested it,works!Thank you for your pull request!