Skip to content

Commit 16dcdb4

Browse files
committed
add yaw smooth function
1 parent 3e85a36 commit 16dcdb4

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

PathTracking/model_predictive_speed_and_steer_control/model_predictive_speed_and_steer_control.py

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def check_goal(state, goal, tind, nind):
365365
return False
366366

367367

368-
def do_simulation(cx, cy, cyaw, ck, sp, dl):
368+
def do_simulation(cx, cy, cyaw, ck, sp, dl, initial_state):
369369
"""
370370
Simulation
371371
@@ -379,7 +379,14 @@ def do_simulation(cx, cy, cyaw, ck, sp, dl):
379379
"""
380380

381381
goal = [cx[-1], cy[-1]]
382-
state = State(x=cx[0], y=cy[0], yaw=cyaw[0], v=0.0)
382+
383+
state = initial_state
384+
385+
# initial yaw compensation
386+
if state.yaw - cyaw[0] >= math.pi:
387+
state.yaw -= math.pi * 2.0
388+
elif state.yaw - cyaw[0] <= -math.pi:
389+
state.yaw += math.pi * 2.0
383390

384391
time = 0.0
385392
x = [state.x]
@@ -494,6 +501,15 @@ def get_straight_course(dl):
494501
return cx, cy, cyaw, ck
495502

496503

504+
def get_straight_course2(dl):
505+
ax = [0.0, -10.0, -20.0, -40.0, -50.0, -60.0, -70.0]
506+
ay = [0.0, -1.0, 1.0, 0.0, -1.0, 1.0, 0.0]
507+
cx, cy, cyaw, ck, s = cubic_spline_planner.calc_spline_course(
508+
ax, ay, ds=dl)
509+
510+
return cx, cy, cyaw, ck
511+
512+
497513
def get_forward_course(dl):
498514
ax = [0.0, 60.0, 125.0, 50.0, 75.0, 30.0, -10.0]
499515
ay = [0.0, 0.0, 50.0, 65.0, 30.0, 50.0, -20.0]
@@ -526,12 +542,49 @@ def main():
526542

527543
dl = 1.0 # course tick
528544
# cx, cy, cyaw, ck = get_straight_course(dl)
545+
# cx, cy, cyaw, ck = get_straight_course2(dl)
529546
# cx, cy, cyaw, ck = get_forward_course(dl)
530547
cx, cy, cyaw, ck = get_switch_back_course(dl)
531548

532549
sp = calc_speed_profile(cx, cy, cyaw, TARGET_SPEED)
533550

534-
t, x, y, yaw, v, d, a = do_simulation(cx, cy, cyaw, ck, sp, dl)
551+
initial_state = State(x=cx[0], y=cy[0], yaw=cyaw[0], v=0.0)
552+
553+
t, x, y, yaw, v, d, a = do_simulation(
554+
cx, cy, cyaw, ck, sp, dl, initial_state)
555+
556+
if show_animation:
557+
plt.close("all")
558+
plt.subplots()
559+
plt.plot(cx, cy, "-r", label="spline")
560+
plt.plot(x, y, "-g", label="tracking")
561+
plt.grid(True)
562+
plt.axis("equal")
563+
plt.xlabel("x[m]")
564+
plt.ylabel("y[m]")
565+
plt.legend()
566+
567+
plt.subplots()
568+
plt.plot(t, v, "-r", label="speed")
569+
plt.grid(True)
570+
plt.xlabel("Time [s]")
571+
plt.ylabel("Speed [kmh]")
572+
573+
plt.show()
574+
575+
576+
def main2():
577+
print(__file__ + " start!!")
578+
579+
dl = 1.0 # course tick
580+
cx, cy, cyaw, ck = get_straight_course2(dl)
581+
582+
sp = calc_speed_profile(cx, cy, cyaw, TARGET_SPEED)
583+
584+
initial_state = State(x=cx[0], y=cy[0], yaw=math.pi, v=0.0)
585+
586+
t, x, y, yaw, v, d, a = do_simulation(
587+
cx, cy, cyaw, ck, sp, dl, initial_state)
535588

536589
if show_animation:
537590
plt.close("all")
@@ -555,3 +608,4 @@ def main():
555608

556609
if __name__ == '__main__':
557610
main()
611+
# main2()

PathTracking/model_predictive_speed_and_steer_control/notebook.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"# Linear vehicle model\n",
21+
"# Vehicle model linearization\n",
2222
"\n",
2323
"State vector is:\n",
2424
"$$ x = [x, y, v,\\phi]$$ x: x-position, y:y-position, v:velocity, φ: yaw angle\n",
2525
"\n",
2626
"Input vector is:\n",
27-
"$$ u = [a, \\delta]$$ a: accellation, δ: steering angle\n"
27+
"$$ u = [a, \\delta]$$ a: accellation, δ: steering angle\n",
28+
"\n",
29+
"Vehicle model is \n",
30+
"$$ \\dot{x} = vcos(\\phi)$$\n",
31+
"$$ \\dot{y} = vsin((\\phi)$$\n",
32+
"$$ \\dot{v} = a$$\n",
33+
"$$ \\dot{\\phi} = \\frac{vtan(\\delta)}{L}$$"
2834
]
2935
},
3036
{

tests/test_model_predictive_speed_and_steer_control.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ class Test(TestCase):
1313
def test1(self):
1414
m.show_animation = False
1515
m.main()
16+
m.main2()

0 commit comments

Comments
 (0)