66from GEMstack .state import Path , ObjectFrameEnum
77from GEMstack .onboard .planning .longitudinal_planning import longitudinal_plan ,longitudinal_brake
88import matplotlib .pyplot as plt
9-
9+
10+
11+ mode = "milestone" # milestone, dt, dx
12+
13+
1014def test_longitudinal_planning ():
1115 test_path = Path (ObjectFrameEnum .START ,[(0 ,0 ),(1 ,0 ),(2 ,0 ),(3 ,0 ),(4 ,0 ),(5 ,0 ),(6 ,0 )])
1216 test_path2 = Path (ObjectFrameEnum .START ,[(5 ,0 ),(6 ,1 ),(7 ,2 ),(9 ,4 )])
@@ -39,7 +43,7 @@ def test_longitudinal_planning():
3943 plt .ylabel ('velocity' )
4044 plt .show ()
4145
42- test_traj = longitudinal_plan (test_path , 1.1 , 2.0 , 3.0 , 0.0 )
46+ test_traj = longitudinal_plan (test_path , 1.1 , 2.0 , 3.0 , 0.0 , mode )
4347 assert (t1 < t2 for (t1 ,t2 ) in zip (test_traj .times [:- 1 ],test_traj .times [1 :]) )
4448 plt .plot (test_traj .times ,[p [0 ] for p in test_traj .points ])
4549 plt .title ("Accelerating from 0 m/s" )
@@ -54,7 +58,7 @@ def test_longitudinal_planning():
5458 plt .show ()
5559
5660
57- test_traj = longitudinal_plan (test_path , 1.0 , 2.0 , 3.0 , 2.0 )
61+ test_traj = longitudinal_plan (test_path , 1.0 , 2.0 , 3.0 , 2.0 , mode )
5862 assert (t1 < t2 for (t1 ,t2 ) in zip (test_traj .times [:- 1 ],test_traj .times [1 :]) )
5963 plt .plot (test_traj .times ,[p [0 ] for p in test_traj .points ])
6064 plt .title ("Accelerating from 2 m/s" )
@@ -69,7 +73,7 @@ def test_longitudinal_planning():
6973 plt .show ()
7074
7175
72- test_traj = longitudinal_plan (test_path , 0.0 , 2.0 , 3.0 , 3.1 )
76+ test_traj = longitudinal_plan (test_path , 0.0 , 2.0 , 3.0 , 3.1 , mode )
7377 assert (t1 < t2 for (t1 ,t2 ) in zip (test_traj .times [:- 1 ],test_traj .times [1 :]) )
7478 plt .plot (test_traj .times ,[p [0 ] for p in test_traj .points ])
7579 plt .title ("Keeping constant velocity at 3.1 m/s" )
@@ -83,7 +87,7 @@ def test_longitudinal_planning():
8387 plt .ylabel ('velocity' )
8488 plt .show ()
8589
86- test_traj = longitudinal_plan (test_path , 2.0 , 2.0 , 20.0 , 10.0 )
90+ test_traj = longitudinal_plan (test_path , 2.0 , 2.0 , 20.0 , 10.0 , mode )
8791 assert (t1 < t2 for (t1 ,t2 ) in zip (test_traj .times [:- 1 ],test_traj .times [1 :]) )
8892 plt .plot (test_traj .times ,[p [0 ] for p in test_traj .points ])
8993 plt .title ("Too little time to stop, starting at 10 m/s" )
@@ -110,7 +114,7 @@ def test_longitudinal_planning():
110114 plt .ylabel ('velocity' )
111115 plt .show ()
112116
113- test_traj = longitudinal_plan (test_path2 , 1.0 , 2.0 , 3.0 , 0.0 )
117+ test_traj = longitudinal_plan (test_path2 , 1.0 , 2.0 , 3.0 , 0.0 , mode )
114118 plt .plot (test_traj .times ,[p [0 ] for p in test_traj .points ])
115119 plt .title ("Nonuniform planning" )
116120 plt .xlabel ('time' )
0 commit comments