python-motion-planning 2.0.dev2__py3-none-any.whl → 2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. python_motion_planning/__init__.py +1 -1
  2. python_motion_planning/common/env/map/grid.py +568 -147
  3. python_motion_planning/common/utils/geometry.py +21 -31
  4. python_motion_planning/path_planner/graph_search/lazy_theta_star.py +15 -7
  5. python_motion_planning/path_planner/graph_search/theta_star.py +4 -3
  6. python_motion_planning/path_planner/sample_search/rrt.py +6 -6
  7. python_motion_planning/path_planner/sample_search/rrt_connect.py +2 -2
  8. python_motion_planning/path_planner/sample_search/rrt_star.py +31 -11
  9. python_motion_planning/traj_optimizer/__init__.py +2 -0
  10. python_motion_planning/traj_optimizer/base_curve_generator.py +53 -0
  11. python_motion_planning/traj_optimizer/curve_generator/__init__.py +2 -0
  12. python_motion_planning/traj_optimizer/curve_generator/point_based/__init__.py +2 -0
  13. python_motion_planning/traj_optimizer/curve_generator/point_based/bspline.py +256 -0
  14. python_motion_planning/traj_optimizer/curve_generator/point_based/cubic_spline.py +115 -0
  15. python_motion_planning/traj_optimizer/curve_generator/pose_based/__init__.py +4 -0
  16. python_motion_planning/traj_optimizer/curve_generator/pose_based/bezier.py +121 -0
  17. python_motion_planning/traj_optimizer/curve_generator/pose_based/dubins.py +355 -0
  18. python_motion_planning/traj_optimizer/curve_generator/pose_based/polynomial.py +197 -0
  19. python_motion_planning/traj_optimizer/curve_generator/pose_based/reeds_shepp.py +606 -0
  20. {python_motion_planning-2.0.dev2.dist-info → python_motion_planning-2.1.dist-info}/METADATA +23 -16
  21. {python_motion_planning-2.0.dev2.dist-info → python_motion_planning-2.1.dist-info}/RECORD +24 -22
  22. {python_motion_planning-2.0.dev2.dist-info → python_motion_planning-2.1.dist-info}/WHEEL +1 -1
  23. python_motion_planning/curve_generator/__init__.py +0 -9
  24. python_motion_planning/curve_generator/bezier_curve.py +0 -131
  25. python_motion_planning/curve_generator/bspline_curve.py +0 -271
  26. python_motion_planning/curve_generator/cubic_spline.py +0 -128
  27. python_motion_planning/curve_generator/curve.py +0 -64
  28. python_motion_planning/curve_generator/dubins_curve.py +0 -348
  29. python_motion_planning/curve_generator/fem_pos_smooth.py +0 -114
  30. python_motion_planning/curve_generator/polynomial_curve.py +0 -226
  31. python_motion_planning/curve_generator/reeds_shepp.py +0 -736
  32. {python_motion_planning-2.0.dev2.dist-info → python_motion_planning-2.1.dist-info}/licenses/LICENSE +0 -0
  33. {python_motion_planning-2.0.dev2.dist-info → python_motion_planning-2.1.dist-info}/top_level.txt +0 -0
@@ -1,226 +0,0 @@
1
- """
2
- @file: polynomial_curve.py
3
- @breif: Polynomial curve generation
4
- @author: Winter
5
- @update: 2023.7.25
6
- """
7
- import math
8
- import numpy as np
9
-
10
- # from python_motion_planning.utils import Plot
11
- from .curve import Curve
12
-
13
- class Polynomial(Curve):
14
- """
15
- Class for polynomial curve generation(Quintic).
16
-
17
- Parameters:
18
- step (float): Simulation or interpolation size
19
- max_acc (float): Maximum acceleration
20
- max_jerk (float): Maximum jerk
21
-
22
- Examples:
23
- >>> from python_motion_planning.curve_generation import Polynomial
24
- >>> points = [(0, 0, 0), (10, 10, -90), (20, 5, 60)]
25
- >>> generator = Polynomial(step, max_acc, max_jerk)
26
- >>> generator.run(points)
27
- """
28
- def __init__(self, step: float, max_acc: float, max_jerk: float) -> None:
29
- super().__init__(step)
30
- self.max_acc = max_acc
31
- self.max_jerk = max_jerk
32
- self.dt = 0.1
33
- self.t_min = 1
34
- self.t_max = 30
35
-
36
- def __str__(self) -> str:
37
- return "Quintic Polynomial Curve"
38
-
39
- class Poly:
40
- """
41
- Polynomial interpolation solver
42
- """
43
- def __init__(self, state0: tuple, state1: tuple, t: float) -> None:
44
- x0, v0, a0 = state0
45
- xt, vt, at = state1
46
-
47
- A = np.array([[t ** 3, t ** 4, t ** 5],
48
- [3 * t ** 2, 4 * t ** 3, 5 * t ** 4],
49
- [6 * t, 12 * t ** 2, 20 * t ** 3]])
50
- b = np.array([xt - x0 - v0 * t - a0 * t ** 2 / 2,
51
- vt - v0 - a0 * t,
52
- at - a0])
53
- X = np.linalg.solve(A, b)
54
-
55
- # Quintic polynomial coefficient
56
- self.p0 = x0
57
- self.p1 = v0
58
- self.p2 = a0 / 2.0
59
- self.p3 = X[0]
60
- self.p4 = X[1]
61
- self.p5 = X[2]
62
-
63
- def x(self, t):
64
- return self.p0 + self.p1 * t + self.p2 * t ** 2 + \
65
- self.p3 * t ** 3 + self.p4 * t ** 4 + self.p5 * t ** 5
66
-
67
- def dx(self, t):
68
- return self.p1 + 2 * self.p2 * t + 3 * self.p3 * t ** 2 + \
69
- 4 * self.p4 * t ** 3 + 5 * self.p5 * t ** 4
70
-
71
- def ddx(self, t):
72
- return 2 * self.p2 + 6 * self.p3 * t + 12 * self.p4 * t ** 2 + 20 * self.p5 * t ** 3
73
-
74
- def dddx(self, t):
75
- return 6 * self.p3 + 24 * self.p4 * t + 60 * self.p5 * t ** 2
76
-
77
- class Trajectory:
78
- """
79
- Polynomial interpolation solver
80
- """
81
- def __init__(self):
82
- self.clear()
83
-
84
- def clear(self):
85
- self.time = []
86
- self.x = []
87
- self.y = []
88
- self.yaw = []
89
- self.v = []
90
- self.a = []
91
- self.jerk = []
92
-
93
- @property
94
- def size(self):
95
- assert len(self.time) == len(self.x) and \
96
- len(self.x) == len(self.y) and \
97
- len(self.y) == len(self.yaw) and \
98
- len(self.yaw) == len(self.v) and \
99
- len(self.v) == len(self.a) and \
100
- len(self.a) == len(self.jerk), \
101
- "Unequal dimensions of each attribute, this should not happen."
102
- return len(self.time)
103
-
104
- def generation(self, start_pose: tuple, goal_pose: tuple):
105
- """
106
- Generate the polynomial Curve.
107
-
108
- Parameters:
109
- start_pose (tuple): Initial pose (x, y, yaw)
110
- goal_pose (tuple): Target pose (x, y, yaw)
111
-
112
- Returns:
113
- traj (Traj): The first trajectory that satisfies the acceleration and jerk constraint
114
- """
115
- sx, sy, syaw, sv, sa = start_pose
116
- gx, gy, gyaw, gv, ga = goal_pose
117
-
118
- sv_x = sv * math.cos(syaw)
119
- sv_y = sv * math.sin(syaw)
120
- gv_x = gv * math.cos(gyaw)
121
- gv_y = gv * math.sin(gyaw)
122
-
123
- sa_x = sa * math.cos(syaw)
124
- sa_y = sa * math.sin(syaw)
125
- ga_x = ga * math.cos(gyaw)
126
- ga_y = ga * math.sin(gyaw)
127
-
128
- traj = self.Trajectory()
129
-
130
- for T in np.arange(self.t_min, self.t_max, self.step):
131
- x_psolver = self.Poly((sx, sv_x, sa_x), (gx, gv_x, ga_x), T)
132
- y_psolver = self.Poly((sy, sv_y, sa_y), (gy, gv_y, ga_y), T)
133
-
134
- for t in np.arange(0.0, T + self.dt, self.dt):
135
- traj.time.append(t)
136
- traj.x.append(x_psolver.x(t))
137
- traj.y.append(y_psolver.x(t))
138
-
139
- vx = x_psolver.dx(t)
140
- vy = y_psolver.dx(t)
141
- traj.v.append(math.hypot(vx, vy))
142
- traj.yaw.append(math.atan2(vy, vx))
143
-
144
- ax = x_psolver.ddx(t)
145
- ay = y_psolver.ddx(t)
146
- a = math.hypot(ax, ay)
147
- if len(traj.v) >= 2 and traj.v[-1] - traj.v[-2] < 0.0:
148
- a *= -1
149
- traj.a.append(a)
150
-
151
- jx = x_psolver.dddx(t)
152
- jy = y_psolver.dddx(t)
153
- j = math.hypot(jx, jy)
154
- if len(traj.a) >= 2 and traj.a[-1] - traj.a[-2] < 0.0:
155
- j *= -1
156
- traj.jerk.append(j)
157
-
158
- if max(np.abs(traj.a)) <= self.max_acc and \
159
- max(np.abs(traj.jerk)) <= self.max_jerk:
160
- return traj
161
- else:
162
- traj.clear()
163
-
164
- return traj
165
-
166
- # def run(self, points: list):
167
- # """
168
- # Running both generation and animation.
169
-
170
- # Parameters:
171
- # points (list[tuple]): path points
172
- # """
173
- # assert len(points) >= 2, "Number of points should be at least 2."
174
- # import matplotlib.pyplot as plt
175
-
176
- # # generate velocity and acceleration constraints heuristically
177
- # v = [0]
178
- # for i in range(len(points) - 1):
179
- # v.append(1.0)
180
-
181
- # a = [(v[i + 1] - v[i]) / 5 for i in range(len(points) - 1)]
182
- # a.append(0)
183
-
184
- # # generate curve
185
- # path_x, path_y, path_yaw = [], [], []
186
- # for i in range(len(points) - 1):
187
- # path = self.generation(
188
- # (points[i][0], points[i][1], np.deg2rad(points[i][2]), v[i], a[i]),
189
- # (points[i + 1][0], points[i + 1][1], np.deg2rad(points[i + 1][2]), v[i + 1], a[i + 1])
190
- # )
191
-
192
- # for j in range(path.size):
193
- # path_x.append(path.x[j])
194
- # path_y.append(path.y[j])
195
- # path_yaw.append(path.yaw[j])
196
-
197
- # # animation
198
- # plt.figure("curve generation")
199
-
200
- # # # static
201
- # # plt.plot(path_x, path_y, linewidth=2, c="#1f77b4")
202
- # # for x, y, theta in points:
203
- # # Plot.plotArrow(x, y, np.deg2rad(theta), 2, 'blueviolet')
204
-
205
- # # plt.axis("equal")
206
- # # plt.title(str(self))
207
-
208
- # # dynamic
209
- # plt.ion()
210
- # for i in range(len(path_x)):
211
- # plt.clf()
212
- # plt.gcf().canvas.mpl_connect('key_release_event',
213
- # lambda event: [exit(0) if event.key == 'escape' else None])
214
- # plt.plot(path_x, path_y, linewidth=2, c="#1f77b4")
215
- # for x, y, theta in points:
216
- # Plot.plotArrow(x, y, np.deg2rad(theta), 2, 'blueviolet')
217
- # Plot.plotCar(path_x[i], path_y[i], path_yaw[i], 1.5, 3, "black")
218
- # plt.axis("equal")
219
- # plt.title(str(self))
220
- # plt.draw()
221
- # plt.pause(0.001)
222
-
223
- # plt.show()
224
-
225
-
226
-