Skip to content

Commit fa1585d

Browse files
authored
fix scanning error (AtsushiSakai#339)
1 parent a36ddb4 commit fa1585d

File tree

11 files changed

+487
-392
lines changed

11 files changed

+487
-392
lines changed

ArmNavigation/n_joint_arm_3d/random_forward_kinematics.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ def random_val(min_val, max_val):
1111
return min_val + random.random() * (max_val - min_val)
1212

1313

14-
if __name__ == "__main__":
14+
def main():
1515
print("Start solving Forward Kinematics 10 times")
16-
17-
# init NLinkArm with Denavit-Hartenberg parameters of PR2
16+
# init NLinkArm with Denavit-Hartenberg parameters of PR2
1817
n_link_arm = NLinkArm([[0., -math.pi / 2, .1, 0.],
1918
[math.pi / 2, math.pi / 2, 0., 0.],
2019
[0., -math.pi / 2, 0., .4],
2120
[0., math.pi / 2, 0., 0.],
2221
[0., -math.pi / 2, 0., .321],
2322
[0., math.pi / 2, 0., 0.],
2423
[0., 0., 0., 0.]])
25-
2624
# execute FK 10 times
27-
for i in range(10):
25+
for _ in range(10):
2826
n_link_arm.set_joint_angles(
29-
[random_val(-1, 1) for j in range(len(n_link_arm.link_list))])
27+
[random_val(-1, 1) for _ in range(len(n_link_arm.link_list))])
3028

31-
ee_pose = n_link_arm.forward_kinematics(plot=True)
29+
n_link_arm.forward_kinematics(plot=True)
30+
31+
32+
if __name__ == "__main__":
33+
main()

ArmNavigation/n_joint_arm_3d/random_inverse_kinematics.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ def random_val(min_val, max_val):
1111
return min_val + random.random() * (max_val - min_val)
1212

1313

14-
if __name__ == "__main__":
14+
def main():
1515
print("Start solving Inverse Kinematics 10 times")
16-
17-
# init NLinkArm with Denavit-Hartenberg parameters of PR2
16+
# init NLinkArm with Denavit-Hartenberg parameters of PR2
1817
n_link_arm = NLinkArm([[0., -math.pi / 2, .1, 0.],
1918
[math.pi / 2, math.pi / 2, 0., 0.],
2019
[0., -math.pi / 2, 0., .4],
2120
[0., math.pi / 2, 0., 0.],
2221
[0., -math.pi / 2, 0., .321],
2322
[0., math.pi / 2, 0., 0.],
2423
[0., 0., 0., 0.]])
25-
2624
# execute IK 10 times
27-
for i in range(10):
25+
for _ in range(10):
2826
n_link_arm.inverse_kinematics([random_val(-0.5, 0.5),
2927
random_val(-0.5, 0.5),
3028
random_val(-0.5, 0.5),
3129
random_val(-0.5, 0.5),
3230
random_val(-0.5, 0.5),
3331
random_val(-0.5, 0.5)], plot=True)
32+
33+
34+
if __name__ == "__main__":
35+
main()

Bipedal/bipedal_planner/bipedal_planner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ def walk(self, t_sup=0.8, z_c=0.8, a=10, b=1, plot=False):
4646
print("No footsteps")
4747
return
4848

49-
com_trajectory_for_plot, ax = None, None
50-
5149
# set up plotter
50+
com_trajectory_for_plot, ax = None, None
5251
if plot:
5352
fig = plt.figure()
5453
ax = Axes3D(fig)

InvertedPendulumCart/inverted_pendulum_mpc_control.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
author: Atsushi Sakai
44
"""
55

6-
import matplotlib.pyplot as plt
7-
import numpy as np
86
import math
97
import time
8+
109
import cvxpy
10+
import matplotlib.pyplot as plt
11+
import numpy as np
1112

1213
# Model parameters
1314

@@ -39,10 +40,11 @@ def main():
3940
for i in range(50):
4041

4142
# calc control input
42-
optimized_x, optimized_delta_x, optimized_theta, optimized_delta_theta, optimized_input = mpc_control(x)
43+
opt_x, opt_delta_x, opt_theta, opt_delta_theta, opt_input = \
44+
mpc_control(x)
4345

4446
# get input
45-
u = optimized_input[0]
47+
u = opt_input[0]
4648

4749
# simulate inverted pendulum cart
4850
x = simulation(x, u)
@@ -86,17 +88,19 @@ def mpc_control(x0):
8688
print("calc time:{0} [sec]".format(elapsed_time))
8789

8890
if prob.status == cvxpy.OPTIMAL:
89-
ox = get_nparray_from_matrix(x.value[0, :])
90-
dx = get_nparray_from_matrix(x.value[1, :])
91-
theta = get_nparray_from_matrix(x.value[2, :])
92-
dtheta = get_nparray_from_matrix(x.value[3, :])
91+
ox = get_numpy_array_from_matrix(x.value[0, :])
92+
dx = get_numpy_array_from_matrix(x.value[1, :])
93+
theta = get_numpy_array_from_matrix(x.value[2, :])
94+
d_theta = get_numpy_array_from_matrix(x.value[3, :])
9395

94-
ou = get_nparray_from_matrix(u.value[0, :])
96+
ou = get_numpy_array_from_matrix(u.value[0, :])
97+
else:
98+
ox, dx, theta, d_theta, ou = None, None, None, None, None
9599

96-
return ox, dx, theta, dtheta, ou
100+
return ox, dx, theta, d_theta, ou
97101

98102

99-
def get_nparray_from_matrix(x):
103+
def get_numpy_array_from_matrix(x):
100104
"""
101105
get build-in list from matrix
102106
"""
@@ -133,7 +137,7 @@ def plot_cart(xt, theta):
133137
radius = 0.1
134138

135139
cx = np.array([-cart_w / 2.0, cart_w / 2.0, cart_w /
136-
2.0, -cart_w / 2.0, -cart_w / 2.0])
140+
2.0, -cart_w / 2.0, -cart_w / 2.0])
137141
cy = np.array([0.0, 0.0, cart_h, cart_h, 0.0])
138142
cy += radius * 2.0
139143

Mapping/lidar_to_grid_map/lidar_to_grid_map.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def file_read(f):
1919
"""
2020
Reading LIDAR laser beams (angles and corresponding distance data)
2121
"""
22-
measures = [line.split(",") for line in open(f)]
22+
with open(f) as data:
23+
measures = [line.split(",") for line in data]
2324
angles = []
2425
distances = []
2526
for measure in measures:

0 commit comments

Comments
 (0)