Class ChoreoEventTracker

java.lang.Object
com.marswars.auto.ChoreoEventTracker

public class ChoreoEventTracker extends Object
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 Details

    • ChoreoEventTracker

      public ChoreoEventTracker(String log_key, Supplier<Pose2d> robot_pose_supplier)
      Creates a new event tracker.
      Parameters:
      log_key - The base key for logging event information
      robot_pose_supplier - Supplier that provides the current robot pose
  • Method Details

    • setEvents

      public void setEvents(ChoreoTrajectory trajectory)
      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 events
      flip_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

      public Trigger getTimeTrigger(String event_name)
      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

      public Trigger 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. 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 on
      translation_tol - The translation distance tolerance in meters
      rotation_tol - The rotation tolerance in radians
      Returns:
      A Trigger that checks pose only
    • getEventPose

      public Pose2d getEventPose(String event_name)
      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

      public boolean hasEventBeenPassed(String event_name)
      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

      public double getEventTimestamp(String event_name)
      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

      public Map<String,Boolean> getEventPassedMap()
      Gets a copy of the event passed map.
      Returns:
      A map of event names to their passed state