File-By-File
Voyager

Voyager

The Voyager class is the highest-level interface for interacting with the Pathfinder library. It provides comprehensive control over your robot's movement, whether in autonomous or manual modes.

Key Concepts

To effectively use Voyager, it's important to understand the following core concepts:

  • Trajectory: Represents a predefined path or motion profile for the robot to follow.
  • Translation: Describes a change in position in 2D or 3D space.
  • PointXY/PointXYZ: Represents a point in 2D (X, Y) or 3D (X, Y, Z) coordinates.
  • Angle: Represents an angular measurement, crucial for robot orientation.

The tick() method is essential for the operation of Pathfinder and should be called as frequently as possible.

"God Class" Design

Voyager is intentionally designed as a "god class" to facilitate method chaining, making it incredibly easy and effective to perform various operations on your robot. You can access smaller components of Pathfinder through its getter methods:

  • getDataMap(): Provides access to a map for inter-class communication.
  • getOdometry(): Returns the robot's odometry system for position tracking.
  • getDrive(): Returns the robot's drive system for movement commands.
  • getExecutorManager(): Manages the execution of robot tasks.
  • getPluginManager(): Manages Pathfinder plugins.

Many of these features can be disabled using "minimal mode" for performance-critical applications.

Global Trajectory Map

Pathfinder includes a global trajectory map that allows you to reference trajectories using a String key. This is convenient for accessing trajectories globally.

  • getTrajectoryMap(): Returns the Map<String, Trajectory> of globally accessible trajectories.
  • getStackTraceMap(): Returns a Map<String, String> that stores the stack trace of where each trajectory was added, useful for debugging naming conflicts.

Minimal Mode

"Minimal mode" is a feature designed to reduce Pathfinder's footprint by skipping the ticking of optional services, managers, and listeners. While it can improve performance, it restricts Pathfinder's capabilities. It's recommended only when performance is absolutely critical.

  • setIsMinimal(boolean): Sets whether Pathfinder should operate in minimal mode.

Constructors

Voyager offers several constructors to accommodate different initialization needs:

  • Voyager(Robot robot, FollowerGenerator generator, Controller turnController, String... doNotLoad): The most comprehensive constructor, allowing you to specify a robot, follower generator, turn controller, and a list of plugins to exclude from automatic loading.
  • Voyager(Robot robot, FollowerGenerator generator, Controller turnController): A simplified constructor that automatically loads all auto-load plugins.
  • Voyager(Robot robot, FollowerGenerator generator): Automatically extracts the turn controller from the provided FollowerGenerator.
  • Voyager(Robot robot, Controller turnController): Uses a GenericFollowerGenerator with the provided turn controller.
  • Voyager(Robot robot, double coefficient): Uses a ProportionalController with the given coefficient as the turn controller.

Static Methods

  • addAutoLoadPlugin(PathfinderPlugin plugin): Adds a plugin to Pathfinder's list of automatically loading plugins.
  • addTrajectory(String group, String name, Trajectory trajectory): Adds a Trajectory to the global trajectory map with a specified group and name.
  • addTrajectory(Class<?> clazz, String name, Trajectory trajectory): Adds a Trajectory to the global trajectory map, using the class name as the group.
  • removeTrajectory(String trajectoryName): Removes a Trajectory from the global trajectory map by its name.
  • removeTrajectory(String group, String name): Removes a Trajectory from the global trajectory map by its group and name.
  • removeTrajectory(Class<?> clazz, String name): Removes a Trajectory from the global trajectory map by its class and name.
  • getTrajectory(String group, String name): Retrieves a Trajectory from the global trajectory map by its group and name.
  • getTrajectory(Class<?> clazz, String name): Retrieves a Trajectory from the global trajectory map by its class and name.
  • clearTrajectoryMap(): Clears Pathfinder's global trajectory map.
  • getTrajectoryMap(): Returns the global trajectory map.
  • getStackTraceMap(): Returns the global stack trace map for debugging.

Instance Methods

  • setIsMinimal(boolean isMinimal): Sets whether Pathfinder should run in minimal mode.
  • getDataMap(): Returns Pathfinder's data map.
  • putData(String key, Object object): Adds data to Pathfinder's data map.
  • getData(String key): Retrieves data from Pathfinder's data map.
  • getDataPointXY(String key): Retrieves and casts data to PointXY.
  • getDataPointXYZ(String key): Retrieves and casts data to PointXYZ.
  • getDataAngle(String key): Retrieves and casts data to Angle.
  • getDataString(String key): Retrieves and casts data to String.
  • loadPlugin(PathfinderPlugin plugin): Loads a PathfinderPlugin.
  • loadBundledPlugins(): Loads all plugins bundled with Pathfinder (e.g., StatTracker, PositionLocker).
  • getRobot(): Returns the Robot instance.
  • getOdometry(): Returns the Odometry system.
  • getDrive(): Returns the Drive system.
  • getSpeed(): Gets the speed for linear trajectory generation.
  • setSpeed(double speed): Sets the speed for linear trajectory generation.
  • getTolerance(): Gets the tolerance for linear trajectory generation.
  • setTolerance(double tolerance): Sets the tolerance for linear trajectory generation.
  • getAngleTolerance(): Gets the angle tolerance for linear trajectory generation.
  • setAngleTolerance(Angle angleTolerance): Sets the angle tolerance for linear trajectory generation.
  • getZoneProcessor(): Returns the ZoneProcessor instance.
  • addZone(String name, Zone zone): Adds a zone to the ZoneProcessor.
  • removeZone(String name): Removes a zone from the ZoneProcessor.
  • ticksPerSecond(): Returns Pathfinder's ticks per second (requires StatTracker plugin).
  • getPluginManager(): Returns Pathfinder's plugin manager.
  • onTick(String name, Consumer<Voyager> onTick): Binds an operation to be executed after every tick().
  • onTick(Consumer<Voyager> onTick): Binds an operation to be executed after every tick() with a random name.
  • onTick(Runnable onTick): Binds a Runnable operation to be executed after every tick().
  • removeOnTick(String name): Removes an on-tick operation.
  • tick(): "Ticks" Pathfinder once, causing it to update its state and move the robot. This method is crucial for Pathfinder's operation.
  • tickFor(double timeMs): Ticks Pathfinder for a specified duration in milliseconds, blocking the current thread.
  • tickUntil(TickConfig config): Ticks Pathfinder according to a TickConfig.
  • tickUntil(): Ticks Pathfinder until the current path is finished.
  • tickUntil(double timeoutMs): Ticks Pathfinder until the current path is finished or a timeout is reached.
  • tickUntil(Supplier<Boolean> shouldContinueRunning): Ticks Pathfinder while a condition is true.
  • tickUntil(double timeoutMs, Supplier<Boolean> shouldContinueRunning): Ticks Pathfinder while a condition is true and within a timeout.
  • tickUntil(Supplier<Boolean> shouldContinueRunning, Consumer<Voyager> onTick): Ticks Pathfinder while a condition is true, executing a consumer after each tick.
  • tickUntil(double timeoutMs, Supplier<Boolean> shouldContinueRunning, Consumer<Voyager> onTick): Ticks Pathfinder while a condition is true and within a timeout, executing a consumer after each tick.
  • tickUntil(Supplier<Boolean> shouldContinueRunning, double timeoutMs): Ticks Pathfinder while a condition is true and within a timeout.
  • tickUntil(double timeoutMs, Supplier<Boolean> shouldContinueRunning, BiConsumer<Voyager, Double> onTick): Ticks Pathfinder while a condition is true and within a timeout, executing a bi-consumer after each tick with elapsed time.
  • tickUntil(BiConsumer<Voyager, Double> onTick): Continually ticks Pathfinder until the current path is finished, executing a bi-consumer after each tick with elapsed time.
  • tickUntil(double timeoutMs, Predicate<Voyager> isValid): Ticks Pathfinder while a predicate is true and within a timeout.
  • tickUntil(double timeoutMs, Supplier<Boolean> shouldContinueRunning, Predicate<Voyager> isValid): Ticks Pathfinder while multiple conditions are true and within a timeout.
  • andThen(Consumer<Voyager> onCompletion): Executes a callback after the current path is finished.
  • andThen(Consumer<Voyager> onCompletion, double timeoutMs): Executes a callback after the current path is finished or a timeout is reached.
  • andThen(Consumer<Voyager> onCompletion, Supplier<Boolean> shouldContinueRunning): Executes a callback after the current path is finished or a condition becomes false.
  • andThen(Consumer<Voyager> onCompletion, double timeoutMs, Supplier<Boolean> shouldContinueRunning): Executes a callback after the current path is finished, a timeout is reached, or a condition becomes false.
  • andThen(Consumer<Voyager> onCompletion, double timeoutMs, Supplier<Boolean> shouldContinueRunning, BiConsumer<Voyager, Double> onTick): Executes a callback after the current path is finished, a timeout is reached, or a condition becomes false, executing a bi-consumer after each tick.
  • asLongAs(double maximumTimeMs, Supplier<Boolean> condition, Runnable action): Executes a Runnable action repeatedly as long as a condition is true and within a maximum time.
  • asLongAs(double maximumTimeMs, Predicate<Voyager> predicate, Runnable action): Executes a Runnable action repeatedly as long as a predicate is true and within a maximum time.
  • asLongAs(Supplier<Boolean> condition, Runnable action): Executes a Runnable action repeatedly as long as a condition is true.
  • asLongAs(Predicate<Voyager> predicate, Runnable action): Executes a Runnable action repeatedly as long as a predicate is true.
  • waitUntil(Supplier<Boolean> condition): Pauses the current thread until a condition is met.
  • waitUntil(double timeoutMs): Pauses the current thread for a specified duration.
  • waitUntil(Supplier<Boolean> condition, double maxTimeMs): Pauses the current thread until a condition is met or a maximum time is reached.
  • waitAsLongAs(Supplier<Boolean> condition): Pauses the current thread as long as a condition is true.
  • waitAsLongAs(Supplier<Boolean> condition, double maxTime): Pauses the current thread as long as a condition is true and within a maximum time.
  • followTrajectory(String group, String name): Follows a trajectory from the global trajectory map by group and name.
  • followTrajectory(Class<?> group, String name): Follows a trajectory from the global trajectory map by class and name.
  • followTrajectory(final String trajectoryName): Follows a trajectory from the global trajectory map by name.