Skip to content

Commit d116137

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents d4cb0f9 + 33f4b94 commit d116137

File tree

5 files changed

+115
-84
lines changed

5 files changed

+115
-84
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ target/
7070
.ipynb_checkpoints
7171

7272
matplotrecorder/*
73+
.vscode/settings.json

PathPlanning/Dijkstra/dijkstra.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, x, y, cost, pind):
3333
self.x = x # index of grid
3434
self.y = y # index of grid
3535
self.cost = cost
36-
self.pind = pind
36+
self.pind = pind # index of previous Node
3737

3838
def __str__(self):
3939
return str(self.x) + "," + str(self.y) + "," + str(self.cost) + "," + str(self.pind)
@@ -88,10 +88,10 @@ def planning(self, sx, sy, gx, gy):
8888
closedset[c_id] = current
8989

9090
# expand search grid based on motion model
91-
for i, _ in enumerate(self.motion):
92-
node = self.Node(current.x + self.motion[i][0],
93-
current.y + self.motion[i][1],
94-
current.cost + self.motion[i][2], c_id)
91+
for move_x, move_y, move_cost in self.motion:
92+
node = self.Node(current.x + move_x,
93+
current.y + move_y,
94+
current.cost + move_cost, c_id)
9595
n_id = self.calc_index(node)
9696

9797
if n_id in closedset:
@@ -124,11 +124,6 @@ def calc_final_path(self, ngoal, closedset):
124124

125125
return rx, ry
126126

127-
def calc_heuristic(self, n1, n2):
128-
w = 1.0 # weight of heuristic
129-
d = w * math.hypot(n1.x - n2.x, n1.y - n2.y)
130-
return d
131-
132127
def calc_position(self, index, minp):
133128
pos = index*self.reso+minp
134129
return pos

PathPlanning/DynamicWindowApproach/dynamic_window_approach.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def dwa_control(x, config, goal, ob):
2222

2323
dw = calc_dynamic_window(x, config)
2424

25-
u, trajectory = calc_final_input(x, dw, config, goal, ob)
25+
u, trajectory = calc_control_and_trajectory(x, dw, config, goal, ob)
2626

2727
return u, trajectory
2828

@@ -101,7 +101,7 @@ def calc_dynamic_window(x, config):
101101
x[4] - config.max_dyawrate * config.dt,
102102
x[4] + config.max_dyawrate * config.dt]
103103

104-
# [vmin,vmax, yaw_rate min, yaw_rate max]
104+
# [vmin, vmax, yaw_rate min, yaw_rate max]
105105
dw = [max(Vs[0], Vd[0]), min(Vs[1], Vd[1]),
106106
max(Vs[2], Vd[2]), min(Vs[3], Vd[3])]
107107

@@ -124,7 +124,7 @@ def predict_trajectory(x_init, v, y, config):
124124
return traj
125125

126126

127-
def calc_final_input(x, dw, config, goal, ob):
127+
def calc_control_and_trajectory(x, dw, config, goal, ob):
128128
"""
129129
calculation final input with dynamic window
130130
"""

PathPlanning/FrenetOptimalTrajectory/frenet_optimal_trajectory.py

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
import copy
1818
import math
1919
import cubic_spline_planner
20+
import sys
21+
import os
22+
23+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) +
24+
"/../QuinticPolynomialsPlanner/")
25+
26+
try:
27+
from quintic_polynomials_planner import QuinticPolynomial
28+
except ImportError:
29+
raise
30+
2031

2132
SIM_LOOP = 500
2233

@@ -44,50 +55,6 @@
4455
show_animation = True
4556

4657

47-
class quintic_polynomial:
48-
49-
def __init__(self, xs, vxs, axs, xe, vxe, axe, T):
50-
51-
# calc coefficient of quintic polynomial
52-
self.a0 = xs
53-
self.a1 = vxs
54-
self.a2 = axs / 2.0
55-
56-
A = np.array([[T**3, T**4, T**5],
57-
[3 * T ** 2, 4 * T ** 3, 5 * T ** 4],
58-
[6 * T, 12 * T ** 2, 20 * T ** 3]])
59-
b = np.array([xe - self.a0 - self.a1 * T - self.a2 * T**2,
60-
vxe - self.a1 - 2 * self.a2 * T,
61-
axe - 2 * self.a2])
62-
x = np.linalg.solve(A, b)
63-
64-
self.a3 = x[0]
65-
self.a4 = x[1]
66-
self.a5 = x[2]
67-
68-
def calc_point(self, t):
69-
xt = self.a0 + self.a1 * t + self.a2 * t**2 + \
70-
self.a3 * t**3 + self.a4 * t**4 + self.a5 * t**5
71-
72-
return xt
73-
74-
def calc_first_derivative(self, t):
75-
xt = self.a1 + 2 * self.a2 * t + \
76-
3 * self.a3 * t**2 + 4 * self.a4 * t**3 + 5 * self.a5 * t**4
77-
78-
return xt
79-
80-
def calc_second_derivative(self, t):
81-
xt = 2 * self.a2 + 6 * self.a3 * t + 12 * self.a4 * t**2 + 20 * self.a5 * t**3
82-
83-
return xt
84-
85-
def calc_third_derivative(self, t):
86-
xt = 6 * self.a3 + 24 * self.a4 * t + 60 * self.a5 * t**2
87-
88-
return xt
89-
90-
9158
class quartic_polynomial:
9259

9360
def __init__(self, xs, vxs, axs, vxe, axe, T):
@@ -164,7 +131,8 @@ def calc_frenet_paths(c_speed, c_d, c_d_d, c_d_dd, s0):
164131
for Ti in np.arange(MINT, MAXT, DT):
165132
fp = Frenet_path()
166133

167-
lat_qp = quintic_polynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
134+
# lat_qp = quintic_polynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
135+
lat_qp = QuinticPolynomial(c_d, c_d_d, c_d_dd, di, 0.0, 0.0, Ti)
168136

169137
fp.t = [t for t in np.arange(0.0, Ti, DT)]
170138
fp.d = [lat_qp.calc_point(t) for t in fp.t]

PathPlanning/QuinticPolynomialsPlanner/quintic_polynomials_planner.ipynb

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,112 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5+
"metadata": {},
56
"source": [
67
"# Quintic polynomials planner"
7-
],
8-
"metadata": {
9-
"collapsed": false
10-
}
8+
]
119
},
1210
{
1311
"cell_type": "markdown",
12+
"metadata": {},
1413
"source": [
1514
"## Quintic polynomials for one dimensional robot motion\n",
1615
"\n",
17-
"We assume a dimensional robot motion $x(t)$ at time $t$ is formulated as a quintic polynomials based on time as follows:\n",
16+
"We assume a one-dimensional robot motion $x(t)$ at time $t$ is formulated as a quintic polynomials based on time as follows:\n",
1817
"\n",
19-
"$x(t) = a_0+a_1t+a_2t^2+a_3t^3+a_4t^4$\n",
18+
"$x(t) = a_0+a_1t+a_2t^2+a_3t^3+a_4t^4+a_5t^5$ --(1)\n",
2019
"\n",
21-
"a_0, a_1. a_2, a_3 are parameters of the quintic polynomial.\n",
20+
"$a_0, a_1. a_2, a_3, a_4, a_5$ are parameters of the quintic polynomial.\n",
2221
"\n",
23-
"So, when time is 0,\n",
22+
"It is assumed that terminal states (start and end) are known as boundary conditions.\n",
23+
"\n",
24+
"Start position, velocity, and acceleration are $x_s, v_s, a_s$ respectively.\n",
2425
"\n",
25-
"$x(0) = a_0 = x_s$\n",
26+
"End position, velocity, and acceleration are $x_e, v_e, a_e$ respectively.\n",
2627
"\n",
27-
"$x_s$ is a start x position.\n",
28+
"So, when time is 0.\n",
2829
"\n",
29-
"Then, differentiating this equation with t, \n",
30+
"$x(0) = a_0 = x_s$ -- (2)\n",
3031
"\n",
31-
"$x'(t) = a_1+2a_2t+3a_3t^2+4a_4t^3$\n",
32+
"Then, differentiating the equation (1) with t, \n",
33+
"\n",
34+
"$x'(t) = a_1+2a_2t+3a_3t^2+4a_4t^3+5a_5t^4$ -- (3)\n",
3235
"\n",
3336
"So, when time is 0,\n",
3437
"\n",
35-
"$x'(0) = a_1 = v_s$\n",
38+
"$x'(0) = a_1 = v_s$ -- (4)\n",
3639
"\n",
37-
"$v_s$ is a initial speed for x axis.\n",
40+
"Then, differentiating the equation (3) with t again, \n",
3841
"\n",
39-
"=== TBD ==== \n"
40-
],
41-
"metadata": {
42-
"collapsed": false
43-
}
42+
"$x''(t) = 2a_2+6a_3t+12a_4t^2$ -- (5)\n",
43+
"\n",
44+
"So, when time is 0,\n",
45+
"\n",
46+
"$x''(0) = 2a_2 = a_s$ -- (6)\n",
47+
"\n",
48+
"so, we can calculate $a_0$, $a_1$, $a_2$ with eq. (2), (4), (6) and boundary conditions.\n",
49+
"\n",
50+
"$a_3, a_4, a_5$ are still unknown in eq(1).\n"
51+
]
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {},
56+
"source": [
57+
"We assume that the end time for a maneuver is $T$, we can get these equations from eq (1), (3), (5):\n",
58+
"\n",
59+
"$x(T)=a_0+a_1T+a_2T^2+a_3T^3+a_4T^4+a_5T^5=x_e$ -- (7)\n",
60+
"\n",
61+
"$x'(T)=a_1+2a_2T+3a_3T^2+4a_4T^3+5a_5T^4=v_e$ -- (8)\n",
62+
"\n",
63+
"$x''(T)=2a_2+6a_3T+12a_4T^2+20a_5T^3=a_e$ -- (9)\n"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"metadata": {},
69+
"source": [
70+
"From eq (7), (8), (9), we can calculate $a_3, a_4, a_5$ to solve the linear equations.\n",
71+
"\n",
72+
"$Ax=b$\n",
73+
"\n",
74+
"$\\begin{bmatrix} T^3 & T^4 & T^5 \\\\ 3T^2 & 4T^3 & 5T^4 \\\\ 6T & 12T^2 & 20T^3 \\end{bmatrix}\n",
75+
"\\begin{bmatrix} a_3\\\\ a_4\\\\ a_5\\end{bmatrix}=\\begin{bmatrix} x_e-x_s-v_sT-0.5a_sT^2\\\\ v_e-v_s-a_sT\\\\ a_e-a_s\\end{bmatrix}$\n",
76+
"\n",
77+
"We can get all unknown parameters now"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"## Quintic polynomials for two dimensional robot motion (x-y)\n",
85+
"\n",
86+
"If you use two quintic polynomials along x axis and y axis, you can plan for two dimensional robot motion in x-y plane.\n",
87+
"\n",
88+
"$x(t) = a_0+a_1t+a_2t^2+a_3t^3+a_4t^4+a_5t^5$ --(10)\n",
89+
"\n",
90+
"$y(t) = b_0+b_1t+b_2t^2+b_3t^3+b_4t^4+b_5t^5$ --(11)\n",
91+
"\n",
92+
"It is assumed that terminal states (start and end) are known as boundary conditions.\n",
93+
"\n",
94+
"Start position, orientation, velocity, and acceleration are $x_s, y_s, \\theta_s, v_s, a_s$ respectively.\n",
95+
"\n",
96+
"End position, orientation, velocity, and acceleration are $x_e, y_e. \\theta_e, v_e, a_e$ respectively.\n",
97+
"\n",
98+
"Each velocity and acceleration boundary condition can be calculated with each orientation.\n",
99+
"\n",
100+
"$v_{xs}=v_scos(\\theta_s), v_{ys}=v_ssin(\\theta_s)$\n",
101+
"\n",
102+
"$v_{xe}=v_ecos(\\theta_e), v_{ye}=v_esin(\\theta_e)$\n"
103+
]
104+
},
105+
{
106+
"cell_type": "code",
107+
"execution_count": null,
108+
"metadata": {},
109+
"outputs": [],
110+
"source": []
44111
}
45112
],
46113
"metadata": {
@@ -52,25 +119,25 @@
52119
"language_info": {
53120
"codemirror_mode": {
54121
"name": "ipython",
55-
"version": 2
122+
"version": 3
56123
},
57124
"file_extension": ".py",
58125
"mimetype": "text/x-python",
59126
"name": "python",
60127
"nbconvert_exporter": "python",
61-
"pygments_lexer": "ipython2",
62-
"version": "2.7.6"
128+
"pygments_lexer": "ipython3",
129+
"version": "3.7.5"
63130
},
64131
"pycharm": {
65132
"stem_cell": {
66133
"cell_type": "raw",
67-
"source": [],
68134
"metadata": {
69135
"collapsed": false
70-
}
136+
},
137+
"source": []
71138
}
72139
}
73140
},
74141
"nbformat": 4,
75-
"nbformat_minor": 0
76-
}
142+
"nbformat_minor": 1
143+
}

0 commit comments

Comments
 (0)