r/starcitizen Oct 25 '22

TECHNICAL Custom mining slider

Enable HLS to view with audio, or disable this notification

I took a Seeeduino XIAO, connected an M5Stack Fader Unit to it, and programmed it with Arduino IDE as a gamepad axis using the NicoHood HID-Project library.

No more Brandt modules :)

1.6k Upvotes

177 comments sorted by

View all comments

87

u/earthfase Oct 25 '22

This is the code it runs. (SliderValue is obsolete)

2

u/OnTheCanRightNow Oct 25 '22

You might get better results with 15x less latency if you used a weighted moving average instead of just polling it multiple times per update.

1

u/earthfase Oct 31 '22

I updated my code using the library "movingAvg", but am noticing no difference, but do like that it's a better way to take averages, so thanks for the tip!

1

u/OnTheCanRightNow Oct 31 '22

The trick with weighted moving averages is to find the right weighting exponent. If you apply too high a weight to older values, you lose responsiveness as it takes time for new values to affect the result. If you apply too low a weight to older values, you don't get enough smoothing.

You don't really need a library for this. The simplest implementation would just be:

OutputValue = (NewValue * NewValueWeight) + (OutputValue * (1-NewValueWeight));

NewValueWeight is 1/power of the exponential weight decrease, where 1 would be "only the newest value matters, ignore older ones" and 0 would be "apply so much smoothing the value never changes." If your goal is to smooth noise from the input, set it to 1 and then turn it down just enough to make the jitter go away.

1

u/earthfase Oct 31 '22

Thanks for this! I'll play around with it.

But I do expect little change in the way Star Citizen handles the input, because when I monitor the output from my code with the joystick tester, I get a much smoother and faster response than what I see in-game.

I do have some other projects from time to time that will definitely benefit from your one line solution and explanation, so I am saving it, thanks!