A library for FTC Java programming that makes multi threading easy.
- Download and extract this repository
- Drag the folder
threadopmode
into theorg.firstinspires.ftc.teamcode
package of yourTeamCode
module
- Add the namespace to the top of your program
import org.firstinspires.ftc.teamcode.threadopmode.*;
- Have your class extend
ThreadOpMode
rather thanOpMode
public class ExampleOpMode extends ThreadOpMode {
...
}
- Override the
mainInit
andmainLoop
methods
@Override
public void mainInit() {
}
@Override
public void mainLoop() {
}
- Add regular
init
code tomainInit
- Create a new thread in
mainInit
using the following template
registerThread(new TaskThread(new TaskThread.Actions() {
@Override
public void loop() {
//The loop method should contain loop code
}
}));
- Repeat this for as many threads as you want to spawn
- (Optional) add code to the main thread in
mainLoop
@Override
public void mainLoop() {
//Anything you want to periodically run in the MAIN thread goes here
}