Skip to content

Commit 3019e95

Browse files
committed
add use case
1 parent 8a3e4a4 commit 3019e95

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

AerialNavigation/rocket_powered_landing/rocket_powered_landing.py

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,7 @@ def omega(self, w):
343343

344344
def initialize_trajectory(self, X, U):
345345
"""
346-
Initialize the trajectory.
347-
348-
:param X: Numpy array of states to be initialized
349-
:param U: Numpy array of inputs to be initialized
350-
:return: The initialized X and U
346+
Initialize the trajectory with linear approximation.
351347
"""
352348
K = X.shape[1]
353349

@@ -565,6 +561,46 @@ def axis3d_equal(X, Y, Z, ax):
565561
ax.plot([xb], [yb], [zb], 'w')
566562

567563

564+
def plot_animation(X, U):
565+
566+
fig = plt.figure()
567+
ax = fig.gca(projection='3d')
568+
569+
for k in range(K):
570+
plt.cla()
571+
ax.plot(X[2, :], X[3, :], X[1, :]) # trajectory
572+
ax.scatter3D([0.0], [0.0], [0.0], c="r",
573+
marker="x") # target landing point
574+
axis3d_equal(X[2, :], X[3, :], X[1, :], ax)
575+
576+
rx, ry, rz = X[1:4, k]
577+
vx, vy, vz = X[4:7, k]
578+
qw, qx, qy, qz = X[7:11, k]
579+
580+
CBI = np.array([
581+
[1 - 2 * (qy ** 2 + qz ** 2), 2 * (qx * qy + qw * qz),
582+
2 * (qx * qz - qw * qy)],
583+
[2 * (qx * qy - qw * qz), 1 - 2 *
584+
(qx ** 2 + qz ** 2), 2 * (qy * qz + qw * qx)],
585+
[2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx),
586+
1 - 2 * (qx ** 2 + qy ** 2)]
587+
])
588+
589+
Fx, Fy, Fz = np.dot(np.transpose(CBI), U[:, k])
590+
dx, dy, dz = np.dot(np.transpose(CBI), np.array([1., 0., 0.]))
591+
592+
# attitude vector
593+
ax.quiver(ry, rz, rx, dy, dz, dx, length=0.5, linewidth=3.0,
594+
arrow_length_ratio=0.0, color='black')
595+
596+
# thrust vector
597+
ax.quiver(ry, rz, rx, -Fy, -Fz, -Fx, length=0.1,
598+
arrow_length_ratio=0.0, color='red')
599+
600+
ax.set_title("Rocket powered landing")
601+
plt.pause(0.5)
602+
603+
568604
def main():
569605
print("start!!")
570606
m = Model_6DoF()
@@ -625,45 +661,5 @@ def main():
625661
print("done!!")
626662

627663

628-
def plot_animation(X, U):
629-
630-
fig = plt.figure()
631-
ax = fig.gca(projection='3d')
632-
633-
for k in range(K):
634-
plt.cla()
635-
ax.plot(X[2, :], X[3, :], X[1, :]) # trajectory
636-
ax.scatter3D([0.0], [0.0], [0.0], c="r",
637-
marker="x") # target landing point
638-
axis3d_equal(X[2, :], X[3, :], X[1, :], ax)
639-
640-
rx, ry, rz = X[1:4, k]
641-
vx, vy, vz = X[4:7, k]
642-
qw, qx, qy, qz = X[7:11, k]
643-
644-
CBI = np.array([
645-
[1 - 2 * (qy ** 2 + qz ** 2), 2 * (qx * qy + qw * qz),
646-
2 * (qx * qz - qw * qy)],
647-
[2 * (qx * qy - qw * qz), 1 - 2 *
648-
(qx ** 2 + qz ** 2), 2 * (qy * qz + qw * qx)],
649-
[2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx),
650-
1 - 2 * (qx ** 2 + qy ** 2)]
651-
])
652-
653-
Fx, Fy, Fz = np.dot(np.transpose(CBI), U[:, k])
654-
dx, dy, dz = np.dot(np.transpose(CBI), np.array([1., 0., 0.]))
655-
656-
# attitude vector
657-
ax.quiver(ry, rz, rx, dy, dz, dx, length=0.5, linewidth=3.0,
658-
arrow_length_ratio=0.0, color='black')
659-
660-
# thrust vector
661-
ax.quiver(ry, rz, rx, -Fy, -Fz, -Fx, length=0.1,
662-
arrow_length_ratio=0.0, color='red')
663-
664-
ax.set_title("Rocket powered landing")
665-
plt.pause(0.5)
666-
667-
668664
if __name__ == '__main__':
669665
main()

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Python codes for robotics algorithm.
1212

1313

14+
1415
# Table of Contents
1516
* [What is this?](#what-is-this)
1617
* [Requirements](#requirements)
@@ -59,6 +60,7 @@ Python codes for robotics algorithm.
5960
* [Aerial Navigation](#aerial-navigation)
6061
* [drone 3d trajectory following](#drone-3d-trajectory-following)
6162
* [License](#license)
63+
* [Use-case](#use-case)
6264
* [Contribution](#contribution)
6365
* [Support](#support)
6466
* [Authors](#authors)
@@ -569,3 +571,4 @@ This is a list: [Users comments](https://github.com/AtsushiSakai/PythonRobotics/
569571

570572

571573

574+

0 commit comments

Comments
 (0)