Skip to content

Commit a146a92

Browse files
committed
Synced trajectory planners different use cases
1 parent 28eaf4c commit a146a92

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

GEMstack/onboard/planning/trajectory_planning_component.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,4 +683,69 @@ def update(self, state: AllState):
683683
if DEBUG:
684684
print('[DEBUG] Current Velocity of the Car: LOOK!', curr_v, self.desired_speed)
685685
print("[DEBUG] YieldTrajectoryPlanner.update: Returning trajectory with", len(traj.points), "points.")
686+
return traj
687+
688+
689+
690+
class SplinePlanner(Component):
691+
"""Follows route by smoothing coarse waypoints into a quintic spline."""
692+
def __init__(self):
693+
super().__init__()
694+
self.route_progress = None
695+
self.t_last = None
696+
697+
# how far ahead to plan (m), and sampling speed & dt
698+
self.lookahead_dist = 10.0
699+
self.v_des = 2.0
700+
self.dt = 0.02
701+
702+
# the spline engine
703+
self._spline = QuinticHermiteSplinePlanner(self.v_des, self.dt)
704+
705+
def state_inputs(self):
706+
return ['all']
707+
708+
def state_outputs(self):
709+
return ['trajectory']
710+
711+
def rate(self):
712+
return 10.0 # Hz
713+
714+
def update(self, state: AllState) -> Trajectory:
715+
t = state.t
716+
if self.t_last is None:
717+
self.t_last = t
718+
719+
# keep route_progress up to date
720+
veh = state.vehicle
721+
curr = np.array([veh.pose.x, veh.pose.y])
722+
723+
if self.route_progress is None:
724+
self.route_progress = 0.0
725+
_, new_param = state.route.closest_point_local(
726+
curr.tolist(),
727+
(self.route_progress - 5.0,
728+
self.route_progress + 5.0)
729+
)
730+
self.route_progress = new_param
731+
732+
# extract a look-ahead segment from the route
733+
seg: Path = state.route.trim(
734+
self.route_progress,
735+
self.route_progress + self.lookahead_dist
736+
)
737+
738+
pts_raw: List[List[float]] = [
739+
list(pt) for pt in seg.points
740+
]
741+
742+
spline_pts, spline_times = self._spline.build(pts_raw)
743+
744+
traj = Trajectory(
745+
frame = seg.frame,
746+
points = spline_pts.tolist(),
747+
times = spline_times.tolist()
748+
)
749+
750+
self.t_last = t
686751
return traj

0 commit comments

Comments
 (0)