mirror of
https://github.com/AtsushiSakai/PythonRobotics.git
synced 2026-02-11 12:26:08 -05:00
code clean up for LGTM
This commit is contained in:
@@ -73,8 +73,8 @@ def quad_sim(x_c, y_c, z_c):
|
|||||||
# des_x_pos = calculate_position(x_c[i], t)
|
# des_x_pos = calculate_position(x_c[i], t)
|
||||||
# des_y_pos = calculate_position(y_c[i], t)
|
# des_y_pos = calculate_position(y_c[i], t)
|
||||||
des_z_pos = calculate_position(z_c[i], t)
|
des_z_pos = calculate_position(z_c[i], t)
|
||||||
des_x_vel = calculate_velocity(x_c[i], t)
|
# des_x_vel = calculate_velocity(x_c[i], t)
|
||||||
des_y_vel = calculate_velocity(y_c[i], t)
|
# des_y_vel = calculate_velocity(y_c[i], t)
|
||||||
des_z_vel = calculate_velocity(z_c[i], t)
|
des_z_vel = calculate_velocity(z_c[i], t)
|
||||||
des_x_acc = calculate_acceleration(x_c[i], t)
|
des_x_acc = calculate_acceleration(x_c[i], t)
|
||||||
des_y_acc = calculate_acceleration(y_c[i], t)
|
des_y_acc = calculate_acceleration(y_c[i], t)
|
||||||
|
|||||||
@@ -576,7 +576,7 @@ def plot_animation(X, U): # pragma: no cover
|
|||||||
axis3d_equal(X[2, :], X[3, :], X[1, :], ax)
|
axis3d_equal(X[2, :], X[3, :], X[1, :], ax)
|
||||||
|
|
||||||
rx, ry, rz = X[1:4, k]
|
rx, ry, rz = X[1:4, k]
|
||||||
vx, vy, vz = X[4:7, k]
|
# vx, vy, vz = X[4:7, k]
|
||||||
qw, qx, qy, qz = X[7:11, k]
|
qw, qx, qy, qz = X[7:11, k]
|
||||||
|
|
||||||
CBI = np.array([
|
CBI = np.array([
|
||||||
@@ -618,8 +618,6 @@ def main():
|
|||||||
integrator = Integrator(m, K)
|
integrator = Integrator(m, K)
|
||||||
problem = SCProblem(m, K)
|
problem = SCProblem(m, K)
|
||||||
|
|
||||||
last_linear_cost = None
|
|
||||||
|
|
||||||
converged = False
|
converged = False
|
||||||
w_delta = W_DELTA
|
w_delta = W_DELTA
|
||||||
for it in range(iterations):
|
for it in range(iterations):
|
||||||
@@ -633,7 +631,7 @@ def main():
|
|||||||
X_last=X, U_last=U, sigma_last=sigma,
|
X_last=X, U_last=U, sigma_last=sigma,
|
||||||
weight_sigma=W_SIGMA, weight_nu=W_NU,
|
weight_sigma=W_SIGMA, weight_nu=W_NU,
|
||||||
weight_delta=w_delta, weight_delta_sigma=W_DELTA_SIGMA)
|
weight_delta=w_delta, weight_delta_sigma=W_DELTA_SIGMA)
|
||||||
info = problem.solve()
|
problem.solve()
|
||||||
|
|
||||||
X = problem.get_variable('X')
|
X = problem.get_variable('X')
|
||||||
U = problem.get_variable('U')
|
U = problem.get_variable('U')
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ def animate(grid, arm, route):
|
|||||||
theta2 = 2 * pi * node[1] / M - pi
|
theta2 = 2 * pi * node[1] / M - pi
|
||||||
arm.update_joints([theta1, theta2])
|
arm.update_joints([theta1, theta2])
|
||||||
plt.subplot(1, 2, 2)
|
plt.subplot(1, 2, 2)
|
||||||
arm.plot(plt, obstacles=obstacles)
|
arm.plot_arm(plt, obstacles=obstacles)
|
||||||
plt.xlim(-2.0, 2.0)
|
plt.xlim(-2.0, 2.0)
|
||||||
plt.ylim(-3.0, 3.0)
|
plt.ylim(-3.0, 3.0)
|
||||||
plt.show()
|
plt.show()
|
||||||
@@ -272,7 +272,7 @@ class NLinkArm(object):
|
|||||||
|
|
||||||
self.end_effector = np.array(self.points[self.n_links]).T
|
self.end_effector = np.array(self.points[self.n_links]).T
|
||||||
|
|
||||||
def plot(self, myplt, obstacles=[]): # pragma: no cover
|
def plot_arm(self, myplt, obstacles=[]): # pragma: no cover
|
||||||
myplt.cla()
|
myplt.cla()
|
||||||
|
|
||||||
for obstacle in obstacles:
|
for obstacle in obstacles:
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ def extend_path(cx, cy, cyaw):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# target course
|
# target course
|
||||||
import numpy as np
|
|
||||||
cx = np.arange(0, 50, 0.1)
|
cx = np.arange(0, 50, 0.1)
|
||||||
cy = [math.sin(ix / 5.0) * ix / 2.0 for ix in cx]
|
cy = [math.sin(ix / 5.0) * ix / 2.0 for ix in cx]
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,6 @@ def solve_DARE(A, B, Q, R):
|
|||||||
Xn = A.T * X * A - A.T * X * B * \
|
Xn = A.T * X * A - A.T * X * B * \
|
||||||
la.inv(R + B.T * X * B) * B.T * X * A + Q
|
la.inv(R + B.T * X * B) * B.T * X * A + Q
|
||||||
if (abs(Xn - X)).max() < eps:
|
if (abs(Xn - X)).max() < eps:
|
||||||
X = Xn
|
|
||||||
break
|
break
|
||||||
X = Xn
|
X = Xn
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ def main():
|
|||||||
plt.axis("equal")
|
plt.axis("equal")
|
||||||
|
|
||||||
# path generation
|
# path generation
|
||||||
rx, ry = potential_field_planning(
|
_, _ = potential_field_planning(
|
||||||
sx, sy, gx, gy, ox, oy, grid_size, robot_radius)
|
sx, sy, gx, gy, ox, oy, grid_size, robot_radius)
|
||||||
|
|
||||||
if show_animation:
|
if show_animation:
|
||||||
|
|||||||
@@ -5,15 +5,18 @@ Path tracking simulation with LQR steering control and PID speed control.
|
|||||||
author Atsushi Sakai (@Atsushi_twi)
|
author Atsushi Sakai (@Atsushi_twi)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import scipy.linalg as la
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import math
|
||||||
|
import numpy as np
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("../../PathPlanning/CubicSpline/")
|
sys.path.append("../../PathPlanning/CubicSpline/")
|
||||||
|
|
||||||
import numpy as np
|
try:
|
||||||
import math
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
import scipy.linalg as la
|
|
||||||
import cubic_spline_planner
|
import cubic_spline_planner
|
||||||
|
except:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
Kp = 1.0 # speed proportional gain
|
Kp = 1.0 # speed proportional gain
|
||||||
|
|
||||||
@@ -76,7 +79,6 @@ def solve_DARE(A, B, Q, R):
|
|||||||
Xn = A.T @ X @ A - A.T @ X @ B @ \
|
Xn = A.T @ X @ A - A.T @ X @ B @ \
|
||||||
la.inv(R + B.T @ X @ B) @ B.T @ X @ A + Q
|
la.inv(R + B.T @ X @ B) @ B.T @ X @ A + Q
|
||||||
if (abs(Xn - X)).max() < eps:
|
if (abs(Xn - X)).max() < eps:
|
||||||
X = Xn
|
|
||||||
break
|
break
|
||||||
X = Xn
|
X = Xn
|
||||||
|
|
||||||
@@ -206,8 +208,8 @@ def closed_loop_prediction(cx, cy, cyaw, ck, speed_profile, goal):
|
|||||||
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")
|
plt.plot(cx[target_ind], cy[target_ind], "xg", label="target")
|
||||||
plt.axis("equal")
|
plt.axis("equal")
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.title("speed[km/h]:" + str(round(state.v * 3.6, 2)) +
|
plt.title("speed[km/h]:" + str(round(state.v * 3.6, 2))
|
||||||
",target index:" + str(target_ind))
|
+ ",target index:" + str(target_ind))
|
||||||
plt.pause(0.0001)
|
plt.pause(0.0001)
|
||||||
|
|
||||||
return t, x, y, yaw, v
|
return t, x, y, yaw, v
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ def main():
|
|||||||
assert lastIndex >= target_ind, "Cannot goal"
|
assert lastIndex >= target_ind, "Cannot goal"
|
||||||
|
|
||||||
if show_animation:
|
if show_animation:
|
||||||
|
plt.cla()
|
||||||
plt.plot(cx, cy, ".r", label="course")
|
plt.plot(cx, cy, ".r", label="course")
|
||||||
plt.plot(x, y, "-b", label="trajectory")
|
plt.plot(x, y, "-b", label="trajectory")
|
||||||
plt.legend()
|
plt.legend()
|
||||||
@@ -148,7 +149,7 @@ def main():
|
|||||||
plt.axis("equal")
|
plt.axis("equal")
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
|
|
||||||
flg, ax = plt.subplots(1)
|
plt.subplots(1)
|
||||||
plt.plot(t, [iv * 3.6 for iv in v], "-r")
|
plt.plot(t, [iv * 3.6 for iv in v], "-r")
|
||||||
plt.xlabel("Time[s]")
|
plt.xlabel("Time[s]")
|
||||||
plt.ylabel("Speed[km/h]")
|
plt.ylabel("Speed[km/h]")
|
||||||
|
|||||||
Reference in New Issue
Block a user