Add thread code and example

This commit is contained in:
2023-11-02 06:50:24 -07:00
parent 089ca0cf3d
commit 8a2973ade8
3 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1,31 @@
import org.firstinspires.ftc.teamcode.threadopmode.*;
import com.qualcomm.robotcore.hardware.DcMotor;
//Extend ThreadOpMode rather than OpMode
public class ThreadedOpMode extends ThreadOpMode {
//Define global variables
private DcMotor dcMotor;
@Override
public void mainInit() {
//Perform your normal init
dcMotor = hardwareMap.dcMotor.get("dcMotor");
//Below is a new thread
registerThread(new TaskThread(new TaskThread.Actions() {
@Override
public void loop() {
//The loop method should contain what to constantly run in the thread
//For instance, this drives a single DcMotor
dcMotor.setPower(gamepad1.left_stick_y);
}
}));
}
@Override
public void mainLoop() {
//Anything you want to constantly run in the MAIN thread goes here
}
}