What you want to achieve could be tricky. From my understanding of the pakage find_object
(and correct me if I'm wrong, it's a key point), you will be able to get the position of some objects, it will be only one poisition but not the edges of this object. That means that you would know in the occupancy grid the area where you need to change the cells data, but not the exact pose of each cells.
With that in mind, you will have to find the edges of an object given its position.
First, you will need to get the occupancy grid from gmapping. To create your new map I would use two occupancy grid : one occupancy grid will be your objects free map, I'll call it cleared_map
,and the other one would be used to create the previous one, I'll call it history_map
.
Why two occupancy grids ?
The idea is to use the data from gmapping to create a new map. The data from the topic map
is an array containing the value of each cells of your map. With gmapping
the cells have three values :
- -1 : UNKNOWN.
- 0 : FREE.
- 100 : OCCUPIED.
Your goal is to create a new map by replacing the values of the cells at the pose of an object from 100
to 0
, that would remove the objects from the map. You need to have another occupancy grid to save the history of your objects that have been removed. This occupancy grid would have cells with intermediate values at the pose of the objects (I'll suggest 50
but anything different than 0, -1 or 100 would be fine). This occupancy grid will be constantly overwritten (meaning the value of each cells) by the occupancy grid from gmapping to always have the updated map, unless the cells have the value 50
. By doing so you won't have to deal with the same object each time. Without history_map
, you wouldn't know which cell needs to be overwritten or not and you would do the same calculations over and over.
Then you will have to remove the objects and you'll be able to create the cleared_map
by changing every cells of histroy_map
from the value 50
to 0
.
Delete your objects
You now have your history_map
, the goal is now to find which cells will be set at the value 50
. You do have the pose of your objects. To work from a pose with an occupancy grid you first need to convert this pose to an index to get the corresponding cell.
Now here's the tricky part. You have to find all the cells corresponding to your object. You can assume that an object in map is always a group of cells at the value -1
and the edges at 100
(because gmapping
can't see inside objects so the cells are always unknown). For a cylindric paper bin as you used this example the map data ... (more)
Can you be more specific about what you exaclty want to achieve please ? How will you use your modified occupancy grid ?
How will you get them ?
An object detector implementation with a depth camera will provide the coordinates of certain objects. See for instance find_object. So when the robot detects these certain objects while gmapping, I'd like to remove them from the map (e.g. a paper bin).
And by saying " remove them from the map" you mean clear the cell value at the pose of the object (i.e. from 100=obstacle to 0=free) to get a map with only the walls, do I understand your issue correctly ?
Indeed, that's what exactly what I wanted to express.
Alsoo one last precision please : how will this new occupancy grid be used ? During the gmapping process or you just want to build a map without objects inside (meaning that you wouldn't have to "reinject" your occupancy grid in the mapping process)
The idea would be to "remove" from the occupancy grid little areas around the markers during gmapping process if possible, that is to build a map without objects inside.