Skip to content

Instantly share code, notes, and snippets.

@TheOutcastVirus
Created December 6, 2023 06:56
Show Gist options
  • Save TheOutcastVirus/81313e5a636d9ecc8af9da2b12737547 to your computer and use it in GitHub Desktop.
Save TheOutcastVirus/81313e5a636d9ecc8af9da2b12737547 to your computer and use it in GitHub Desktop.
Example of RR Async Trajectories in use
package org.firstinspires.ftc.teamcode.autonomous;
import com.acmerobotics.dashboard.config.Config;
import com.acmerobotics.roadrunner.geometry.Pose2d;
import com.acmerobotics.roadrunner.geometry.Vector2d;
import com.acmerobotics.roadrunner.trajectory.Trajectory;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import org.firstinspires.ftc.teamcode.modules.drive.SampleMecanumDrive;
@Config
@Autonomous(name = "Async Example Autoop", group = "16481-Example")
public class AsyncExampleAutoop extends LinearOpMode {
Trajectory trajectory1;
Trajectory trajectory2;
Trajectory trajectory3;
@Override
public void runOpMode() {
SampleMecanumDrive drive = new SampleMecanumDrive(hardwareMap);
trajectory1 = drive.trajectoryBuilder(new Pose2d())
.lineTo(new Vector2d())
.addDisplacementMarker(() -> drive.followTrajectoryAsync(trajectory2))
// Basically just tells RR to follow the next trajectory at the end of this one
.build();
trajectory2 = drive.trajectoryBuilder(trajectory1.end())
.lineTo(new Vector2d())
.addDisplacementMarker(() -> drive.followTrajectoryAsync(trajectory3))
.build();
trajectory3 = drive.trajectoryBuilder(trajectory2.end())
.lineTo(new Vector2d())
.build();
while (!isStopRequested() && !opModeIsActive()) {
}
waitForStart();
if (isStopRequested()) return;
drive.followTrajectoryAsync(trajectory1);
while (!isStopRequested() && opModeIsActive()) {
drive.update();
// Put your PID Update Function Here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment