Plot real-time position of robot on computer

Hello!

I would like your advice for an Arduino project.
I am building a little robot that can move on the floor (either forward-backward in x direction, or laterally in y direction, but never turn).
It moves inside a rectangular floor, with walls on the sides.
The robot has 2 distance sensors around it (front, right), measuring the distance to 2 walls.

On my computer, I would like to plot the position of the robot in real time, on the screen of my computer (top view): one small rectangle (the robot) moving inside one big rectangle (the floor)
(Just 2 rectangles at the beginning of the project. After that, I'd like to add more complex objects in the plot, like wheels, bumpers, images, etc.)

But I have no idea how to get the measures immediately on the computer (in real-time) and use them to plot this.
I know Serial.print() , I use it quite often to check the sensor values. But I don't really know how to do "more" with those values.

I thought about something like:

  • send, at some frequency (like every 0.5 s, so 2 Hz), the 2 sensor measures to my computer
  • have them written in some file
  • write an independent Python program to plot read the file and plot the rectangles in real-time
    although I don't really know how to do it. And I don't know if it would be the most effective way to do it.

Can I ask you for some help on this, please? Would there be a "classical" way to do this? Some projects I could have a look on?

Thanks!

Maybe have the robot run a webserver that draws the graphics and access it from your PC with a web browser

No need for that. A program can read serial input and plot data, in real time.

1 Like

So this is not really an Arduino question - it's a PC question.

But, yes - this basically covers it:

  1. send the position data to the PC;
  2. plot that data on the PC.

That would be the "classicial" way to do it.

In Python, perhaps take a look at matplotlib:

https://matplotlib.org/

But I'm sure there are graphics frameworks/libraries available in any PC language you care to choose - search for "2D data plotting" or "2D data visualisation" or similar ...

Lots of ways to do that, mqtt to node-red running on your pc, as mentioned before have your
esp32 act a web server to send to to your pc (client web browser), serial to blue tooth on the
esp32 and blue-tooth to serial on the pc running a python program.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.