Skip to content

Commit 18a4a2e

Browse files
committed
code clean up
1 parent 74b8432 commit 18a4a2e

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

Mapping/rectangle_fitting/rectangle_fitting.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def plot(self):
4242
plt.plot(gx, gy, "-xr")
4343

4444
def calc_global_contour(self):
45-
gx = [(ix * math.cos(self.yaw) + iy * math.sin(self.yaw)) +
46-
self.x for (ix, iy) in zip(self.vc_x, self.vc_y)]
47-
gy = [(ix * math.sin(self.yaw) - iy * math.cos(self.yaw)) +
48-
self.y for (ix, iy) in zip(self.vc_x, self.vc_y)]
45+
gx = [(ix * math.cos(self.yaw) + iy * math.sin(self.yaw))
46+
+ self.x for (ix, iy) in zip(self.vc_x, self.vc_y)]
47+
gy = [(ix * math.sin(self.yaw) - iy * math.cos(self.yaw))
48+
+ self.y for (ix, iy) in zip(self.vc_x, self.vc_y)]
4949

5050
return gx, gy
5151

@@ -131,6 +131,40 @@ def ray_casting_filter(xl, yl, thetal, rangel, angle_reso):
131131
return rx, ry
132132

133133

134+
def adoptive_range_segmentation(ox, oy):
135+
136+
S = []
137+
138+
checked = [False] * len(ox)
139+
R = 5.0
140+
141+
for i, _ in enumerate(ox):
142+
if checked[i]:
143+
continue
144+
C = []
145+
r = R
146+
for j, _ in enumerate(ox):
147+
d = math.sqrt((ox[i] - ox[j])**2 + (oy[i] - oy[j])**2)
148+
if d <= r:
149+
C.append(j)
150+
checked[j] = True
151+
S.append(C)
152+
153+
# Merge claster
154+
fS = []
155+
for k, _ in enumerate(S):
156+
for l, _ in enumerate(S):
157+
if k == l:
158+
continue
159+
160+
for k, _ in enumerate(S[k]):
161+
162+
print(S)
163+
input()
164+
165+
return S
166+
167+
134168
def main():
135169

136170
# simulation parameters
@@ -153,6 +187,9 @@ def main():
153187

154188
ox, oy = get_observation_points([v1, v2], angle_reso)
155189

190+
# step1: Adaptive Range Segmentation
191+
ids = adoptive_range_segmentation(ox, oy)
192+
156193
if show_animation: # pragma: no cover
157194
plt.cla()
158195
plt.axis("equal")

PathPlanning/RRT/simple_rrt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def Planning(self, animation=True):
9494

9595
return path
9696

97-
def DrawGraph(self, rnd=None):
97+
def DrawGraph(self, rnd=None): # pragma: no cover
9898
"""
9999
Draw Graph
100100
"""
@@ -162,7 +162,7 @@ def main():
162162
path = rrt.Planning(animation=show_animation)
163163

164164
# Draw final path
165-
if show_animation:
165+
if show_animation: # pragma: no cover
166166
rrt.DrawGraph()
167167
plt.plot([x for (x, y) in path], [y for (x, y) in path], '-r')
168168
plt.grid(True)

PathTracking/rear_wheel_feedback/rear_wheel_feedback.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import cubic_spline_planner
2-
import matplotlib.pyplot as plt
3-
import math
41
"""
52
63
Path tracking simulation with rear wheel feedback steering control and PID speed control.
74
85
author: Atsushi Sakai(@Atsushi_twi)
96
107
"""
8+
import matplotlib.pyplot as plt
9+
import math
10+
import numpy as np
1111
import sys
1212
sys.path.append("../../PathPlanning/CubicSpline/")
1313

14+
try:
15+
import cubic_spline_planner
16+
except:
17+
raise
18+
1419

1520
Kp = 1.0 # speed propotional gain
1621
# steering control parameter

0 commit comments

Comments
 (0)