File-By-File
PositionLocker

PositionLocker

This PathfinderPlugin allows you to lock the robot's odometry position, preventing it from drifting or changing. You can individually lock the X, Y, and Z (heading) components of the position. This plugin works by repeatedly calling Odometry.offsetSoPositionIs(PointXYZ) to force the robot's reported position to a desired value.

Key Concepts

  • Position Locking: The plugin ensures that the robot's reported position (X, Y, and/or Z) remains constant, even if the underlying odometry system reports movement.
  • Component-wise Locking: X, Y, and Z components can be locked independently.
  • Frequent Updates: The position is enforced three times per tick cycle (pre-tick, on-tick, and post-tick) to maintain accuracy.
  • Activation: The position lock is activated by setting the is_locked flag in Pathfinder's data map to true.

Fields

KEY_IS_LOCKED

A static String constant representing the key used in the Voyager data map to enable or disable the position lock. Its value is "is_locked".

Methods

PositionLocker()

Constructs a new PositionLocker instance. By default, all X, Y, and Z components are locked.

onLoad(Voyager voyager)

Called when the plugin is loaded. It stores the Voyager instance for later use.

getName()

Returns the name of the plugin, which is the simple class name of PositionLocker.

setPosition(PointXYZ position)

Sets the target PointXYZ that the robot's odometry will be locked to. Returns this for method chaining.

setLockX(boolean lockX)

Sets whether the X component of the position should be locked. Returns this for method chaining.

setLockY(boolean lockY)

Sets whether the Y component of the position should be locked. Returns this for method chaining.

setLockZ(boolean lockZ)

Sets whether the Z (heading) component of the position should be locked. Returns this for method chaining.

shouldEnsurePosition()

Private helper method. Checks if the position should be enforced based on whether a target position has been set and if the KEY_IS_LOCKED flag in the Voyager data map is true.

ensurePosition()

Private helper method. Applies the position lock by calling voyager.getOdometry().offsetSoPositionIs() with the appropriate locked and unlocked components.

preTick(Voyager voyager)

Called before each tick. If shouldEnsurePosition() is true, it calls ensurePosition().

onTick(Voyager voyager)

Called during each tick. If shouldEnsurePosition() is true, it calls ensurePosition().

postTick(Voyager voyager)

Called after each tick. If shouldEnsurePosition() is true, it calls ensurePosition().

setPositionLock(boolean isLocked)

Sets the is_locked flag in the Voyager data map to enable or disable the position lock. Returns this for method chaining.

lockPosition()

A convenience method to enable the position lock by setting KEY_IS_LOCKED to true.

unlockPosition()

A convenience method to disable the position lock by setting KEY_IS_LOCKED to false.