Skip to content

OpModes

OpModes in NextFTC extend the NextFTCOpMode base class, which is a subtype of OpMode. NextFTCOpModes have five functions, similar to OpMode's five functions.

OpMode functionNextFTCOpMode functionCalled
initonInitOnce, when the init button is pressed
init_looponWaitForStartEvery loop between initialization and when the start/stop button is pressed
startonStartButtonPressedOnce, when the start button is pressed
looponUpdateEvery loop, between start and when the stop button is pressed
stoponStopOnce, when the stop button is pressed

Additionally, OpModes can have components that are registered with the addComponents function.

An empty OpMode is as follows.

kotlin
class MyOpMode : NextFTCOpMode() {
    init {
        addComponents(/* vararg components */)
    }
    
    override fun onInit() { }
    override fun onWaitForStart() { }
    override fun onStartButtonPressed() { }
    override fun onUpdate() { }
    override fun onStop() { }
}

There is also an onInit function that can be used to create properties that depend on hardware. It runs before the main onInit function, so properties created with it can be used in the main onInit function.

Here is an example OpMode that uses onInit to create a property for a color sensor, since there is no NextFTC wrapper for color sensors.

kotlin
class MyOpMode : NextFTCOpMode() {
    val sensor by onInit { hardwareMap.get(NormalizedColorSensor::class.java, "colorSensor") }

    init {
        addComponents(/* vararg components */)
    }
    
    override fun onInit() { }
    override fun onWaitForStart() { }
    override fun onStartButtonPressed() { }
    override fun onUpdate() { }
    override fun onStop() { }
}