Performance: Occupancy grid map concept
This concept affects how quickly a robot can update and render its environment map, impacting real-time navigation and sensor data processing.
for each cell within sensor range: update occupancy probability based on sensor reading
for each cell in the entire grid: update occupancy probability based on sensor reading
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Update entire grid every cycle | N/A | N/A | High CPU load delays rendering | [X] Bad |
| Update only cells in sensor range | N/A | N/A | Lower CPU load, smoother updates | [OK] Good |
What does an occupancy grid map represent in ROS?
Which data type correctly represents the occupancy grid map data in ROS?
nav_msgs::OccupancyGrid map;
// What type is map.data?Given this snippet in ROS Python:
grid = [0, 100, -1, 0]
free_cells = sum(1 for cell in grid if cell == 0)
occupied_cells = sum(1 for cell in grid if cell == 100)
unknown_cells = sum(1 for cell in grid if cell == -1)
print(f"Free: {free_cells}, Occupied: {occupied_cells}, Unknown: {unknown_cells}")What will be printed?
Identify the error in this ROS Python code snippet that tries to update an occupancy grid cell:
map_data = [0, 0, 0, 0]
index = 2
map_data[index] = 100
print(map_data)Why might this code fail in a real ROS occupancy grid update?
You want to create a 5x5 occupancy grid map in ROS where the center cell is occupied (value 100), edges are unknown (-1), and others are free (0). Which Python code correctly creates the data list for this map?
# Options:
# A
# data = [100 if i == 12 else -1 if i % 5 == 0 or i % 5 == 4 else 0 for i in range(25)]
# B
# data = [0]*25
# data[12] = 100
# for i in range(25):
# if i % 5 == 0 or i % 5 == 4 or i < 5 or i > 19:
# data[i] = -1
# C
# data = [-1]*25
# data[12] = 100
# for i in range(25):
# if i % 5 != 0 and i % 5 != 4 and 5 <= i <= 19:
# data[i] = 0
# D
# data = [0 if i != 7 else 100 for i in range(25)]
# for i in range(25):
# if i % 5 == 0 or i % 5 == 4 or i < 5 or i > 19:
# data[i] = -1Pass the test and this pattern moves unknown