Skip to content

Commit 033e301

Browse files
authored
Cleanup cvxpy related codes (AtsushiSakai#823)
* add normal_vector_estimation_main.rst * add normal_vector_estimation_main.rst * cleanup cvxpy related codes * cleanup cvxpy related codes
1 parent 80124f2 commit 033e301

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

AerialNavigation/rocket_powered_landing/rocket_powered_landing.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
- EmbersArc/SuccessiveConvexificationFreeFinalTime: Implementation of "Successive Convexification for 6-DoF Mars Rocket Powered Landing with Free-Final-Time" https://github.com/EmbersArc/SuccessiveConvexificationFreeFinalTime
1313
1414
"""
15-
15+
import warnings
1616
from time import time
1717
import numpy as np
1818
from scipy.integrate import odeint
1919
import cvxpy
2020
import matplotlib.pyplot as plt
21-
from mpl_toolkits import mplot3d
2221

2322
# Trajectory points
2423
K = 50
@@ -123,7 +122,7 @@ def set_random_initial_state(self, rng):
123122
rng.uniform(-20, 20)))
124123

125124
def f_func(self, x, u):
126-
m, rx, ry, rz, vx, vy, vz, q0, q1, q2, q3, wx, wy, wz = x[0], x[1], x[
125+
m, _, _, _, vx, vy, vz, q0, q1, q2, q3, wx, wy, wz = x[0], x[1], x[
127126
2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13]
128127
ux, uy, uz = u[0], u[1], u[2]
129128

@@ -148,7 +147,7 @@ def f_func(self, x, u):
148147
])
149148

150149
def A_func(self, x, u):
151-
m, rx, ry, rz, vx, vy, vz, q0, q1, q2, q3, wx, wy, wz = x[0], x[1], x[
150+
m, _, _, _, _, _, _, q0, q1, q2, q3, wx, wy, wz = x[0], x[1], x[
152151
2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13]
153152
ux, uy, uz = u[0], u[1], u[2]
154153

@@ -176,7 +175,7 @@ def A_func(self, x, u):
176175
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
177176

178177
def B_func(self, x, u):
179-
m, rx, ry, rz, vx, vy, vz, q0, q1, q2, q3, wx, wy, wz = x[0], x[1], x[
178+
m, _, _, _, _, _, _, q0, q1, q2, q3, _, _, _ = x[0], x[1], x[
180179
2], x[3], x[4], x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12], x[13]
181180
ux, uy, uz = u[0], u[1], u[2]
182181

@@ -534,7 +533,9 @@ def get_variable(self, name):
534533
def solve(self, **kwargs):
535534
error = False
536535
try:
537-
self.prob.solve(verbose=verbose_solver,
536+
with warnings.catch_warnings(): # For User warning from solver
537+
warnings.simplefilter('ignore')
538+
self.prob.solve(verbose=verbose_solver,
538539
solver=solver)
539540
except cvxpy.SolverError:
540541
error = True
@@ -569,10 +570,10 @@ def axis3d_equal(X, Y, Z, ax):
569570
def plot_animation(X, U): # pragma: no cover
570571

571572
fig = plt.figure()
572-
ax = fig.gca(projection='3d')
573+
ax = fig.add_subplot(projection='3d')
573574
# for stopping simulation with the esc key.
574575
fig.canvas.mpl_connect('key_release_event',
575-
lambda event: [exit(0) if event.key == 'escape' else None])
576+
lambda event: [exit(0) if event.key == 'escape' else None])
576577

577578
for k in range(K):
578579
plt.cla()

PathTracking/model_predictive_speed_and_steer_control/model_predictive_speed_and_steer_control.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ def predict_motion(x0, oa, od, xref):
225225

226226
def iterative_linear_mpc_control(xref, x0, dref, oa, od):
227227
"""
228-
MPC contorl with updating operational point iteraitvely
228+
MPC control with updating operational point iteratively
229229
"""
230+
ox, oy, oyaw, ov = None, None, None, None
230231

231232
if oa is None or od is None:
232233
oa = [0.0] * T
@@ -406,10 +407,11 @@ def do_simulation(cx, cy, cyaw, ck, sp, dl, initial_state):
406407
oa, odelta, ox, oy, oyaw, ov = iterative_linear_mpc_control(
407408
xref, x0, dref, oa, odelta)
408409

410+
di, ai = 0.0, 0.0
409411
if odelta is not None:
410412
di, ai = odelta[0], oa[0]
413+
state = update_state(state, ai, di)
411414

412-
state = update_state(state, ai, di)
413415
time = time + DT
414416

415417
x.append(state.x)

0 commit comments

Comments
 (0)