Created
December 6, 2023 06:56
-
-
Save TheOutcastVirus/81313e5a636d9ecc8af9da2b12737547 to your computer and use it in GitHub Desktop.
Example of RR Async Trajectories in use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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