Borrar filtros
Borrar filtros

Displaying Live Occupancy Grid

30 visualizaciones (últimos 30 días)
Josh
Josh el 24 de Jun. de 2024 a las 11:12
Comentada: Josh el 26 de Jun. de 2024 a las 10:46
The problem I've got is when using show() for occupancy grids within Navigation Toolbox -> Mapping I have a problem when I try to display a live occupancy grid which I'm generating from a LIDAR stream then I can't manipulate the plot that is generated (move, zoom etc) as it defaults back to the original viewing angle and zoom every time show() is called.
I've been scouring the web for any guidance but nothing is coming up so I would appreciate any assistance - thanks!

Respuestas (1)

Namnendra
Namnendra el 26 de Jun. de 2024 a las 8:47
Hi Josh,
I understand that you want to keep the viewing settings and don't want it to reset when you call show() function.
When you are displaying a live occupancy grid using `show()` in MATLAB's Navigation Toolbox, the issue you are encountering is due to the fact that each call to `show()` resets the plot to its default view. To maintain interactivity (such as moving, zooming, etc.) while updating the occupancy grid, you can update the plot data without completely redrawing the plot.
One way to achieve this is by using `hold on` to maintain the current plot and then updating the data within the same plot. Here is a general approach to handle this:
1. Initialize the Plot: Create the initial plot outside of your loop.
2. Update the Plot Data: Instead of calling `show()` repeatedly, update the existing plot data.
Here is an example code snippet demonstrating this approach:
% Assume you have a function getLidarData() that returns the latest occupancy grid
% and a function updateOccupancyGrid() that updates the occupancy grid with new LIDAR data
% Initialize the occupancy grid
map = occupancyMap(10, 10, 20); % Create a 10x10 meter map with 20 cells per meter
% Initialize the plot
figure;
h = show(map);
title('Live Occupancy Grid');
xlabel('X [meters]');
ylabel('Y [meters]');
axis equal;
hold on;
% Main loop to update the occupancy grid
while true
% Get new LIDAR data and update the occupancy grid
newLidarData = getLidarData();
updateOccupancyGrid(map, newLidarData);
% Update the plot data
h.CData = occupancyMatrix(map);
% Pause for a short duration to allow for plot updates
pause(0.1);
end
function newLidarData = getLidarData()
% Placeholder function to simulate getting new LIDAR data
% Replace this with your actual LIDAR data acquisition code
newLidarData = rand(10, 10); % Example random data
end
function updateOccupancyGrid(map, newLidarData)
% Placeholder function to simulate updating the occupancy grid
% Replace this with your actual occupancy grid update code
setOccupancy(map, [1:size(newLidarData, 1)]', [1:size(newLidarData, 2)]', newLidarData);
end
Explanation:
1. Initialize the Occupancy Grid and Plot:
- Create an occupancy grid using `occupancyMap`.
- Initialize the plot using `show(map)` and store the handle to the plot in `h`.
2. Main Loop:
- Continuously update the occupancy grid with new LIDAR data.
- Update the plot data using `h.CData = occupancyMatrix(map)` to reflect the changes in the occupancy grid without resetting the plot view.
3. Helper Functions:
- `getLidarData()`: Simulates acquiring new LIDAR data.
- `updateOccupancyGrid()`: Simulates updating the occupancy grid with the new LIDAR data.
Notes:
- This approach avoids calling `show()` repeatedly, which resets the plot view.
- By updating the `CData` property of the plot handle `h`, the plot is updated with the new occupancy grid data while maintaining the current view.
You can replace the placeholder functions `getLidarData()` and `updateOccupancyGrid()` with your actual LIDAR data acquisition and occupancy grid update logic. This should help you maintain interactivity with the plot while displaying a live occupancy grid.
I hope the above information resolves your query.
Thank you.
  1 comentario
Josh
Josh el 26 de Jun. de 2024 a las 10:46
Hey Namnendra thank you for this, this has helped my 2D occupancy map case!
Can you advise how this could be done for a 3D map using occupanyMap3D?
Thank you for your help so far!

Iniciar sesión para comentar.

Categorías

Más información sobre Preprocessing en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by