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 function | NextFTCOpMode function | Called |
---|---|---|
init | onInit | Once, when the init button is pressed |
init_loop | onWaitForStart | Every loop between initialization and when the start/stop button is pressed |
start | onStartButtonPressed | Once, when the start button is pressed |
loop | onUpdate | Every loop, between start and when the stop button is pressed |
stop | onStop | Once, 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() { }
}