I have seen no pre-packaged way to do what you ask for.
I would think twice before implementing this in a gazebo-specific way. The problem is that it will work only in simulation (and will not work when running a real robot.) I'd look for a solution that works for both cases.
Probably the simplest programming approach for someone new to ros would be to create a python ros node which opens a graphical image window using the opencv API. The idea is to treat this window as a 2D grid. Load your map into the window, scaling it if necessary. Subscribe to your robot's pose topic. For each pose message you receive, color the corresponding grid x,y in the window.
There is a conceptually similar approach that would use rviz for the display by creating a custom layer for the global costmap, but this requires using c++, and the API's have a steeper learning curve than opencv has. This approach is not for beginners.
Originally posted by Mike Scheutzow with karma: 4903 on 2023-01-21
This answer was NOT ACCEPTED on the original site
Post score: 2
Original comments
Comment by Fizpok on 2023-01-23:
I am new to ROS (actually, ROS2), but not to C++: I can program OpenCV. So, could you please explain, what should I do with the image after it is created in OpenCV? I need to put it on top of a map somehow, right?
Also, I am not sure the approach is optimal. Let me suggest two use cases. It needs to work both for simulated robot and for a real robot that is reflected in a simulation (this is part I haven't touched yet).
- A robotic vacuum cleaner cleans the floor, and I want clean floor to be marked with a color. It is similar to occupancy grid, so i thought about mimicking what is done in RViz... except, it would be nice to have it in Gazebo.
- A car drives in a simulated city. As it approaches a cyclist, arrows of possible directions of this object are displayed, and as new data arrives (and as we move), length and colors of arrows change... It all can be very dynamic.
In Gazebo (and probably, in RViz), the world might have 3rd dimension, so flat image might not be the best...
Comment by Mike Scheutzow on 2023-01-23:
The simple thing to do is create 1 image, then draw ON that image. The opencv API provides functions for drawing rectangles.
Comment by Fizpok on 2023-01-23:
I understand. My question is, how can I use the image after I painted on it? Like, should I open it in RViz as, say, a layer on top of a map? If yes, how do I do it?
Thanks.