Graphing libraries for real-time data?

22 views
Skip to first unread message

Mark Womack

unread,
Mar 23, 2023, 7:37:48 PM3/23/23
to hbrob...@googlegroups.com
I have been heavy into modifying the popular Arduino PID library to allow it to provide detailed instrumentation/telemetry/transparency into what it is calculating in each call to the compute() method (it is at https://github.com/markwomack/InstrumentedPIDLibrary). I started with Brett Beauregard's code, cleaned it up a lot, cleaned it up some more, and then added the instrumentation. I'm at the point where I am ready to implement the 'transmission' part with a method that will return a MsgPack'd JSON blob.

Once I have that done, I want to graph the data. I'm going to be grabbing the blob each time compute actually does something, like every 50 milliseconds. So, I'd like to be able to have a graph that is updating and scrolling in real time with the data. Some kind of dashboard that I can put together to better understand what the hell the PID is calculating.

Does anyone know of a library/tool I could use to do this? I'd be fine with Linux, but open to Windows or Chromebook as well. I saw a great video (from 7 years ago...) where this guy has a detailed set of graphs showing how much each of the PID elements are contributing to the value. I want something like that. I think I have the data, I just need a graph...

-Mark

Michael Wimble

unread,
Mar 23, 2023, 8:07:20 PM3/23/23
to hbrob...@googlegroups.com
I’ve been writing some data visualizers in Python using mathplotlib and tkinter. If you have a pointer to my raven GitHub at wimblerobitics look in raven/raven_base/scripts/monitor.py. The code is also described in my WimbleRobotics blog in the post “Visualizing the noise in proximity sensors “. I think a previous group email points to this.  There are a fair number of YouTube videos on mathplotlib and tkinter. Ask questions if you need help if you go that route. 

On Mar 23, 2023, at 4:37 PM, Mark Womack <mwo...@gmail.com> wrote:



Mark Womack

unread,
Mar 23, 2023, 8:15:12 PM3/23/23
to hbrob...@googlegroups.com
Thanks, Michael, I will take a look!

Also following some links from that original video, it turns out the graphs are a home grown tool (in Java) that he created and explains usage of in another video. It is six years old as well, but it seems simple and flexible.

-Mark

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/0C45F242-FC8D-4525-A175-9B4149F611D4%40gmail.com.

Dan

unread,
Mar 23, 2023, 8:18:55 PM3/23/23
to hbrob...@googlegroups.com
Hey Mark,
I take on a lot of different contracts writing uC code. Ultimately I need some telemetry to see what is going on.  My belief is to use the easiest tool for the job.  In my case I use the free version of Visual Studio for Windows. Controls and graphs are easy. I have snippets of code if you get stuck. I run the telemetry over serial at 1.5 Mbs.
I use C++ but you can use C# or Visual Basic as it is all .Net.
Let me know if you go this route and need some support.

Daniel Albert

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.

Mark Womack

unread,
Mar 23, 2023, 11:22:15 PM3/23/23
to hbrob...@googlegroups.com
Thanks, Dan! I feel like this should be a meeting topic or something. Everyone could present and demo their tools/methods!

Mark

Mark Womack

unread,
Mar 23, 2023, 11:26:36 PM3/23/23
to hbrob...@googlegroups.com
Digging more into TelemetryViewer, there is a much more recent version that supports both UART and UDP and I think a binary format. Anyways, the latest video is here:


And the latest code is on his website (not the github afaict). See the description of the YT video for a link. I think I can get this up and running tomorrow.

Mark

Chris Albertson

unread,
Mar 24, 2023, 12:22:02 AM3/24/23
to hbrob...@googlegroups.com
There is one that "everyone" uses, matplotlib.  It is really easy to use and does just about everything.  It does 2D and 3D plots and python runs equally well on Linux, Mac or Windows.   https://matplotlib.org/stable/tutorials/index.html

matplotlib is likey the most commonly used library for plotting today.    You can do animations too.   It is versatile enough to do 3D drawing of my robo-dog so I can see if the software is getting the leg angles right and it can do pie charts and anything else.     Can also make interactive plots where a user can move a cursor and get data readouts.

I last used it for my servo calibrator to visualize the micro-seconds to angle function for a given servo.






--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.


--

Chris Albertson
Redondo Beach, California

Yousof

unread,
Mar 24, 2023, 12:46:36 AM3/24/23
to HomeBrew Robotics Club
I used bokeh for live plotting in python. I like the hovering feature of it and also it is more interactive than matplotlib. Here is one example I used it for:

https://youtu.be/ve7QrjSRdCs

If you don't use the jupyter notebook. The plots will be available through a browser. 

I used plotly before as well. That one is also cool. 

This video is listing different libraries for visualization in python: https://youtu.be/4O_o53ag3ag

Yousof

unread,
Mar 24, 2023, 3:21:39 AM3/24/23
to HomeBrew Robotics Club
How do you send the data to visualize out of the Arduino?

Mark Womack

unread,
Mar 24, 2023, 7:11:27 AM3/24/23
to hbrob...@googlegroups.com

Mark Womack

unread,
Mar 24, 2023, 7:29:21 AM3/24/23
to hbrob...@googlegroups.com
Yousof, thanks for those pointers. I'll take a look. 

As far as exporting data out of the Arduino, I was thinking of using AduinoJson in the MsgPack format. That is a compact binary format. Just a simple array of keys and values. Maybe just the values if the order is maintained. But it would mean that the receiver would need to process MsgPack format or I would need an intermediate process that handled that and output the format used by the graphing software. In realtime. The TelemetryViewer I got excited about just takes comma separated values, though there does seem to be a custom binary format it can use. You just have to know the order of the values.

The communication mechanism is going to need to be UDP or some related ether protocol. I can't chase the robot around with a laptop connected by USB. I have the Adafruit AirLift breakout which works great with the WiFiNINA library for opening and accessing ports. I've used it in the past to broadcast debug messages via UDP. Though any microcontroller with wifi should work as long as I can connect it to my controller to get the output stream. I'll have everything connected to my wifi for now, but eventually I'll need to have the robot on it's own hub as it wanders too far from the house. It's an ongoing adventure. :-)

Mark

Yousof

unread,
Mar 24, 2023, 5:53:43 PM3/24/23
to HomeBrew Robotics Club
If you have JSON format, you might be able to use Foxglove as well. I haven't used them, so I don't know how much pain is to set it up but they are getting popular.
I have seen people from the company in the bay area meetups.

Joep Suijs

unread,
Mar 25, 2023, 4:55:40 AM3/25/23
to hbrob...@googlegroups.com
Hi Mark,

Nice thread, as a serial robot builder, I've been revisiting this topic quite often.

My robots are micro-controller-based and use bluetooth serial to communicate, for commands, free-format logging and structured data. 
The structured data is embedded in the datastream, encapsulated in SLIP packages (basically start/end flag, since all other data is 7 bit ascii). Each packet contains space separated data and the first field indicates the dataset. For example, this indicates the position (or actually, the pose) of the robot with X, Y in mm and heading in Rad).
ÁPOSITION 219 626 0.246952À
The requirement to mix structured with unstructured data emerged from necessity, since there was only a single channel and that was already used for unstructured data like commands and logging. But it proved quite valuable since the single datastream preserves the chain of events. When there is an odd spike in a graph, you can go back to the raw data to see what happened.

My first attempt at presenting structured data was to build a combined presentation/terminal app, a primitive variant of the 'dashboards' shown, but that turned out to be inflexible for me.

Currently I use a modular approach, with programs in Python, with tkinter and Matplotlib, for each window. So I have a terminal program, one to plot up to 4 graphs, a polar graph plotter and an x/y view of the track.

An issue to be solved was how to link the serial port to these programs. I tried Mqtt (Mosquito) but couldn't get it to work fast enough, resulting in a substantial backlog of messages and thus delay. I've switched from Mqtt to UPD and that works well (on a single machine at least).
So I have a 'client' program on my PC to get all data from the serial port and send it to UDP and to get data from another UDP-port and send that to serial. (See drawing below and note the broker pictured has been replaced by UDP).

This might be overly complicated if you target one robot and a limited number of datasets. But the use of a single channel for both structured and unstructured data proved useful.
If you're interested, I'm happy to put my code on github.

Joep


image.png






Op vr 24 mrt 2023 om 22:53 schreef Yousof <youe...@gmail.com>:

Stephen Williams

unread,
Mar 26, 2023, 12:54:19 PM3/26/23
to hbrob...@googlegroups.com

Hi Joep,

This seems like a great approach, especially for minimal microcontrollers.

It also reminds me of the days of SLIP, PPP, Kermit, etc.

I'd love to see & use this code.

Thanks,
Stephen

Joep Suijs

unread,
Mar 26, 2023, 1:48:47 PM3/26/23
to hbrob...@googlegroups.com
Hi Stephen,

I've put the code on github: https://github.com/jsuijs/RlConsole

The folder batchfiles contains both the configuration-files and batch files to start the scripts. Should work when paths are set appropriately. I'd suggest you start with Bridge and Terminal.

Frames from the robot are basically readable text with space separated fields, starting with 0xC0 and terminated with 0xC1. 

Regards,
Joep



Op zo 26 mrt 2023 om 18:54 schreef 'Stephen Williams' via HomeBrew Robotics Club <hbrob...@googlegroups.com>:

Mark Womack

unread,
Mar 30, 2023, 4:51:26 PM3/30/23
to hbrob...@googlegroups.com
Sorry I haven't replied to the latest posts in this thread. Thank you for the pointers and advice. I really think that some sort of presentation on the subject at one of the upcoming meetings would be awesome.

The problem I am having right now is much more basic, just trying to get the data out of my setup. I have successfully used the Adafruit AirLift breakout board (it's a good deal and add-on at 14.95) to export debug messages via UDP ports. But that was with a Teensy 3.5, and now that I am using Teensy 4.0/4.1 I find that the AirLift will not work well. It can sometimes make the connection and send data for about 30s. Then it reboots and then gets into a state where it just reboots over and over. I've swapped Teensys and AirLifts, but the problem still happens. Works great with the 3.5 though! I've been trying to figure out the problem with help in the Teensy and Adafruit forums, but no luck yet. So, I'm stuck at an impasse for now.

-Mark

Chris Albertson

unread,
Mar 31, 2023, 1:43:27 AM3/31/23
to hbrob...@googlegroups.com
Most people just use "print" statements and the data does over USB via a virtual serial port.    The bandwidth is not too bad. 

Another faster debug technique is to toggle a free pin or two.   You have to invent some kind of code and then you look at it with a logic analyzer.     I'd say the logic analyzer is my go-to tool for  low level debugging.   I can record up to 8 pins in real time.

There are many people selling the "logic 8" on eBay and aliexpress for prices between $16 and $6.  They are all the same.   These are near exact clones of the Saleae logic 8 and use the same Saleae software which is excellent.

Usually I can figure out what's up by looking at the raw waveform but you can also dump the raw data to a CSV file and import to a spreadsheet or read it with python.

I'm doing about the same work, 3-phase motor drivers and nested PID loops.

The other thing these cheap analysers can do is decode DATA.  So you send debut via I2C (or serial or SPI or whatever) out one pin and the Logic-8 prints this above the waveforms. so you see internal stats and pin values in real time.

here is one random ebay seller





Mark Womack

unread,
Mar 31, 2023, 10:33:29 PM3/31/23
to hbrob...@googlegroups.com
My goal is to send telemetry from the robot (RoboMagellan) as it is moving in its environment, so a USB cable isn't really going to help. I was planning to send the motor controller telemetry using a serial connection, yes, but then that data needs to be transmitted 'off' the robot. So, I was going to have a second microcontroller (or maybe someday the main RPi) with the AirLift transmitting the data via UDP as it received it. But like I said, I can't get the AirLift to work as expected. But that is the plan. Then I can start looking at the francy graphs. First things first. If I can't figure out the AirLift issue, then I am going to switch to a Pico W, just to get the ball rolling. There's just going to be a learning curve with that.

-Mark

Mark Womack

unread,
Apr 1, 2023, 1:18:48 PM4/1/23
to hbrob...@googlegroups.com
OK. I solved my issue with the AirLift. For some reason they shipped it to me with v1.2.2 of the firmware, which is really, really old. I don't know why they would not use a newer version.

But regardless, for those following along, I updated the AirLift to v1.7.4 firmware and now it works great with the Teensy 4.0. Performing the upgrade took some investigation. Please see this post in the Adafruit forum for more details.

I'm going to start more investigation into the various tools/techniques folks mentioned next week.

-Mark

Joep Suijs

unread,
Apr 1, 2023, 1:31:31 PM4/1/23
to hbrob...@googlegroups.com
>  then I am going to switch to a Pico W, just to get the ball rolling. There's just going to be a learning curve with that.
I'm on that curve right now. Aim is to have a reliable and fast serial link. First prototype was esp32-based and worked okay at 115k2, but dropped data from 300k up. Pushed that up to about 450kbps, and even further when switching to the Pico. Looks like the Pico prototype hits the 921k6 sustainable transfer rate target without data loss, but this needs to be converted to production-grade code which detects data overflows, does reconnects etc...
Not on top of my priority list right now, but happy to share when someone wants to work on this or when it's done.

Joep


Op za 1 apr 2023 om 04:33 schreef Mark Womack <mwo...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages