Skip to content

Commit 4d71470

Browse files
authored
upgrade numpy to 1.25.0 and fix bugs (AtsushiSakai#861)
1 parent 67edaf8 commit 4d71470

File tree

18 files changed

+66
-58
lines changed

18 files changed

+66
-58
lines changed

AerialNavigation/drone_3d_trajectory_following/drone_3d_trajectory_following.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import numpy as np
99
from Quadrotor import Quadrotor
1010
from TrajectoryGenerator import TrajectoryGenerator
11-
from mpl_toolkits.mplot3d import Axes3D
1211

1312
show_animation = True
1413

@@ -128,7 +127,7 @@ def calculate_position(c, t):
128127
Calculates a position given a set of quintic coefficients and a time.
129128
130129
Args
131-
c: List of coefficients generated by a quintic polynomial
130+
c: List of coefficients generated by a quintic polynomial
132131
trajectory generator.
133132
t: Time at which to calculate the position
134133
@@ -143,7 +142,7 @@ def calculate_velocity(c, t):
143142
Calculates a velocity given a set of quintic coefficients and a time.
144143
145144
Args
146-
c: List of coefficients generated by a quintic polynomial
145+
c: List of coefficients generated by a quintic polynomial
147146
trajectory generator.
148147
t: Time at which to calculate the velocity
149148
@@ -158,7 +157,7 @@ def calculate_acceleration(c, t):
158157
Calculates an acceleration given a set of quintic coefficients and a time.
159158
160159
Args
161-
c: List of coefficients generated by a quintic polynomial
160+
c: List of coefficients generated by a quintic polynomial
162161
trajectory generator.
163162
t: Time at which to calculate the acceleration
164163
@@ -168,7 +167,7 @@ def calculate_acceleration(c, t):
168167
return 20 * c[0] * t**3 + 12 * c[1] * t**2 + 6 * c[2] * t + 2 * c[3]
169168

170169

171-
def rotation_matrix(roll, pitch, yaw):
170+
def rotation_matrix(roll_array, pitch_array, yaw):
172171
"""
173172
Calculates the ZYX rotation matrix.
174173
@@ -180,6 +179,8 @@ def rotation_matrix(roll, pitch, yaw):
180179
Returns
181180
3x3 rotation matrix as NumPy array
182181
"""
182+
roll = roll_array[0]
183+
pitch = pitch_array[0]
183184
return np.array(
184185
[[cos(yaw) * cos(pitch), -sin(yaw) * cos(roll) + cos(yaw) * sin(pitch) * sin(roll), sin(yaw) * sin(roll) + cos(yaw) * sin(pitch) * cos(roll)],
185186
[sin(yaw) * cos(pitch), cos(yaw) * cos(roll) + sin(yaw) * sin(pitch) *
@@ -190,7 +191,7 @@ def rotation_matrix(roll, pitch, yaw):
190191

191192
def main():
192193
"""
193-
Calculates the x, y, z coefficients for the four segments
194+
Calculates the x, y, z coefficients for the four segments
194195
of the trajectory
195196
"""
196197
x_coeffs = [[], [], [], []]

ArmNavigation/two_joint_arm_to_point_control/two_joint_arm_to_point_control.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
import matplotlib.pyplot as plt
1616
import numpy as np
17+
import math
1718

1819

19-
# Similation parameters
20+
# Simulation parameters
2021
Kp = 15
2122
dt = 0.01
2223

@@ -50,15 +51,15 @@ def two_joint_arm(GOAL_TH=0.0, theta1=0.0, theta2=0.0):
5051
else:
5152
theta2_goal = np.arccos(
5253
(x**2 + y**2 - l1**2 - l2**2) / (2 * l1 * l2))
53-
tmp = np.math.atan2(l2 * np.sin(theta2_goal),
54+
tmp = math.atan2(l2 * np.sin(theta2_goal),
5455
(l1 + l2 * np.cos(theta2_goal)))
55-
theta1_goal = np.math.atan2(y, x) - tmp
56+
theta1_goal = math.atan2(y, x) - tmp
5657

5758
if theta1_goal < 0:
5859
theta2_goal = -theta2_goal
59-
tmp = np.math.atan2(l2 * np.sin(theta2_goal),
60+
tmp = math.atan2(l2 * np.sin(theta2_goal),
6061
(l1 + l2 * np.cos(theta2_goal)))
61-
theta1_goal = np.math.atan2(y, x) - tmp
62+
theta1_goal = math.atan2(y, x) - tmp
6263

6364
theta1 = theta1 + Kp * ang_diff(theta1_goal, theta1) * dt
6465
theta2 = theta2 + Kp * ang_diff(theta2_goal, theta2) * dt

Control/inverted_pendulum/inverted_pendulum_lqr_control.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ def main():
5050

5151
if show_animation:
5252
plt.clf()
53-
px = float(x[0])
54-
theta = float(x[2])
53+
px = float(x[0, 0])
54+
theta = float(x[2, 0])
5555
plot_cart(px, theta)
5656
plt.xlim([-5.0, 2.0])
5757
plt.pause(0.001)
5858

5959
print("Finish")
60-
print(f"x={float(x[0]):.2f} [m] , theta={math.degrees(x[2]):.2f} [deg]")
60+
print(f"x={float(x[0, 0]):.2f} [m] , theta={math.degrees(x[2, 0]):.2f} [deg]")
6161
if show_animation:
6262
plt.show()
6363

Control/inverted_pendulum/inverted_pendulum_mpc_control.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def main():
5555

5656
if show_animation:
5757
plt.clf()
58-
px = float(x[0])
59-
theta = float(x[2])
58+
px = float(x[0, 0])
59+
theta = float(x[2, 0])
6060
plot_cart(px, theta)
6161
plt.xlim([-5.0, 2.0])
6262
plt.pause(0.001)
6363

6464
print("Finish")
65-
print(f"x={float(x[0]):.2f} [m] , theta={math.degrees(x[2]):.2f} [deg]")
65+
print(f"x={float(x[0, 0]):.2f} [m] , theta={math.degrees(x[2, 0]):.2f} [deg]")
6666
if show_animation:
6767
plt.show()
6868

Localization/histogram_filter/histogram_filter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import math
1616

1717
import matplotlib.pyplot as plt
18+
import matplotlib as mpl
1819
import numpy as np
1920
from scipy.ndimage import gaussian_filter
2021
from scipy.stats import norm
@@ -114,7 +115,7 @@ def motion_model(x, u):
114115
def draw_heat_map(data, mx, my):
115116
max_value = max([max(i_data) for i_data in data])
116117
plt.grid(False)
117-
plt.pcolor(mx, my, data, vmax=max_value, cmap=plt.cm.get_cmap("Blues"))
118+
plt.pcolor(mx, my, data, vmax=max_value, cmap=mpl.colormaps["Blues"])
118119
plt.axis("equal")
119120

120121

@@ -194,7 +195,7 @@ def motion_update(grid_map, u, yaw):
194195
y_shift = grid_map.dy // grid_map.xy_resolution
195196

196197
if abs(x_shift) >= 1.0 or abs(y_shift) >= 1.0: # map should be shifted
197-
grid_map = map_shift(grid_map, int(x_shift), int(y_shift))
198+
grid_map = map_shift(grid_map, int(x_shift[0]), int(y_shift[0]))
198199
grid_map.dx -= x_shift * grid_map.xy_resolution
199200
grid_map.dy -= y_shift * grid_map.xy_resolution
200201

Localization/unscented_kalman_filter/unscented_kalman_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def motion_model(x, u):
6969
[0, 0, 1.0, 0],
7070
[0, 0, 0, 0]])
7171

72-
B = np.array([[DT * math.cos(x[2]), 0],
73-
[DT * math.sin(x[2]), 0],
72+
B = np.array([[DT * math.cos(x[2, 0]), 0],
73+
[DT * math.sin(x[2, 0]), 0],
7474
[0.0, DT],
7575
[1.0, 0.0]])
7676

Mapping/circle_fitting/circle_fitting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def circle_fitting(x, y):
4040

4141
T = np.linalg.inv(F).dot(G)
4242

43-
cxe = float(T[0] / -2)
44-
cye = float(T[1] / -2)
45-
re = math.sqrt(cxe**2 + cye**2 - T[2])
43+
cxe = float(T[0, 0] / -2)
44+
cye = float(T[1, 0] / -2)
45+
re = math.sqrt(cxe**2 + cye**2 - T[2, 0])
4646

4747
error = sum([np.hypot(cxe - ix, cye - iy) - re for (ix, iy) in zip(x, y)])
4848

PathPlanning/BatchInformedRRTStar/batch_informed_rrtstar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
show_animation = True
2424

2525

26-
class RTree(object):
26+
class RTree:
2727
# Class to represent the explicit tree created
2828
# while sampling through the state space
2929

@@ -132,7 +132,7 @@ def node_id_to_real_world_coord(self, nid):
132132
self.node_id_to_grid_coord(nid))
133133

134134

135-
class BITStar(object):
135+
class BITStar:
136136

137137
def __init__(self, start, goal,
138138
obstacleList, randArea, eta=2.0,
@@ -189,7 +189,7 @@ def setup_planning(self):
189189
[(self.start[1] + self.goal[1]) / 2.0], [0]])
190190
a1 = np.array([[(self.goal[0] - self.start[0]) / cMin],
191191
[(self.goal[1] - self.start[1]) / cMin], [0]])
192-
eTheta = math.atan2(a1[1], a1[0])
192+
eTheta = math.atan2(a1[1, 0], a1[0, 0])
193193
# first column of identity matrix transposed
194194
id1_t = np.array([1.0, 0.0, 0.0]).reshape(1, 3)
195195
M = np.dot(a1, id1_t)

PathPlanning/InformedRRTStar/informed_rrt_star.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def informed_rrt_star_search(self, animation=True):
5858
a1 = np.array([[(self.goal.x - self.start.x) / c_min],
5959
[(self.goal.y - self.start.y) / c_min], [0]])
6060

61-
e_theta = math.atan2(a1[1], a1[0])
61+
e_theta = math.atan2(a1[1, 0], a1[0, 0])
6262
# first column of identity matrix transposed
6363
id1_t = np.array([1.0, 0.0, 0.0]).reshape(1, 3)
6464
m = a1 @ id1_t
@@ -136,7 +136,7 @@ def choose_parent(self, new_node, near_inds):
136136

137137
def find_near_nodes(self, new_node):
138138
n_node = len(self.node_list)
139-
r = 50.0 * math.sqrt((math.log(n_node) / n_node))
139+
r = 50.0 * math.sqrt(math.log(n_node) / n_node)
140140
d_list = [(node.x - new_node.x) ** 2 + (node.y - new_node.y) ** 2 for
141141
node in self.node_list]
142142
near_inds = [d_list.index(i) for i in d_list if i <= r ** 2]

PathPlanning/ModelPredictiveTrajectoryGenerator/lookup_table_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def generate_lookup_table():
8181
if x is not None:
8282
print("find good path")
8383
lookup_table.append(
84-
[x[-1], y[-1], yaw[-1], float(p[0]), float(p[1]), float(p[2])])
84+
[x[-1], y[-1], yaw[-1], float(p[0, 0]), float(p[1, 0]), float(p[2, 0])])
8585

8686
print("finish lookup table generation")
8787

0 commit comments

Comments
 (0)