r/howdidtheycodeit • u/protomor • Jun 05 '22
How did they code racing game force feedback?
I'm trying to develop my own racing game and I just can't get my head around coding trail and how that force is to be applied.
19
Upvotes
11
u/reality_boy Jun 06 '22 edited Jun 06 '22
Finally a subject I can answer properly, since this is my actual job.
Force feedback wheels are usually built on top of the usb hid standard (but they don’t have to be) and on the computer (windows) side they use a driver to communicate with Microsoft’s direct input api. Most other operating systems replicate most of this api for there own use since the first commercial force feedback wheels were a collaboration between Microsoft and Immersion.
Direct input has a set of different effects you can play on the wheel, including spring and damper effects, constant force effects, and compound effects built up from sine waves and envelopes. Most of these effects were designed at a time when game physics was simple.
Most modern games just use the constant force effect. This allows you to command the force feedback motor to push the wheel left or right with a certain percent of the wheels peak force. This can be updated as fast as 1000 times a second, but typically it is updated 50-250 times a second.
In the sim the physics sums up the forces pushing the tires around and transmits them up the steering column. That force is directly sent to the wheel at whatever update rate you use from above. These forces are typically massaged a bit to scale them down and clean things up a bit.
From there the motor in the wheel tries to replicate the force requested by turning on its motors. Typically you would have some sort of current loop that can control the force more precisely than just driving a voltage to the motor. The goal is to make the force output very linear and predictable and not have it change over time or when the motors heat up.
If you have a direct drive wheel you have to further massage the signal to cover up the cogging caused by the armature passing by the stators in the motor resulting in a ripple in the torque. In this case you use a position sensor to map out the poles and then vary the torque based on position to counteract any resistance.
Wheels also run there own filters to smooth out the low frequency forces from the sim. As well as applying static dampers and other effects to give the wheel weight.
All of that is just the force feedback side. There is another side where the wheels position is read out and feed back to the sim to provide input to the sim. This feedback loop is inherently unstable, and fighting this instability is a big part of the job. Reducing latency is also important.
The most important part is the physics itself. Force feedback is really boring without this. The better the physics the better the ffb feel.
This whole thing is a subset of haptics, the study of using motors and sensors to trick your body into feeling virtual worlds. In this case it is a single axis haptic device, similar to a haptic paddle. Haptics also covers bass shakers, motion platforms, pager motors, and even wind simulators (and 6 axis research devices)
1
u/Last-Entrance2915 Aug 11 '24
How's it going with the project
1
u/New_Plantain_942 Aug 11 '24
I also want to know/test about this project. 👍
1
u/Adorable_Drop_3474 Sep 15 '24
How can I start to make an program to be use as the Logitech g hub but in linux? I what to be able to use my Logitech pro wheel on racing games. Now with the steam deck it works but the wheel feels ligth ( WRC Generations ) and on American truck simulator after I turn the wheel it feels to much and I can't make a 360 wheel turn. I also have other peripheral like handbrakes and sequential shifter that are not recognized.
1
u/qoning Jun 06 '22
Im not sure what you mean. Do you mean using wheel or joystick hardware? If so, then that hardware is likely to have drivers which handle the application of those effects for you. As to when to apply it, there's a bunch of heuristics that feel good, like angular velocity or bumpiness of material.