diff --git a/core/src/main/kotlin/org/sertain/Robot.kt b/core/src/main/kotlin/org/sertain/Robot.kt index 250ce05..6d78c5c 100644 --- a/core/src/main/kotlin/org/sertain/Robot.kt +++ b/core/src/main/kotlin/org/sertain/Robot.kt @@ -5,6 +5,7 @@ package org.sertain import android.support.annotation.VisibleForTesting import edu.wpi.first.wpilibj.IterativeRobot import edu.wpi.first.wpilibj.command.Scheduler +import org.sertain.command.Subsystem private typealias LifecycleDistributor = RobotLifecycle.Companion.Distributor @@ -143,7 +144,7 @@ public interface RobotLifecycle { } /** Base robot class which must be used for [RobotLifecycle] callbacks to work. */ -public abstract class Robot : IterativeRobot(), RobotLifecycle { +public abstract class Robot(vararg subsystems: Subsystem) : IterativeRobot(), RobotLifecycle { private var mode = State.DISABLED set(value) { if (value != field) { @@ -160,6 +161,8 @@ public abstract class Robot : IterativeRobot(), RobotLifecycle { @Suppress("LeakingThis") // Invoked through reflection and initialized later RobotLifecycle.rawAddListener(this) + subsystems.forEach { RobotLifecycle.addListener(it) } + val existingHandler = Thread.getDefaultUncaughtExceptionHandler() Thread.setDefaultUncaughtExceptionHandler { t, e -> println("Exception occurred on thread $t:") diff --git a/core/src/main/kotlin/org/sertain/command/Subsystem.kt b/core/src/main/kotlin/org/sertain/command/Subsystem.kt index 0ca5f73..4d678db 100644 --- a/core/src/main/kotlin/org/sertain/command/Subsystem.kt +++ b/core/src/main/kotlin/org/sertain/command/Subsystem.kt @@ -2,7 +2,6 @@ @file:JvmName("SubsystemUtils") package org.sertain.command -import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder import org.sertain.RobotLifecycle import edu.wpi.first.wpilibj.command.Subsystem as WpiLibSubsystem @@ -11,10 +10,5 @@ public abstract class Subsystem : WpiLibSubsystem(), RobotLifecycle { /** @see edu.wpi.first.wpilibj.command.Subsystem.setDefaultCommand */ open val defaultCommand: CommandBase? = null - override fun initSendable(builder: SendableBuilder?) { - super.initSendable(builder) - RobotLifecycle.addListener(this) - } - override fun initDefaultCommand() = setDefaultCommand(defaultCommand?.mirror) }