Improving the loadcell reading - ChrGri/DIY-Sim-Racing-FFB-Pedal GitHub Wiki

Intro

The ESP reads the loadcell each cycle, controlling the pedal position based on the adjusted force–travel curve. Any noise in the loadcell reading will cause unwanted micro-vibrations in the movement, e.g., a grainy pedal feel or a shaking pedal. Digital filtering reduces noise but introduces latency, which may cause closed-loop instability and pedal oscillations. A good loadcell reading thus becomes a crucial goal when aiming to achieve a nicely behaving pedal.

Let's start with a bad-quality loadcell reading plot like this image.

This log was taken from the pedal and shows the unfiltered loadcell signal (blue curve), the filtered loadcell reading (red curve), and the servo current (green curve). Until just before 30s, the pedal was left untouched. One can see large spikes in the blue signal, which should not be there. The filtered signal was able to reduce the spikes amplitudes mostly but fluctuated quite a bit, approximately about 200g of force/weight.

All the subsequent tests were done with V5 PCB.

Stable 5V signal

The external Analog to an analog-to-digital converter (ADC) converts the analog loadcell reading into an ESP-readable digital signal. The utilized ADS1256 does not measure the loadcell in a ratiometric fashion, which makes a noise-free 5V signal crucial for low-noise loadcell readings. Here is some advice for achieving a clean 5V signal.

Use a good quality USB cable

A significant portion of the provided USB voltage (up to 0.75V according to USB C standard) can be eaten up by the internal resistance of the USB cable. It is recommended to use a good-quality USB cable. Please refer to the video from GreatScott for more information.

I only tested a regular 1.2m long USB-C cable and a 0.2m long regular USB-C cable. The 5V signal was probed with an oscilloscope. The measurements are depicted below. The line is the channel of interest.

cable variant measurements plots identified values
1.2m regular cable approx. 4.73 Vrms and 65mVpp
0.2m regular cable approx. 4.74 Vrms and 67mVpp

The Vrms and Vpp values looked very close, indicating no significant difference by the used USB cable in my setup.

Use an active USB hub

Use a good-quality active USB for the pedals. Measurements have shown that using an active USB hub can (a) increase the voltage received by the ESP (4.4V vs 4.7V) and (b) reduce the 5V bus fluctuation. To verify that the 5V signal received by the ESP was probed via oscilloscope and can be seen below ThrottlePowerTransisiton_withText

The USB hub used in the measurements can be found here Amazon (affiliate) or Aliexpress (affiliate).

The usage of the active USB hub greatly increased the voltage received by the ESP and by that alone increased the excitation voltage of the loadcell.

Loadcell selection

Let's see what influence the loadcell selection has on the force readings. I had three different loadcell variants available

  1. YZC-516C loadcell design, referenced in the baseline design in 100kg rating
  2. YZC-516C loadcell design, referenced in the baseline design in 300kg rating
  3. A smaller and more expensive DYLY-107, also referenced in the baseline repo, in 200kg rating.

All loadcells were calibrated to their nominal rating in the Simhub plugin. During testing, the loadcells were left untouched and a trace was taken for approximately 10s. After that, a histogram of the loadcell reading is plotted and the empirical standard deviation is calculated from which we can gain knowledge about the signal fluctuation.

The following plots show the loadcell readings over time/sample in the left subplots. The right subplots show the histogram of the same data and thus give a good picture of the noise distribution.

info YZC-516C DYLY-107
Design
100kg variant measurments not available
200kg variant measurments not available
300kg variant measurments not available

Observations

The DYLY-107 (200kg) reading shows a standard deviation of approx. 13g, whilst the YZC-516C loadcell (100kg) shows a standard deviation of roughly 8g for the 100kg rating variant and 20g for the 300kg variant. All histograms show normal distributed behavior.

Conclusion

The measured weight noise scales with the loadcell rating (compare cheap 100kg vs. 300kg loadcell traces), which is no surprise. Thus, to reduce force/weight measurement fluctuations, it's best to select a loadcell with a lower weight rating. Applying weight above the rating might introduce non-linear behavior (uncritical for pedal application) or in the worst case damage the loadcell.

Due to the limited number of loadcells, I couldn't judge whether DYLY-107 has a better noise figure than the YZC-516C loadcells. If we'd interpolate a YZC-516C 200kg loadcells standard deviation from the 100kg and 300kg variants, that'd be (8g+20g) / 2 = 14g. That'd be 1g worse than what was estimated for the 200kg DYLY-107 variant. It's up to the user to decide whether this increase would be noticeable.

Firmware optimization

Sample rejection

Remaining voltage spikes can lead to sudden loadcell reading changes, beyond reasonable values. The pedal software contains a simple outlier detection and rejection which greatly helps suppress these sudden loadcell spikes. The code is depicted below: image

With the introduction of this outlier detection, the spikes from the uppermost image were easily detected during runtime and improved the pedal response by a lot. The change has been integrated into the official software an requires no user action.

Kalman filter setting

For additional digital smoothing of the loadcell reading, a Kalman filter was implemented. It contains dynamic a model to describe the loadcell response. It does not only allow smoothing of the loadcell signal but also estimates hidden states, like force-velocity and acceleration, which in turn are used in the damping effect module.

The filter speed can be tuned via the Simhub plugin, see the screenshot below image.

A fast filter response is desirable to reduce latency and therefore reduce closed-loop oscillations. A slow filter setting is desired for good smoothing behavior. Finding a reasonable value is thus a tradeoff and needs to be adjusted by the user.

Disable Wifi module

Activation of the wifi module on the ESP can cause dynamic load on the 5V signal, significantly influencing the loadcell reading. An example pedal force log can be seen below image. The blue curve is the unfiltered loadcell reading, and the red curve is the filtered loadcell reading. One can see spikes in the filtered loadcell reading all over the trace. Due to the limited bandwidth of the serial line, roughly only every 3rd cycle is logged. Thus, some of the spikes in the unfiltered loadcell reading are missing in the plot.

Probing the 5V signal with an oscilloscope, shows large 5V signal fluctuations of about 190mVpp, see below image

As a workaround, firmware with disabled ESPnow can now be found in the releases. Unfortunately, this disables the rudder or wireless functionality. We are looking to improve the wireless-induced fluctuations though.

Proof of concept

After applying the aforementioned recommendations, it's time to test the performance. Previously, it was challenging to achieve a smooth pedal response for a very soft throttle pedal. Let's change the pedal force to the lowest possible values, a minimum and maximum pedal force (weight) of 0kg and 3kg, see below image.

Exporting the pedal state logs indicates only small loadcell fluctuations and the pedal feels very smooth, even at fast filter settings. The responsiveness of the pedal is great and it's barely possible to make it oscillate, even when applying pressure by hand.

image

Compared to the uppermost image, the loadcell reading is much nicer and so is the pedal feeling. Less grain and increased closed-loop stability, since better loadcell reading allowed to increase in the digital filter dynamic.

Further hardware optimizations

Ratiometric measurement

Ratiometric measurement is beneficial when the excitation voltage of the loadcell is noisy. By referencing the ADC's measurements to the same supply or reference voltage that powers the loadcell, any fluctuations or noise present on that supply affect both the input signal and the reference equally. As a result, the ratio remains stable, improving measurement accuracy and stability, especially in environments with noisy or unstable power.

On V5 PCB, the loadcell excitation comes from the ESPs 5V bus. By soldering the loadcells excitation to the ADSs devboards reference voltage source (outport of the OPA350), as shown in the picture below, ratiometric measurement can be achieved. Connecting the loadcell in between the operation amplifier and R2 reduces current flow through R2, which would cause an unwanted voltage drop of the reference voltage for the ADS1256 chip.

In practice it looks like this: .

Measurments

During testing, I found that my two ADS1256 dev boards seemed to be of different quality, as their load cell reading quality significantly differed. I have included measurements for both ADS boards below. For testing, I left the loadcell/pedal untouched while collecting pedal logs of roughly 1kB filesize. The trace log was repeated 5 times for each configuration for statistical reasons. To handle the excitation voltage change, the nominal loadcell rating setting in the Simhub plugin was adjusted from 200kg to 400kg, when using 2.5V to excite the loadcell.

Sample good ADS 5V excitation good ADS 2.5V excitation bad ADS 5V excitation bad ADS 2.5V excitation
1
2
3
4
5

Observations

For the good ADS1256, the standard deviation for 5V excitation typically was around 10-11g. For 2.5V it was around 20g.

For the bad ADS1256, the standard deviation for 5V excitation typically was around 62g, and in the last measurement >90g. For the 2.5V excitation, it was typically around 20g.

Also, the force reading from the 5V bad ADS plots shows some slower process fluctuations, making the reading fluctate between 0kg and 0.7kg, whereas all other measurements typically fluctuate between 0kg and 0.1kg.

Conclusion

For the bad ADS1256, switching from 5V excitation to 2.5V doubled the identified standard deviation, which is as expected. The bad ADS1256 had strong fluctuating measurements at 5V, resulting in a standard deviation >4 times larger compared to the good ADS. After switching to a 2.5V reference voltage source, the standard deviation decreased to 20g. The results follow the theory and thus prove a more consistent measurement when using a ratiometric measurement setup.

ADS1220

Available ADS1220 dev boards have the advantage, that they expose the reference signal. This allows easy integration of ratiometric measurement setups. With the DYLY-107 200kg loadcell following noise figure was observed : newplot (3)

It looks to be on par with the ADS1256.

ADS1256, buffer vs. no buffer

image

no buffer: newplot (2) with buffer: newplot (4)

Connecting the loadcell shield

To check the influence of connecting the loadcell shield to ground, additional tests were done. Results to follow.

Research

Despite the good results, reducing the loadcell noise even further is under development. Current research to improve the loadcell readings even further is documented here.