Skip to main content

Custom mappings

These are a collection of methods that aren't in the TrajectorySequenceBuilder, but they are really quite nice and useful.

All of these functions return the Anvil instance to allow for method chaining (like so)

Anvil.forgeTrajectory(drive, startPose)
.forward(...)
.back(...)
.lineTo(...);

anvil.execute()

A utility method for splitting up your trajectory into multiple methods without generating a whole new one. Applies the actions on the anvil instance that's passed in.

Useful for organizing the parts of your trajectory into their own little section allowing for cleaner and more reusable code.

Anvil mainTrajectory(Pose2d startPose) {
return Anvil.forgeTrajectory(drive, startPose)
.execute(this::goToPole)
.execute(this::awaitDeposit);

// Equivalent to:
// return Anvil.forgeTrajectory(drive, startPose)
// .forwards(10)
// .turn(45)
// .addTemporalMarker(() -> {
// lift.goToHigh();
// })
// .addTemporalMarker(.5, () -> {
// claw.open();
// })
// .waitTime(1);
}

Anvil goToPole(Anvil anvil) {
return anvil
.forwards(10)
.turn(45);
}

Anvil awaitDeposit(Anvil anvil) {
return anvil
.addTemporalMarker(() -> {
lift.goToHigh();
})
.addTemporalMarker(.5, () -> {
claw.open();
})
.waitTime(1);
}
Params
  • toExecute: (Anvil) -> Anvil - The function that transforms the given Anvil
  • anvil.doTimes()

    Performs the actions in the lambda 'x' times.

    Anvil.forgeTrajectory(...)
    .doTimes(3, (anvil, iterationNum) -> {
    // Keep in mind iterationNum starts from 0 (so it's 0, 1, 2 here)
    anvil.forward(iterationNum * 3);

    anvil.addTemporalMarker(() -> {
    telemetry.addLine("Hi " + iterationNum);
    });
    });

    // Equiv. to:

    Anvil.forgeTrajectory(...)
    .forward(0)
    .addTemporalMarker(() -> {
    telemetry.addLine("Hi 0");
    });
    .forward(10)
    .addTemporalMarker(() -> {
    telemetry.addLine("Hi 1");
    });
    .forward(20)
    .addTemporalMarker(() -> {
    telemetry.addLine("Hi 2");
    });
    Params
  • times: Number - The amount of times to do the given actions
  • pathsToDo: (Anvil, Int) -> Void - The actions to do. Consumes the anvil instance, as well as an int which is the current iteration number. Starts at 0
  • anvil.inReverse()

    Performs the actions in the lambda in reverse. Note that roadrunner can be a bit "unintuitive" for lack of a better phrase when it comes to reversing, I can not fix any quirks with this you may run in to.

    Anvil.forgeTrajectory(...)
    .inReverse((anvil) -> {
    anvil.forward(10);
    anvil.splineTo(0, 0, 180);
    });

    // Equiv to:

    Anvil.forgeTrajectory(...)
    .setReversed(true)
    .forward(10)
    .splineTo(0, 0, 180)
    .setReversed(false);
    Gotcha

    The following does not run the spline forwards like normal.

    .inReverse((anvil) -> {
    .inReverse((anvil) -> {
    anvil.splineTo(0, 0, 180);
    });
    });

    It is equivalent to the following, which, as you can see, is tautologous.

    anvil.setReversed(true)
    anvil.setReversed(true)
    anvil.splineTo(0, 0, 180);
    anvil.setReversed(false)
    anvil.setReversed(false);
    Params
  • pathsToDoInReverse: (Anvil) -> Void - The paths to do in reverse
  • anvil.setPoseEstimateNow()

    Just does sampleMecanumDrive.setPoseEstimate(pose2d). That's it. Nothing special about it.

    anvil.setPoseEstimateInTemporalMarker()

    Equivalent to-

    UNSTABLE_addTemporalMarker(0, () -> {
    sampleMecanumDrive.setPoseEstimate(pose2d);
    });

    anvil.noop()

    Does nothing and just returns itself. Literally. Like, it does absolutely nothing.

    Anvil.forgeTrajectory(...)
    .forward(10)
    .noop() // Does nothing
    .back(10);

    ok you might be wondering why this may exist so uh [TODO write & link page about how Anvil works] also can be useful if using something like 'doInReverse()'

    Also, if you're in Kotlin, you can just use it as noop (i.e. as a property accessor instead of a function)

    anvil.withRawBuilder()

    This is a very niche one, but it basically just allows you to access the raw TrajectorySequenceBuilder and use it directly there instead of interacting with it through Anvil.

    Directly using the raw TrajectorySequenceBuilder does not auto convert units for you or anything. It allows you to access methods that Anvil doesn't support as well.

    Usage example- (Note that you need to pass in the class in the <>s)

    Anvil.forgeTrajectory(...)
    .<TrajectorySequenceBuilder>withRawBuilder((builder) -> {
    // Allows you to access methods Anvil doesn't support
    // 10 is in inches, the unit is not autoconverted if it's set to cm or something
    builder.forward(10, velConstraint, accelConstraint);
    });
    Params
  • <T> - The TrajectorySequenceBuilder class
  • builder: (T) -> Unit - The lambda that accepts and modifies the raw TrajectorySequenceBuilder
  • anvil.doInReverse()

    Pops the last thing(s) off the builder deque and reverses it. Can be finicky, please don't use if you don't understand the basics of how Anvil works under the hood or you may shoot yourself in the foot.

    Params
  • numThingsToPop: Int - max # of things to pop, if size of deque < n, it pops the entire deque
    - Defaults to: 1
  • numThingsPopped: AtomicInteger - You can optionally pass in an AtomicInteger that'll be set to the # of things popped if really you want to know for whatever reason
    - Defaults to: new AtomicInteger()