TeamMeanMachine / meanlib

A Kotlin FRC library
The Unlicense
16 stars 3 forks source link

Run enable method if enabled on application start #17

Closed andrewda closed 5 years ago

andrewda commented 5 years ago

Imagine this robot code:

object Robot : RobotProgram {
    init {
        DriverStationSim().enabled = true
        DriverStationSim().autonomous = false

        periodic { DriverStationSim().notifyNewData() }
    }

    override suspend fun enable() {
        println("Enabling")
    }

    override suspend fun disable() {
        println("Disabling")
    }

    override suspend fun teleop() {
        println("Entering teleop...")
    }

    override suspend fun autonomous() {
        println("Entering autonomous...")
    }
}

You'd expect the following to be printed:

Enabling
Entering teleop...

But the enable function is actually skipped because the robot is never registered as disabled (and thus, internally, wasDisabled == false). This fixes that issue so that even if the robot is enabled immediately upon starting the program, the enable method is still called.

Surprisingly enough, this isn't even just an issue in simulations -- mash the "Enable" button on the Driver Station fast enough while the robot is booting up or after pushing code and the enable function sometimes fails to get called!

tylerscheuble commented 5 years ago

Nice catch! Thanks again.