Package com.marswars.auto
Class ChoreoEventTracker
java.lang.Object
com.marswars.auto.ChoreoEventTracker
Tracks and manages Choreo trajectory event markers using a HashMap. This class maintains a map of
event names to their passed state and provides triggers that can be used to schedule commands
when events are reached.
-
Constructor Summary
ConstructorsConstructorDescriptionChoreoEventTracker(String log_key, Supplier<Pose2d> robot_pose_supplier) Creates a new event tracker. -
Method Summary
Modifier and TypeMethodDescriptionGets a copy of the event passed map.getEventPose(String event_name) Gets the pose associated with an event (the pose at the event's timestamp).doublegetEventTimestamp(String event_name) Gets the timestamp of a specific event.getPoseTrigger(String event_name, double translation_tol, double rotation_tol) Gets a trigger for the specified event that checks if the robot is at the event's pose.getTimeTrigger(String event_name) Gets a trigger for the specified event.booleanhasEventBeenPassed(String event_name) Checks if a specific event has been passed.voidsetEvents(ChoreoTrajectory trajectory) Sets the events for the current trajectory and resets all tracking state.voidstart()Starts tracking events.voidstop()Stops tracking events.voidupdate(double trajectory_time) Updates the tracker with the current trajectory time.
-
Constructor Details
-
ChoreoEventTracker
Creates a new event tracker.- Parameters:
log_key- The base key for logging event informationrobot_pose_supplier- Supplier that provides the current robot pose
-
-
Method Details
-
setEvents
Sets the events for the current trajectory and resets all tracking state. Creates a HashMap entry for each event, initialized to false (not passed).- Parameters:
trajectory- The trajectory containing the eventsflip_for_red- Whether to flip the trajectory for red alliance
-
update
public void update(double trajectory_time) Updates the tracker with the current trajectory time. Checks all events and marks them as passed if the current time has reached their timestamp.- Parameters:
trajectory_time- The current time in the trajectory (in seconds)
-
start
public void start()Starts tracking events. This should be called when trajectory following begins. -
stop
public void stop()Stops tracking events. This should be called when trajectory following ends. -
getTimeTrigger
Gets a trigger for the specified event. The trigger will be true from the moment the event timestamp is passed until the trajectory ends or a new trajectory is loaded.Use with .onTrue() for one-time actions or .whileTrue() for continuous actions.
- Parameters:
event_name- The name of the event to trigger on- Returns:
- A Trigger that reads from the event HashMap
-
getPoseTrigger
Gets a trigger for the specified event that checks if the robot is at the event's pose. This is a pose-only check (does not require time condition). The trigger will be true when the robot is within tolerances of the event's pose.- Parameters:
event_name- The name of the event to trigger ontranslation_tol- The translation distance tolerance in metersrotation_tol- The rotation tolerance in radians- Returns:
- A Trigger that checks pose only
-
getEventPose
Gets the pose associated with an event (the pose at the event's timestamp).- Parameters:
event_name- The name of the event- Returns:
- The pose at the event, or null if not found
-
hasEventBeenPassed
Checks if a specific event has been passed.- Parameters:
event_name- The name of the event to check- Returns:
- true if the event has been passed, false otherwise
-
getEventTimestamp
Gets the timestamp of a specific event.- Parameters:
event_name- The name of the event- Returns:
- The timestamp of the event, or -1 if not found
-
getEventPassedMap
Gets a copy of the event passed map.- Returns:
- A map of event names to their passed state
-