Multiple values with same time stamp in time plot

Support forum for MegunoLink
Post Reply
TuigWerk
Posts: 5
Joined: Wed Feb 17, 2021 5:11 pm

Thu Feb 18, 2021 9:28 am

Hi there,

I have been looking for the cause of this issue for a couple of hours now and I can't figure out how to improve the smoothness of my time plot in Megunolink. I hope someone can help me with this..
As you can see in the attached screenshots, the time plot of Megunolink is stepped, whereas the Arduino serial plotter shown a smooth signal. This is done with the same sketch and sensors.
The weird thing is that this jaggedness of the Megunolink does not seem constant. Sometimes its worse, sometimes better.

Does anyone know what the issue could be?

Cheers, Tjeerd
Attachments
Megunolink time plot.jpg
Megunolink time plot.jpg (90.17 KiB) Viewed 10772 times
Arduino serial plotter.jpg
Arduino serial plotter.jpg (77.34 KiB) Viewed 10772 times
Last edited by TuigWerk on Fri Feb 19, 2021 4:22 pm, edited 1 time in total.
TuigWerk
Posts: 5
Joined: Wed Feb 17, 2021 5:11 pm

Fri Feb 19, 2021 1:09 pm

The problem seems that the time plot displays multiple values with the same timestamp, then about 15 ms later does the same thing, but I still don't know why.
I stripped down my code, and tried adding a delay, but it still gives me the same issue and it seems that the resolution of the time axis is not sufficient.
Hopefully it is just a setting that I have overlooked. I hope someone can help, because it is really annoying small, but critical issue.

Best Regards, Tjeerd

Code: Select all

 const int xpin1 = A0; // x-axis of the accelerometer 1

#include "MegunoLink.h"
#include "CommandHandler.h"

TimePlot Acc1 ("Acc1");

CommandHandler<> Commands;
InterfacePanel AccPanel;


void setup() {

  Serial.begin(115200);

}


void loop() {
  Commands.Process();
  int x1raw = analogRead(xpin1);

  float x1g = map(x1raw, 410, 613, -100, 100) * 0.01; //Mapping with raw values

  Acc1.SendData(F("Acc1"), x1g);

}

Attachments
Megunolink time plot 2.jpg
Megunolink time plot 2.jpg (70.18 KiB) Viewed 10768 times
philr
Posts: 371
Joined: Mon May 26, 2014 10:58 am

Fri Feb 26, 2021 6:02 am

The issue is one of processing jitter. Windows computers are typically allocates slices in time to process data. Because you are sending data at full speed multiple messages are arriving at the computer and are being processed in quick succession. Because the timestamp is being generated in the computer this leads to jagged plots. 

If you switch to generating your own timestamp (easiest is using the xyplot and millisecond counter rather than having to keep time) your plot should be nice and smooth. How fast do you need data? You could adjust it to send data every 50ms or so which will probably solve your problem as well.

Here is one method for syncing time to your device if you still need absolute time.
https://www.megunolink.com/documentatio ... egunolink/
TuigWerk
Posts: 5
Joined: Wed Feb 17, 2021 5:11 pm

Sun Mar 07, 2021 11:43 am

Hi Phil,

thanks a lot for your suggestion!
Using a XY plot not only solved the jagged display caused by using the pc time, but also made it possible to display the standing sine wave by using a trigger to reset the time.
I have posted my solution in this thread: https://megunolink.com/discussion/viewt ... f=5&t=1516.

Cheers, Tjeerd
philr
Posts: 371
Joined: Mon May 26, 2014 10:58 am

Thu Mar 11, 2021 6:13 am

Nice, great work!
Post Reply