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)
- Java
- Kotlin
Anvil.forgeTrajectory(drive, startPose)
.forward(...)
.back(...)
.lineTo(...);
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.
- Java
- Kotlin
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);
}
fun mainTrajectory(startPose: Pose2d) =
Anvil.forgeTrajectory(drive, startPose)
.execute(::goToPole)
.execute(::awaitDeposit);
// Equivalent to:
// Anvil.forgeTrajectory(drive, startPose)
// .forwards(10)
// .turn(45)
// .addTemporalMarker() {
// lift.goToHigh()
// }
// .addTemporalMarker(.5) {
// claw.open()
// }
// .waitTime(1)
fun goToPole(anvil: Anvil) = anvil
.forwards(10)
.turn(45)
fun awaitDeposit(anvil: Anvil) = anvil
.addTemporalMarker() {
lift.goToHigh()
}
.addTemporalMarker(.5) {
claw.open()
}
.waitTime(1)
anvil.doTimes()
Performs the actions in the lambda 'x' times.
- Java
- Kotlin
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");
});
Anvil.forgeTrajectory(...)
// Lambda w/ receiver ofc
.doTimes(3) { iterationNum ->
// Keep in mind iterationNum starts from 0 (so it's 0, 1, 2 here)
forward(iterationNum * 3)
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")
}
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.
- Java
- Kotlin
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);
Anvil.forgeTrajectory(...)
// Lambda w/ receiver ofc
.inReverse {
anvil.forward(10);
anvil.splineTo(0, 0, 180)
}
// Equiv to:
Anvil.forgeTrajectory(...)
.setReversed(true)
.forward(10)
.splineTo(0, 0, 180)
.setReversed(false)
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);
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)
- Java
- Kotlin
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);
});
Anvil.forgeTrajectory(...)
.withRawBuilder<TrajectorySequenceBuilder> {
// 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)
}
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.
1
new AtomicInteger()