Skip to content

Commit a164faa

Browse files
committed
replace math.radians to np.deg2rad
1 parent 15e044d commit a164faa

File tree

30 files changed

+108
-107
lines changed

30 files changed

+108
-107
lines changed

Localization/extended_kalman_filter/extended_kalman_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import matplotlib.pyplot as plt
1212

1313
# Estimation parameter of EKF
14-
Q = np.diag([0.1, 0.1, math.radians(1.0), 1.0])**2
15-
R = np.diag([1.0, math.radians(40.0)])**2
14+
Q = np.diag([0.1, 0.1, np.deg2rad(1.0), 1.0])**2
15+
R = np.diag([1.0, np.deg2rad(40.0)])**2
1616

1717
# Simulation parameter
1818
Qsim = np.diag([0.5, 0.5])**2
19-
Rsim = np.diag([1.0, math.radians(30.0)])**2
19+
Rsim = np.diag([1.0, np.deg2rad(30.0)])**2
2020

2121
DT = 0.1 # time tick [s]
2222
SIM_TIME = 50.0 # simulation time [s]

Localization/particle_filter/particle_filter.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
# Estimation parameter of PF
1414
Q = np.diag([0.1])**2 # range error
15-
R = np.diag([1.0, math.radians(40.0)])**2 # input error
15+
R = np.diag([1.0, np.deg2rad(40.0)])**2 # input error
1616

1717
# Simulation parameter
1818
Qsim = np.diag([0.2])**2
19-
Rsim = np.diag([1.0, math.radians(30.0)])**2
19+
Rsim = np.diag([1.0, np.deg2rad(30.0)])**2
2020

2121
DT = 0.1 # time tick [s]
2222
SIM_TIME = 50.0 # simulation time [s]
@@ -170,13 +170,17 @@ def plot_covariance_ellipse(xEst, PEst):
170170

171171
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
172172

173-
#eigval[bigind] or eiqval[smallind] were occassionally negative numbers extremely
174-
#close to 0 (~10^-20), catch these cases and set the respective variable to 0
175-
try: a = math.sqrt(eigval[bigind])
176-
except ValueError: a = 0
177-
178-
try: b = math.sqrt(eigval[smallind])
179-
except ValueError: b = 0
173+
# eigval[bigind] or eiqval[smallind] were occassionally negative numbers extremely
174+
# close to 0 (~10^-20), catch these cases and set the respective variable to 0
175+
try:
176+
a = math.sqrt(eigval[bigind])
177+
except ValueError:
178+
a = 0
179+
180+
try:
181+
b = math.sqrt(eigval[smallind])
182+
except ValueError:
183+
b = 0
180184

181185
x = [a * math.cos(it) for it in t]
182186
y = [b * math.sin(it) for it in t]

Localization/unscented_kalman_filter/unscented_kalman_filter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import matplotlib.pyplot as plt
1313

1414
# Estimation parameter of UKF
15-
Q = np.diag([0.1, 0.1, math.radians(1.0), 1.0])**2
16-
R = np.diag([1.0, math.radians(40.0)])**2
15+
Q = np.diag([0.1, 0.1, np.deg2rad(1.0), 1.0])**2
16+
R = np.diag([1.0, np.deg2rad(40.0)])**2
1717

1818
# Simulation parameter
1919
Qsim = np.diag([0.5, 0.5])**2
20-
Rsim = np.diag([1.0, math.radians(30.0)])**2
20+
Rsim = np.diag([1.0, np.deg2rad(30.0)])**2
2121

2222
DT = 0.1 # time tick [s]
2323
SIM_TIME = 50.0 # simulation time [s]

Mapping/circle_fitting/circle_fitting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def ray_casting_filter(xl, yl, thetal, rangel, angle_reso):
9393
def plot_circle(x, y, size, color="-b"):
9494
deg = list(range(0, 360, 5))
9595
deg.append(0)
96-
xl = [x + size * math.cos(math.radians(d)) for d in deg]
97-
yl = [y + size * math.sin(math.radians(d)) for d in deg]
96+
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
97+
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
9898
plt.plot(xl, yl, color)
9999

100100

@@ -107,8 +107,8 @@ def main():
107107
cx = -2.0 # initial x position of obstacle
108108
cy = -8.0 # initial y position of obstacle
109109
cr = 1.0 # obstacle radious
110-
theta = math.radians(30.0) # obstacle moving direction
111-
angle_reso = math.radians(3.0) # sensor angle resolution
110+
theta = np.deg2rad(30.0) # obstacle moving direction
111+
angle_reso = np.deg2rad(3.0) # sensor angle resolution
112112

113113
time = 0.0
114114
while time <= simtime:

Mapping/raycasting_grid_map/raycasting_grid_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def main():
114114
print(__file__ + " start!!")
115115

116116
xyreso = 0.25 # x-y grid resolution [m]
117-
yawreso = math.radians(10.0) # yaw angle resolution [rad]
117+
yawreso = np.deg2rad(10.0) # yaw angle resolution [rad]
118118

119119
for i in range(5):
120120
ox = (np.random.rand(4) - 0.5) * 10.0

Mapping/rectangle_fitting/rectangle_fitting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def ray_casting_filter(xl, yl, thetal, rangel, angle_reso):
9393
def plot_circle(x, y, size, color="-b"):
9494
deg = list(range(0, 360, 5))
9595
deg.append(0)
96-
xl = [x + size * math.cos(math.radians(d)) for d in deg]
97-
yl = [y + size * math.sin(math.radians(d)) for d in deg]
96+
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
97+
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
9898
plt.plot(xl, yl, color)
9999

100100

@@ -107,8 +107,8 @@ def main():
107107
cx = -2.0 # initial x position of obstacle
108108
cy = -8.0 # initial y position of obstacle
109109
cr = 1.0 # obstacle radious
110-
theta = math.radians(30.0) # obstacle moving direction
111-
angle_reso = math.radians(3.0) # sensor angle resolution
110+
theta = np.deg2rad(30.0) # obstacle moving direction
111+
angle_reso = np.deg2rad(3.0) # sensor angle resolution
112112

113113
time = 0.0
114114
while time <= simtime:

PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,8 @@ def choose_parent(self, newNode, nearinds):
221221

222222
return newNode
223223

224-
225224
def pi_2_pi(self, angle):
226-
return (angle + math.pi) % (2*math.pi) - math.pi
227-
225+
return (angle + math.pi) % (2 * math.pi) - math.pi
228226

229227
def steer(self, rnd, nind):
230228
# print(rnd)
@@ -265,7 +263,7 @@ def get_random_point(self):
265263
def get_best_last_indexs(self):
266264
# print("get_best_last_index")
267265

268-
YAWTH = math.radians(1.0)
266+
YAWTH = np.deg2rad(1.0)
269267
XYTH = 0.5
270268

271269
goalinds = []
@@ -420,8 +418,8 @@ def main():
420418
] # [x,y,size(radius)]
421419

422420
# Set Initial parameters
423-
start = [0.0, 0.0, math.radians(0.0)]
424-
goal = [6.0, 7.0, math.radians(90.0)]
421+
start = [0.0, 0.0, np.deg2rad(0.0)]
422+
goal = [6.0, 7.0, np.deg2rad(90.0)]
425423

426424
rrt = RRT(start, goal, randArea=[-2.0, 20.0], obstacleList=obstacleList)
427425
flag, x, y, yaw, v, t, a, d = rrt.Planning(animation=show_animation)

PathPlanning/ClosedLoopRRTStar/pure_pursuit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ def main():
236236
# state = unicycle_model.State(x=-1.0, y=-5.0, yaw=0.0, v=-30.0 / 3.6)
237237
# state = unicycle_model.State(x=10.0, y=5.0, yaw=0.0, v=-30.0 / 3.6)
238238
# state = unicycle_model.State(
239-
# x=3.0, y=5.0, yaw=math.radians(-40.0), v=-10.0 / 3.6)
239+
# x=3.0, y=5.0, yaw=np.deg2rad(-40.0), v=-10.0 / 3.6)
240240
# state = unicycle_model.State(
241-
# x=3.0, y=5.0, yaw=math.radians(40.0), v=50.0 / 3.6)
241+
# x=3.0, y=5.0, yaw=np.deg2rad(40.0), v=50.0 / 3.6)
242242

243243
lastIndex = len(cx) - 1
244244
time = 0.0

PathPlanning/ClosedLoopRRTStar/unicycle_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
dt = 0.05 # [s]
1212
L = 0.9 # [m]
13-
steer_max = math.radians(40.0)
13+
steer_max = np.deg2rad(40.0)
1414
curvature_max = math.tan(steer_max) / L
1515
curvature_max = 1.0 / curvature_max + 1.0
1616

@@ -38,7 +38,7 @@ def update(state, a, delta):
3838

3939

4040
def pi_2_pi(angle):
41-
return (angle + math.pi) % (2*math.pi) - math.pi
41+
return (angle + math.pi) % (2 * math.pi) - math.pi
4242

4343

4444
if __name__ == '__main__':
@@ -47,7 +47,7 @@ def pi_2_pi(angle):
4747

4848
T = 100
4949
a = [1.0] * T
50-
delta = [math.radians(1.0)] * T
50+
delta = [np.deg2rad(1.0)] * T
5151
# print(delta)
5252
# print(a, delta)
5353

PathPlanning/DubinsPath/dubins_path_planning.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def mod2pi(theta):
1717

1818

1919
def pi_2_pi(angle):
20-
return (angle + math.pi) % (2*math.pi) - math.pi
20+
return (angle + math.pi) % (2 * math.pi) - math.pi
2121

2222

2323
def LSL(alpha, beta, d):
@@ -221,7 +221,7 @@ def generate_course(length, mode, c):
221221
if m is "S":
222222
d = 1.0 * c
223223
else: # turning couse
224-
d = math.radians(3.0)
224+
d = np.deg2rad(3.0)
225225

226226
while pd < abs(l - d):
227227
# print(pd, l)
@@ -270,11 +270,11 @@ def main():
270270

271271
start_x = 1.0 # [m]
272272
start_y = 1.0 # [m]
273-
start_yaw = math.radians(45.0) # [rad]
273+
start_yaw = np.deg2rad(45.0) # [rad]
274274

275275
end_x = -3.0 # [m]
276276
end_y = -3.0 # [m]
277-
end_yaw = math.radians(-45.0) # [rad]
277+
end_yaw = np.deg2rad(-45.0) # [rad]
278278

279279
curvature = 1.0
280280

@@ -304,11 +304,11 @@ def test():
304304
for i in range(NTEST):
305305
start_x = (np.random.rand() - 0.5) * 10.0 # [m]
306306
start_y = (np.random.rand() - 0.5) * 10.0 # [m]
307-
start_yaw = math.radians((np.random.rand() - 0.5) * 180.0) # [rad]
307+
start_yaw = np.deg2rad((np.random.rand() - 0.5) * 180.0) # [rad]
308308

309309
end_x = (np.random.rand() - 0.5) * 10.0 # [m]
310310
end_y = (np.random.rand() - 0.5) * 10.0 # [m]
311-
end_yaw = math.radians((np.random.rand() - 0.5) * 180.0) # [rad]
311+
end_yaw = np.deg2rad((np.random.rand() - 0.5) * 180.0) # [rad]
312312

313313
curvature = 1.0 / (np.random.rand() * 5.0)
314314

PathPlanning/HybridAStar/hybrid_a_star.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ def main():
198198
oy.append(60.0 - i)
199199

200200
# Set Initial parameters
201-
start = [10.0, 10.0, math.radians(90.0)]
202-
goal = [50.0, 50.0, math.radians(-90.0)]
201+
start = [10.0, 10.0, np.deg2rad(90.0)]
202+
goal = [50.0, 50.0, np.deg2rad(-90.0)]
203203

204204
xyreso = 2.0
205-
yawreso = math.radians(15.0)
205+
yawreso = np.deg2rad(15.0)
206206

207207
rx, ry, ryaw = hybrid_a_star_planning(
208208
start, goal, ox, oy, xyreso, yawreso)

PathPlanning/ModelPredictiveTrajectoryGenerator/lookuptable_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def calc_states_list():
15-
maxyaw = math.radians(-30.0)
15+
maxyaw = np.deg2rad(-30.0)
1616

1717
x = np.arange(1.0, 30.0, 5.0)
1818
y = np.arange(0.0, 20.0, 2.0)

PathPlanning/ModelPredictiveTrajectoryGenerator/model_predictive_trajectory_generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def optimize_trajectory(target, k0, p):
133133

134134
def test_optimize_trajectory():
135135

136-
# target = motion_model.State(x=5.0, y=2.0, yaw=math.radians(00.0))
137-
target = motion_model.State(x=5.0, y=2.0, yaw=math.radians(90.0))
136+
# target = motion_model.State(x=5.0, y=2.0, yaw=np.deg2rad(00.0))
137+
target = motion_model.State(x=5.0, y=2.0, yaw=np.deg2rad(90.0))
138138
k0 = 0.0
139139

140140
init_p = np.matrix([6.0, 0.0, 0.0]).T
@@ -152,8 +152,8 @@ def test_optimize_trajectory():
152152
def test_trajectory_generate():
153153
s = 5.0 # [m]
154154
k0 = 0.0
155-
km = math.radians(30.0)
156-
kf = math.radians(-30.0)
155+
km = np.deg2rad(30.0)
156+
kf = np.deg2rad(-30.0)
157157

158158
# plt.plot(xk, yk, "xr")
159159
# plt.plot(t, kp)

PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ def main():
182182

183183
sx = 10.0 # start x position [m]
184184
sy = 10.0 # start y position [m]
185-
syaw = math.radians(10.0) # start yaw angle [rad]
185+
syaw = np.deg2rad(10.0) # start yaw angle [rad]
186186
sv = 1.0 # start speed [m/s]
187187
sa = 0.1 # start accel [m/ss]
188188
gx = 30.0 # goal x position [m]
189189
gy = -10.0 # goal y position [m]
190-
gyaw = math.radians(20.0) # goal yaw angle [rad]
190+
gyaw = np.deg2rad(20.0) # goal yaw angle [rad]
191191
gv = 1.0 # goal speed [m/s]
192192
ga = 0.1 # goal accel [m/ss]
193193
max_accel = 1.0 # max accel [m/ss]

PathPlanning/RRT/rrt_with_pathsmoothing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def DrawGraph(self, rnd=None):
112112
def PlotCircle(self, x, y, size):
113113
deg = list(range(0, 360, 5))
114114
deg.append(0)
115-
xl = [x + size * math.cos(math.radians(d)) for d in deg]
116-
yl = [y + size * math.sin(math.radians(d)) for d in deg]
115+
xl = [x + size * math.cos(np.deg2rad(d)) for d in deg]
116+
yl = [y + size * math.sin(np.deg2rad(d)) for d in deg]
117117
plt.plot(xl, yl, "-k")
118118

119119
def GetNearestListIndex(self, nodeList, rnd):

PathPlanning/RRTDubins/dubins_path_planning.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
1111
"""
1212
import math
13+
import numpy as np
1314

1415

1516
def mod2pi(theta):
1617
return theta - 2.0 * math.pi * math.floor(theta / 2.0 / math.pi)
1718

1819

1920
def pi_2_pi(angle):
20-
return (angle + math.pi) % (2*math.pi) - math.pi
21+
return (angle + math.pi) % (2 * math.pi) - math.pi
2122

2223

2324
def LSL(alpha, beta, d):
@@ -230,7 +231,7 @@ def generate_course(length, mode, c):
230231
if m is "S":
231232
d = 1.0 / c
232233
else: # turning couse
233-
d = math.radians(3.0)
234+
d = np.deg2rad(3.0)
234235

235236
while pd < abs(l - d):
236237
# print(pd, l)
@@ -281,11 +282,11 @@ def plot_arrow(x, y, yaw, length=1.0, width=0.5, fc="r", ec="k"):
281282

282283
start_x = 1.0 # [m]
283284
start_y = 1.0 # [m]
284-
start_yaw = math.radians(45.0) # [rad]
285+
start_yaw = np.deg2rad(45.0) # [rad]
285286

286287
end_x = -3.0 # [m]
287288
end_y = -3.0 # [m]
288-
end_yaw = math.radians(-45.0) # [rad]
289+
end_yaw = np.deg2rad(-45.0) # [rad]
289290

290291
curvature = 1.0
291292

PathPlanning/RRTDubins/rrt_dubins.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ def choose_parent(self, newNode, nearinds):
9696

9797
return newNode
9898

99-
10099
def pi_2_pi(self, angle):
101-
return (angle + math.pi) % (2*math.pi) - math.pi
102-
100+
return (angle + math.pi) % (2 * math.pi) - math.pi
103101

104102
def steer(self, rnd, nind):
105103
# print(rnd)
@@ -234,8 +232,8 @@ def main():
234232
] # [x,y,size(radius)]
235233

236234
# Set Initial parameters
237-
start = [0.0, 0.0, math.radians(0.0)]
238-
goal = [10.0, 10.0, math.radians(0.0)]
235+
start = [0.0, 0.0, np.deg2rad(0.0)]
236+
goal = [10.0, 10.0, np.deg2rad(0.0)]
239237

240238
rrt = RRT(start, goal, randArea=[-2.0, 15.0], obstacleList=obstacleList)
241239
path = rrt.Planning(animation=show_animation)

0 commit comments

Comments
 (0)