/FTC-Threaded-OpMode

A library for FTC Java programming that makes multi threading easy.

Primary LanguageJava

FTC-Threaded-OpMode

A library for FTC Java programming that makes multi threading easy.

How to install

  1. Download and extract this repository
  2. Drag the folder threadopmode into the org.firstinspires.ftc.teamcode package of your TeamCode module

How to use

  1. Add the namespace to the top of your program
import org.firstinspires.ftc.teamcode.threadopmode.*;
  1. Have your class extend ThreadOpMode rather than OpMode
public class ExampleOpMode extends ThreadOpMode {
  ...
}
  1. Override the mainInit and mainLoop methods
@Override
public void mainInit() {

}

@Override
public void mainLoop() {

}
  1. Add regular init code to mainInit
  2. 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
    }
}));
  1. Repeat this for as many threads as you want to spawn
  2. (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
}