HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
687 stars 129 forks source link

Showing average value in gauge #185

Closed chocomo99 closed 4 years ago

chocomo99 commented 4 years ago

I'm restoring a 1976 GMC motorhome and thought it would be cool to build a digital gauge panel. Medusa gauges are the ticket. An Arduino Mega 2560 is used to convert the senders analog signals to digital for display using a Raspberry Pi 3B. Here's a link to a screenshot of the current version of the gauge panel. http://www.gmcmhphotos.com/photos/dashboard/p67033-current-gauge-setup.html It appears that the Arduino A/D's are noisy and causing unwanted needle jitter. The obvious solution is to display an average value to smooth out the noise. Medusa gauges can compute an average but if I use SetValue to display the average the data Queue is corrupted. Sort of a catch 22 situation. I have substantial C++ OOP experience but my Java/JFX/Eclipse experience is just a couple of months. My solution to the jitter problem is to create buffers in the view controller, compute the average and feed this result to SetValue. Here is an example:

double favg = 0;
int q[] = new int[10];
int wndw = 10;
int j = 0;

for (int i=0; i<100; i++) {
    if( j==wndw ) j = 0;
    favg += i - q[j];
    q[j++] = i;
    fuelavg.setValue(favg/wndw);    // show average value
}

While this solves the problem it adds complexity and overhead to the controller. So my question is it somehow possible to do this using the existing Medusa gauges or is another method (like SetAvgValue) needed?

JP

HanSolo commented 4 years ago

Hi there, first of all...nice project 👍🏻 The averaging in Medusa is used in another way and not for smoothing out values. In your case I would simply calculate a running average over the last 5-10 values before I send it to the Medusa gauges. Why not averaging the values directly on the Arduino before you send them out? That‘s what I would do, but there might be different ways. Cheers, Gerrit

chocomo99 commented 4 years ago

Thanks for the reply and thanks for creating and sharing the Medusa library. I pretty much stopped coding about 10 years ago (retired) so this has been a challenging but worthwhile and rewarding project. The "sparkline" gauge with graph and average display is handy for raw data visualization. I hadn't thought of pushing the average calculations upstream to the Arduino. However there are some idle CPU cycles and raw data can still be analyzed via the Arduino serial monitor. So I'll try that out and see how it works. JP