Skip to main content

Overview

info

Anvil assumes that you are at least somewhat familiar with Roadrunner's TrajectorySequenceBuilders. The Anvil docs will only cover in detail special methods that the normal TrajectorySequenceBuilder API does not have. To learn more about TrajectorySequences & Roadrunner in general, check out learnroadrunner.com

Visual explanation of TrajectorySequences

tip

You can check out our codebase in TeamCode to see how Anvil is used in actual code & how it's used with other parts of Blacksmith

The majority code is in Kotlin, but many/most of the concepts remain the same.

Read the docs still though.

What is Anvil?

Anvil is a wrapper around Roadrunner v0.5.x's TrajectorySequenceBuilder that provides a much nicer API, providing utilities to heavily speed up both your auto and your development time!

Warning

Anvil does not yet support v1.0.0+. It's not battle tested and honestly 0.5.x works perfectly fine as is.

Features

  • Intuitive and cleaner methods for building and running TrajectorySequences

  • Implicit unit conversion- program your auto in any units you want by changing just a couple lines!

  • Trajectory generation is implicitly done in background threads unless otherwise specified

    • Trajectories normally take a while to create on the fly, so it slows down your auto when done in the main thread
    • Using background threads (or rather coroutines) prevents your auto from being bogged down when generating however many trajectories you'd like!
  • Works together with other parts of Blacksmith for even more conciseness and practicality

Example

BaseAuto.java
abstract class BaseAuto extends BlackOp {
@CreateOnGo // Using BlackOp's CreateOnGo for cleaner object creation
protected AutoBotComponents bot;

@CreateOnGo(passHwMap = true)
protected SampleMecanumDrive drive;

protected Pose2d startPose;
protected abstract Anvil mainTraj(Pose2d startPose);

@Override
public void go() {
Anvil startTraj = mainTraj(startPose);

// Easy way to set up the auto declaratively
Anvil
.startAutoWith(startTraj)
.onSchedulerLaunch();

// Using Scheduler to make life even easier
Scheduler.launchOnStart(this, () -> {
drive.update();
bot.update();
});
}
}
AutoDemo.java
@Autonomous
class AutoDemo extends BaseAuto {
public AutoDemo() {
// We can use GlobalUnits.pos() to create a Pose2d of our own desired units that
// automatically converts to inches/radians for us
startPose = GlobalUnits.pos(x, y, r);
}

@Override
protected Anvil mainTraj(Pose2d startPose) {
return Anvil.forgeTrajectory(drive, startPose)
.forward(10) // You can use any unit you want with GlobalUnits!
.addTemporalMarker(100, () -> {
/* Do something */
})
.back(10)
// parkTraj is implicitly make in a background thread
.thenRun(this::parkTraj);
}

private Anvil parkTraj(Pose2d startPose) {
/* Create and return parking trajectory */
}
}

Usage with MeepMeep

Anvil is pretty compatable with MeepMeep, I'd say the majority of Anvil methods work with MeepMeep (it works perfectly fine for me). You just have to build the TrajectorySequence manually

Also just pass in the DriveShim like normal instead of a SampleMecanumDrive

Confused?

Why are there two different auto files?

That's just how I like to organize my auto files- one BaseAuto class for all the common logic that all of the autos use, and separate files for each unique auto for their own paths.

You are, however, welcome to use Anvil with all your logic and stuff in a single class or however else you like and feel comfortabe with.

What is BlackOp or @CreateOnGo?

You don't need to use this, you can use LinearOpMode if you'd like, or even OpMode if you want to build and run the trajectories yourself (read for manual building/running) Check out this for more info

What are GlobalUnits?

You don't need to use this. Check out this for more info

Can I use this to just build a trajectory?

TODO()

What does '::' mean?

TODO()

What is AutoBotComponents?

It's just a class I made that keeps all of the motors and servos and stuff together in one class to keep it organized. You can do whatever you'd like, I just did this to make my code look cleaner.

What do all of those Anvil methods do?

Read the rest of the Anvil docs to find out.