Skip to content

Commit 7577494

Browse files
committed
plots 1 and 3 are now correct
1 parent 8901c53 commit 7577494

File tree

5 files changed

+2667
-3280
lines changed

5 files changed

+2667
-3280
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ consideration is that Phil sucks at C++ but no one sucks at Python.
1616

1717
# TODOs
1818

19-
- [] BUG: Histogram grid active region is upside down.
19+
- [] BUG: Histogram grid active region is upside down. Potential cause: have been using \[x\]\[y\] but should have been \[y\]\[x\]

lib/histogram_grid.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def from_map(cls, map_fname, active_region_dimension, resolution, robot_location
2727
reader = csv.reader(f, delimiter=" ")
2828
lines = list(reader)
2929

30+
# Convert string "1"s and "0"s to integer 1s and 0s
3031
lines = list(map(lambda l: list(map(int, l)), lines))
31-
# print(*lines, sep="\n")
32+
print("histogram_grid: histogram =")
33+
print(*lines, sep="\n")
3234
dimension = (len(lines[0]), len(lines))
3335
hg = cls(dimension, resolution, robot_location, active_region_dimension)
3436
hg.histogram_grid = lines
@@ -62,15 +64,17 @@ def update_certainty_at_continuous_point(self, continuous_point, certainty):
6264
certainty: certainty value to set.
6365
"""
6466
discrete_x, discrete_y = self.continuous_point_to_discrete_point(continuous_point)
65-
self.histogram_grid[discrete_x][discrete_y] = certainty
67+
# self.histogram_grid[discrete_x][discrete_y] = certainty
68+
self.histogram_grid[discrete_y][discrete_x] = certainty
6669

6770

6871
def get_certainty_at_discrete_point(self, discrete_point):
6972
"""
7073
Returns the certainty of an object being present at the given node
7174
"""
7275
discrete_x, discrete_y = discrete_point
73-
return self.histogram_grid[discrete_x][discrete_y]
76+
# return self.histogram_grid[discrete_x][discrete_y]
77+
return self.histogram_grid[discrete_y][discrete_x]
7478

7579

7680
def get_continuous_distance_between_discrete_points(self, discrete_start, discrete_end):
@@ -158,8 +162,8 @@ def get_obstacles(self):
158162
for col_idx, cell in enumerate(row):
159163
if cell != 0:
160164
# print("histogram_grid: obstacle =", (row_idx, col_idx))
161-
obstacles_points_x.append(row_idx)
162-
obstacles_points_y.append(col_idx)
165+
obstacles_points_x.append(col_idx)
166+
obstacles_points_y.append(row_idx)
163167
# print("histogram_grid: obstacles_points =", list(zip(obstacles_points_x, obstacles_points_y)))
164168
return obstacles_points_x, obstacles_points_y
165169

lib/path_planner.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def generate_histogram(self, robot_location):
7070
polar_histogram.add_certainty_to_bin_at_angle(robot_to_node_angle, delta_certainty)
7171
histogram_grid.get_certainty_at_discrete_point(node_considered)
7272

73+
7374
polar_histogram.smooth_histogram(self.l)
7475

7576

lib/robot.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def loop(self, num_steps, draw=True):
128128
fill=False
129129
)
130130
)
131+
simulation_plot.invert_yaxis()
131132

132133
# 2. Plot the polar histogram
133134
num_bins = self.path_planner.polar_histogram.num_bins
@@ -155,10 +156,10 @@ def my_autopct(pct):
155156

156157
# 3. Plot the valley
157158
histogram_grid_active_region = self.path_planner.histogram_grid.get_histogram_grid_active_region(active_region_min_x, active_region_min_y, active_region_max_x, active_region_max_y)
158-
print('histogram =')
159+
print('active region histogram =')
159160
print(*histogram_grid_active_region, sep='\n')
160161
histogram_grid_plot.clear()
161-
histogram_grid_plot.matshow(histogram_grid_active_region, origin="lower")
162+
histogram_grid_plot.matshow(histogram_grid_active_region, origin="upper")
162163

163164

164165
# self.draw(ax)
@@ -185,6 +186,7 @@ def my_autopct(pct):
185186
active_region_min_x, active_region_min_y, active_region_max_x, active_region_max_y = self.path_planner.histogram_grid.get_active_region(self.location)
186187
rectangle.set_bounds(active_region_min_x, active_region_min_y, active_region_max_x - active_region_min_x, active_region_max_y - active_region_min_y)
187188

189+
# simulation_plot.invert_yaxis()
188190

189191
# 2. Replot the polar histogram
190192
# sectors = self.path_planner.get_sectors() # NOTE: sectors are only valid
@@ -214,10 +216,10 @@ def my_autopct(pct):
214216

215217
# 3. Replot the histogram_grid
216218
histogram_grid_active_region = self.path_planner.histogram_grid.get_histogram_grid_active_region(active_region_min_x, active_region_min_y, active_region_max_x, active_region_max_y)
217-
print('histogram =')
219+
print('active region histogram =')
218220
print(*histogram_grid_active_region, sep='\n')
219221
histogram_grid_plot.clear()
220-
histogram_grid_plot.matshow(histogram_grid_active_region, origin="lower")
222+
histogram_grid_plot.matshow(histogram_grid_active_region, origin="upper")
221223

222224

223225
# 4. Actually display the plots

playground.ipynb

+2,650-3,270
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)