From 2c59aff3db18180277fe0ec1577c5a1b01232ca1 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Mon, 28 Apr 2025 22:16:01 +1000 Subject: [PATCH 1/2] add on enable and on disable to test --- magicbot/magiccomponent.py | 4 ++-- magicbot/magicrobot.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/magicbot/magiccomponent.py b/magicbot/magiccomponent.py index 8f6b958..d5915d8 100644 --- a/magicbot/magiccomponent.py +++ b/magicbot/magiccomponent.py @@ -49,7 +49,7 @@ def setup(self) -> None: def on_enable(self) -> None: """ - Called when the robot enters autonomous or teleoperated mode. This + Called when the robot enters autonomous, teleoperated or test mode mode. This function should initialize your component to a "safe" state so that unexpected things don't happen when enabling the robot. @@ -60,7 +60,7 @@ def on_enable(self) -> None: def on_disable(self) -> None: """ - Called when the robot leaves autonomous or teleoperated + Called when the robot leaves autonomous, teleoperated or test mode """ def execute(self) -> None: diff --git a/magicbot/magicrobot.py b/magicbot/magicrobot.py index 85d1dd7..fcce4cb 100644 --- a/magicbot/magicrobot.py +++ b/magicbot/magicrobot.py @@ -526,6 +526,9 @@ def _test(self) -> None: wpilib.LiveWindow.setEnabled(True) # Shuffleboard.enableActuatorWidgets() + # initialize things + self._on_mode_enable_components() + try: self.testInit() except: @@ -559,6 +562,8 @@ def _test(self) -> None: wpilib.LiveWindow.setEnabled(False) # Shuffleboard.disableActuatorWidgets() + self._on_mode_disable_components() + def _on_mode_enable_components(self) -> None: # initialize things for _, component in self._components: From 0e6cc3806ca19956c504214a8bd7e14b238b92b3 Mon Sep 17 00:00:00 2001 From: Lucien Morey Date: Mon, 28 Apr 2025 22:20:44 +1000 Subject: [PATCH 2/2] stop double calling on_disable callbacks --- magicbot/magiccomponent.py | 2 +- magicbot/magicrobot.py | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/magicbot/magiccomponent.py b/magicbot/magiccomponent.py index d5915d8..35bbdef 100644 --- a/magicbot/magiccomponent.py +++ b/magicbot/magiccomponent.py @@ -60,7 +60,7 @@ def on_enable(self) -> None: def on_disable(self) -> None: """ - Called when the robot leaves autonomous, teleoperated or test mode + Called when the robot enters disabled mode. """ def execute(self) -> None: diff --git a/magicbot/magicrobot.py b/magicbot/magicrobot.py index fcce4cb..9db0ea8 100644 --- a/magicbot/magicrobot.py +++ b/magicbot/magicrobot.py @@ -413,8 +413,6 @@ def autonomous(self) -> None: watchdog=self.watchdog, ) - self._on_mode_disable_components() - def _disabled(self) -> None: """ This function is called in disabled mode. You should not @@ -513,8 +511,6 @@ def _operatorControl(self) -> None: delay.wait() watchdog.reset() - self._on_mode_disable_components() - def _test(self) -> None: """Called when the robot is in test mode""" watchdog = self.watchdog @@ -562,8 +558,6 @@ def _test(self) -> None: wpilib.LiveWindow.setEnabled(False) # Shuffleboard.disableActuatorWidgets() - self._on_mode_disable_components() - def _on_mode_enable_components(self) -> None: # initialize things for _, component in self._components: