@@ -14,19 +14,87 @@ def longitudinal_plan(path : Path, acceleration : float, deceleration : float, m
1414 decelerate with accel = -deceleration until velocity goes to 0.
1515 """
1616 path_normalized = path .arc_length_parameterize ()
17+
1718 #TODO: actually do something to points and times
1819 points = [p for p in path_normalized .points ]
1920 times = [t for t in path_normalized .times ]
21+
22+ #=============================================
23+
24+ print ("-----LONGITUDINAL PLAN-----" )
25+ print ("path length: " , path .length ())
26+ length = path .length ()
27+
28+ # Starting point
29+ x0 = points [0 ][0 ]
30+ # Time to stop
31+ t_stop = current_speed / deceleration
32+ # Position to stop
33+ x_stop = x0 + current_speed * t_stop - 0.5 * deceleration * t_stop ** 2
34+
35+ # GEM will decelerate to 0 before the end of the path
36+ if length < 10.0 and x_stop > points [- 1 ][0 ]:
37+ new_points = []
38+ for t in times :
39+ if t <= t_stop :
40+ x = x0 + current_speed * t - 0.5 * deceleration * t ** 2
41+ # Keep the position after reaching 0 velocity
42+ else :
43+ x = x_stop
44+ new_points .append ([x , 0 ])
45+ points = new_points
46+ print ("[BRAKE] Computed points:" , points )
47+
48+ # GEM will accelerate to max speed before the end of the path
49+ else :
50+ new_points = []
51+ for t in times :
52+ # Accelerate to max speed
53+ if max_speed > current_speed :
54+ x = x0 + current_speed * t + 0.5 * acceleration * t ** 2
55+ # Keep the velocity after reaching max speed
56+ else :
57+ x = x0 + current_speed * t
58+ new_points .append ([x , 0 ])
59+ points = new_points
60+ print ("[ACCEL] Computed points:" , points )
61+
62+ #=============================================
63+
2064 trajectory = Trajectory (path .frame ,points ,times )
2165 return trajectory
2266
2367
2468def longitudinal_brake (path : Path , deceleration : float , current_speed : float ) -> Trajectory :
2569 """Generates a longitudinal trajectory for braking along a path."""
2670 path_normalized = path .arc_length_parameterize ()
71+
2772 #TODO: actually do something to points and times
2873 points = [p for p in path_normalized .points ]
2974 times = [t for t in path_normalized .times ]
75+
76+ #=============================================
77+
78+ print ("=====LONGITUDINAL BRAKE=====" )
79+ print ("path length: " , path .length ())
80+ length = path .length ()
81+
82+ x0 = points [0 ][0 ]
83+ t_stop = current_speed / deceleration
84+ x_stop = x0 + current_speed * t_stop - 0.5 * deceleration * t_stop ** 2
85+
86+ new_points = []
87+ for t in times :
88+ if t <= t_stop :
89+ x = x0 + current_speed * t - 0.5 * deceleration * t ** 2
90+ else :
91+ x = x_stop
92+ new_points .append ([x , 0 ])
93+ points = new_points
94+ print ("[BRAKE] Computed points:" , points )
95+
96+ #=============================================
97+
3098 trajectory = Trajectory (path .frame ,points ,times )
3199 return trajectory
32100
0 commit comments