HolonomicVectorDriveTask

Gamepad drive for all holonomic drivetrains which will use a vector-based approach to drive. This task is designed to be used as a default/standard-priority task, other tasks will override it.

Compared to HolonomicDriveTask, this task will constantly track the (x,y,r) pose of the robot, rather than setting the powers directly from the gamepad inputs. When the translational/rotational components for these poses are zero, this task will take a snapshot of the values they were at, using PID controllers to attempt to stay in place. This allows for more predictable and consistent driving, as the robot will only accept movement when told to do so, ensuring that all movements of the robot can only be achieved via the controller.

This system can be comparable to one of a drone, where releasing the sticks and allowing it to hover will hold position and resist external forces. This locking nature has been implemented on the vector (translation) and heading components. Note that user input overrides all, where the x or y inputs will both unlock both translational axes to avoid corrections that could be dangerous. This caveat means that this task will make no effort to try and correct translational deviation when the robot is being commanded.

A RoadRunner drive is required for this class, as it will require the use of the pose estimate system and other coefficients such as your PID. Therefore, the only supported class this task will work for is MecanumDrive.

Author

Lucas Bubner, 2024

Since

4.0.0

Constructors

Link copied to clipboard
constructor(xSupplier: Supplier<Float>, ySupplier: Supplier<Float>, rSupplier: Supplier<Float>, @NotNull mecanumDrive: MecanumDrive, fieldCentricEnabled: BooleanSupplier)
Constructor for HolonomicVectorDriveTask.
constructor(driver: Gamepad, @NotNull mecanumDrive: MecanumDrive, fieldCentricEnabled: BooleanSupplier)
Constructor for HolonomicVectorDriveTask using a default Mecanum binding.

Inherited properties

Link copied to clipboard
Link copied to clipboard

Timeout value for an infinite task that will run forever.

Link copied to clipboard
protected val opMode: BunyipsOpMode
Link copied to clipboard

Whether the task is finished or not via timeout or custom condition. Will be true regardless of the finisher being fired or not, as some tasks will handle this via finishNow().

Link copied to clipboard
open var timeout: Measure<Time>

Functions

Link copied to clipboard
protected open fun init()
Define code to run once, when the task is started.
Link copied to clipboard
protected open fun onFinish()
Finalising function to run once the task is finished.
Link copied to clipboard
protected open fun periodic()
To run as an active loop during this task's duration.
Link copied to clipboard
open fun setHeadingTarget(heading: Measure<Angle>)
Set a manual heading that this task should lock to, much as if the robot were rotated to this position and is to try and hold rotation.
Link copied to clipboard
open fun setVectorTarget(forwardX: Measure<Distance>, strafeY: Measure<Distance>)
Set a manual target that this task should lock to, much as if the robot was moved here and is to try and hold position here.
Link copied to clipboard
Set the rotational PID coefficients.
Link copied to clipboard
Set the pose stabilisation timeout before locking the pose vectors for correction.
Link copied to clipboard
open fun withTolerance(inchRad: Pose2d): HolonomicVectorDriveTask
Set the minimum pose error when in self-holding mode to activate correction for.
Link copied to clipboard
Set the translational PID coefficients.

Inherited functions

Link copied to clipboard
fun finish()

Tell a task to finish on the next iteration.

Link copied to clipboard
fun finishNow()

Force a task to finish immediately, and fire the onFinish() method without waiting for the next polling loop. This method is useful when your task needs to die and needs to finish up immediately. If your finisher has already been fired, this method will do nothing but ensure that the task is marked as finished.

Link copied to clipboard

Time in seconds since the task was started.

Link copied to clipboard

Get the subsystem reference that this task has elected a dependency on. Will return an Optional where if it is not present, this task is not dependent on any subsystem.

Link copied to clipboard

Return whether this task has elected a dependency on a subsystem or not.

Link copied to clipboard

Query (but not update) the finished state of the task. This will return true if the task is finished and the finisher has been fired.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
protected fun isTaskFinished(): Boolean
Return a boolean to this method to add custom criteria if a task should be considered finished.
protected abstract fun isTaskFinished(): Boolean

Return a boolean to this method to add custom criteria if a task should be considered finished.

Link copied to clipboard
protected open fun onInterrupt()

Finalising function that will be called after onFinish in the event this task is finished via a call to finish or finishNow. Override to add your own callback.

Link copied to clipboard
protected open fun onReset()

Called when the task is resetting now. Override this method to add custom reset behaviour, such as resetting any internal state variables such as iterators or lists.

Link copied to clipboard
open fun onSubsystem(subsystem: BunyipsSubsystem, override: Boolean): Task

Set the subsystem you want to elect this task to run on, notifying the runner that this task should run there.

Link copied to clipboard

Update and query the state of the task if it is finished. This will return true if the task is finished and the finisher has been fired.

Link copied to clipboard
fun reset()

Reset a task to an uninitialised and unfinished state. Will no-op if the task is already fully reset.

Link copied to clipboard
abstract fun run()

fun run()

Should be called by your polling loop to run the task and manage all state properly.

Link copied to clipboard

Get the name of this task. By default, it will be the class simple name, but you can call withName to set a custom name.

Link copied to clipboard

Get a verbose string representation of this task, including all of its properties.

Link copied to clipboard

Mute task reports from the Scheduler.

Link copied to clipboard
open fun withName(name: String): Task

Set the name of this task to be displayed in the OpMode. You may override this method if required to enforce a naming convention/prefix.

Link copied to clipboard
fun withTimeout(timeout: Measure<Time>): Task

Set the timeout of this task dynamically and return the task.