def startCompetition(self) -> None: """Provide an alternate "main loop" via startCompetition()""" self.robotInit() hal.observeUserProgramStarting() # Loop forever, calling the appropriate mode-dependent function self._loop.run_until_complete(self._run_robot())
def startCompetition(self): hal.report(hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Iterative) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() LiveWindow.setEnabled(False) while True: # Wait for new data to arrive self.ds.waitForData() if self.isDisabled(): self.earlyStop = False if self.iterator: self.iterator.close() self.iterator = None LiveWindow.setEnabled(False) hal.observeUserProgramDisabled() else: # not disabled if not self.iterator and not self.earlyStop: LiveWindow.setEnabled(True) try: if self.isTest(): self.iterator = self.test() elif self.isAutonomous(): self.iterator = self.autonomous() else: self.iterator = self.teleop() except: print("Exception while starting sequence!") traceback.print_exc() self.earlyStop = True if self.isTest(): hal.observeUserProgramTest() elif self.isAutonomous(): hal.observeUserProgramAutonomous() else: hal.observeUserProgramTeleop() if self.iterator: try: next(self.iterator) except StopIteration: print("Robot done.") self.iterator = None self.earlyStop = True except: print("Exception in robot code!") traceback.print_exc() self.iterator = None self.earlyStop = True
def startCompetition(self) -> None: """Start a competition. This code tracks the order of the field starting to ensure that everything happens in the right order. Repeatedly run the correct method, either Autonomous or OperatorControl when the robot is enabled. After running the correct method, wait for some state to change, either the other mode starts or the robot is disabled. Then go back and wait for the robot to be enabled again. """ hal.report( hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Sample, ) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() self.robotMain() if hasattr(self, "_no_robot_main"): while True: # python-specific isEnabled, isAutonomous, isTest = self.getControlState() if not isEnabled: self.ds.InDisabled(True) self.disabled() self.ds.InDisabled(False) while self.isDisabled(): Timer.delay(0.01) elif isAutonomous: self.ds.InAutonomous(True) self.autonomous() self.ds.InAutonomous(False) while self.isAutonomousEnabled(): Timer.delay(0.01) elif isTest: LiveWindow.setEnabled(True) Shuffleboard.enableActuatorWidgets() self.ds.InTest(True) self.test() self.ds.InTest(False) while self.isTest() and self.isEnabled(): Timer.delay(0.01) LiveWindow.setEnabled(False) Shuffleboard.disableActuatorWidgets() else: self.ds.InOperatorControl(True) self.operatorControl() self.ds.InOperatorControl(False) while self.isOperatorControlEnabled(): Timer.delay(0.01)
def startCompetition(self) -> None: """Provide an alternate "main loop" via startCompetition()""" self.robotInit() hal.observeUserProgramStarting() self.startLoop = True self.loop.startPeriodic(self.period) while True: Timer.delay(60 * 60 * 24)
def startCompetition(self): """ Provide an alternate "main loop" via startCompetition(). Rewritten from IterativeRobot for readability and to initialize scheduler. """ hal.report(hal.HALUsageReporting.kResourceType_Framework, hal.HALUsageReporting.kFramework_Iterative) self.scheduler = Scheduler.getInstance() self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() # loop forever, calling the appropriate mode-dependent function while True: if self.ds.isDisabled(): hal.observeUserProgramDisabled() self.disabledInit() while self.ds.isDisabled(): self.disabledPeriodic() self.ds.waitForData() elif self.ds.isAutonomous(): hal.observeUserProgramAutonomous() self.autonomousInit() while self.ds.isEnabled() and self.ds.isAutonomous(): self.autonomousPeriodic() self.ds.waitForData() elif self.ds.isTest(): hal.observeUserProgramTest() LiveWindow.setEnabled(True) self.testInit() while self.ds.isEnabled() and self.ds.isTest(): self.testPeriodic() self.ds.waitForData() LiveWindow.setEnabled(False) else: hal.observeUserProgramTeleop() self.teleopInit() # isOperatorControl checks "not autonomous or test", so we need # to check isEnabled as well, since otherwise it will continue # looping while disabled. while self.ds.isEnabled() and self.ds.isOperatorControl(): self.teleopPeriodic() self.ds.waitForData()
def startCompetition(self): """Start a competition. This code tracks the order of the field starting to ensure that everything happens in the right order. Repeatedly run the correct method, either Autonomous or OperatorControl when the robot is enabled. After running the correct method, wait for some state to change, either the other mode starts or the robot is disabled. Then go back and wait for the robot to be enabled again. """ hal.report(hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Sample) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() self.robotMain() if hasattr(self, '_no_robot_main'): # first and one-time initialization LiveWindow.setEnabled(False) while True: if self.isDisabled(): self.ds.InDisabled(True) self.disabled() self.ds.InDisabled(False) while self.isDisabled(): Timer.delay(0.01) elif self.isAutonomous(): self.ds.InAutonomous(True) self.autonomous() self.ds.InAutonomous(False) while self.isAutonomous() and not self.isDisabled(): Timer.delay(0.01) elif self.isTest(): LiveWindow.setEnabled(True) self.ds.InTest(True) self.test() self.ds.InTest(False) while self.isTest() and self.isEnabled(): Timer.delay(0.01) LiveWindow.setEnabled(False) else: self.ds.InOperatorControl(True) self.operatorControl() self.ds.InOperatorControl(False) while self.isOperatorControl() and not self.isDisabled(): Timer.delay(0.01)
def startCompetition(self) -> None: """Provide an alternate "main loop" via startCompetition()""" self.robotInit() hal.observeUserProgramStarting() self.startLoop = True self._expirationTime = RobotController.getFPGATime( ) * 1e-6 + self.period self._updateAlarm() # Loop forever, calling the appropriate mode-dependent function self._loop.run_until_complete(self._pollTimer(self._loop))
def startCompetition(self): """Provide an alternate "main loop" via startCompetition().""" self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() # loop forever, calling the appropriate mode-dependent function while True: # Wait for new data to arrive self.ds.waitForData() # Call the appropriate function depending upon the current robot mode self.loopFunc()
def startCompetition(self) -> None: """Provide an alternate "main loop" via startCompetition().""" self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() # loop forever, calling the appropriate mode-dependent function while True: # Wait for new data to arrive self.ds.waitForData() # Call the appropriate function depending upon the current robot mode self.loopFunc()
def startCompetition(self): """Start a competition. This code tracks the order of the field starting to ensure that everything happens in the right order. Repeatedly run the correct method, either Autonomous or OperatorControl when the robot is enabled. After running the correct method, wait for some state to change, either the other mode starts or the robot is disabled. Then go back and wait for the robot to be enabled again. """ hal.report(hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Sample) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() self.robotMain() if hasattr(self, '_no_robot_main'): # first and one-time initialization LiveWindow.setEnabled(False) while True: if self.isDisabled(): self.ds.InDisabled(True) self.disabled() self.ds.InDisabled(False) while self.isDisabled(): Timer.delay(0.01) elif self.isAutonomous(): self.ds.InAutonomous(True) self.autonomous() self.ds.InAutonomous(False) while self.isAutonomous() and not self.isDisabled(): Timer.delay(0.01) elif self.isTest(): LiveWindow.setEnabled(True) self.ds.InTest(True) self.test() self.ds.InTest(False) while self.isTest() and self.isEnabled(): Timer.delay(0.01) LiveWindow.setEnabled(False) else: self.ds.InOperatorControl(True) self.operatorControl() self.ds.InOperatorControl(False) while self.isOperatorControl() and not self.isDisabled(): Timer.delay(0.01)
def startCompetition(self) -> None: """Provide an alternate "main loop" via startCompetition()""" self.robotInit() hal.observeUserProgramStarting() self._expirationTime = RobotController.getFPGATime() * 1e-6 + self.period self._updateAlarm() # Loop forever, calling the appropriate mode-dependent function while True: if hal.waitForNotifierAlarm(self._notifier) == 0: break self._expirationTime += self.period self._updateAlarm() self.loopFunc()
def startCompetition(self) -> None: """ This runs the mode-switching loop. .. warning:: Internal API, don't override """ # TODO: usage reporting? self.robotInit() # Tell the DS the robot is ready to be enabled hal.observeUserProgramStarting() while not self.__done: isEnabled, isAutonomous, isTest = self.getControlState() if not isEnabled: self._disabled() elif isAutonomous: self.autonomous() elif isTest: self._test() else: self._operatorControl()
def startCompetition(self): """Provide an alternate "main loop" via startCompetition().""" hal.report(hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Iterative) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() # loop forever, calling the appropriate mode-dependent function LiveWindow.setEnabled(False) while True: # Wait for new data to arrive self.ds.waitForData() # Call the appropriate function depending upon the current robot mode if self.isDisabled(): # call DisabledInit() if we are now just entering disabled mode from # either a different mode or from power-on if not self.disabledInitialized: LiveWindow.setEnabled(False) self.disabledInit() self.disabledInitialized = True # reset the initialization flags for the other modes self.autonomousInitialized = False self.teleopInitialized = False self.testInitialized = False hal.observeUserProgramDisabled() self.disabledPeriodic() elif self.isTest(): # call TestInit() if we are now just entering test mode from either # a different mode or from power-on if not self.testInitialized: LiveWindow.setEnabled(True) self.testInit() self.testInitialized = True self.autonomousInitialized = False self.teleopInitialized = False self.disabledInitialized = False hal.observeUserProgramTest() self.testPeriodic() elif self.isAutonomous(): # call Autonomous_Init() if this is the first time # we've entered autonomous_mode if not self.autonomousInitialized: LiveWindow.setEnabled(False) # KBS NOTE: old code reset all PWMs and relays to "safe values" # whenever entering autonomous mode, before calling # "Autonomous_Init()" self.autonomousInit() self.autonomousInitialized = True self.testInitialized = False self.teleopInitialized = False self.disabledInitialized = False hal.observeUserProgramAutonomous() self.autonomousPeriodic() else: # call Teleop_Init() if this is the first time # we've entered teleop_mode if not self.teleopInitialized: LiveWindow.setEnabled(False) self.teleopInit() self.teleopInitialized = True self.testInitialized = False self.autonomousInitialized = False self.disabledInitialized = False hal.observeUserProgramTeleop() self.teleopPeriodic() self.robotPeriodic()
def startCompetition(self): self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() self._expirationTime = RobotController.getFPGATime( ) * 1e-6 + self.period self._updateAlarm() while True: if hal.waitForNotifierAlarm(self._notifier[0]) == 0: if self.iterator is not None: self.iterator.close() self.iterator = None self.logger.error("Robot Break!") break self._expirationTime += self.period self._updateAlarm() # Wait for new data to arrive self.ds.waitForData() if self.isDisabled(): self.earlyStop = False if self.iterator: self.iterator.close() self.iterator = None hal.observeUserProgramDisabled() else: # not disabled if not self.iterator and not self.earlyStop: try: if self.isTest(): self.iterator = self.test() elif self.isAutonomous(): self.iterator = self.autonomous() else: self.iterator = self.teleop() if self.iterator is None: self.logger.error( "Robot function is not a generator!") except BaseException as e: self.logger.exception( "Exception while starting sequence!", exc_info=e) self.earlyStop = True if self.isTest(): hal.observeUserProgramTest() elif self.isAutonomous(): hal.observeUserProgramAutonomous() else: hal.observeUserProgramTeleop() if self.iterator: try: next(self.iterator) except StopIteration: self.logger.info("Robot done.") self.iterator = None self.earlyStop = True except BaseException as e: self.logger.exception("Exception in robot code!", exc_info=e) self.iterator = None self.earlyStop = True
def startCompetition(self): """Provide an alternate "main loop" via startCompetition().""" hal.report(hal.UsageReporting.kResourceType_Framework, hal.UsageReporting.kFramework_Iterative) self.robotInit() # Tell the DS that the robot is ready to be enabled hal.observeUserProgramStarting() # loop forever, calling the appropriate mode-dependent function LiveWindow.setEnabled(False) while True: # Wait for new data to arrive self.ds.waitForData() # Call the appropriate function depending upon the current robot mode if self.isDisabled(): # call DisabledInit() if we are now just entering disabled mode from # either a different mode or from power-on if not self.disabledInitialized: LiveWindow.setEnabled(False) self.disabledInit() self.disabledInitialized = True # reset the initialization flags for the other modes self.autonomousInitialized = False self.teleopInitialized = False self.testInitialized = False hal.observeUserProgramDisabled() self.disabledPeriodic() elif self.isTest(): # call TestInit() if we are now just entering test mode from either # a different mode or from power-on if not self.testInitialized: LiveWindow.setEnabled(True) self.testInit() self.testInitialized = True self.autonomousInitialized = False self.teleopInitialized = False self.disabledInitialized = False hal.observeUserProgramTest() self.testPeriodic() elif self.isAutonomous(): # call Autonomous_Init() if this is the first time # we've entered autonomous_mode if not self.autonomousInitialized: LiveWindow.setEnabled(False) # KBS NOTE: old code reset all PWMs and relays to "safe values" # whenever entering autonomous mode, before calling # "Autonomous_Init()" self.autonomousInit() self.autonomousInitialized = True self.testInitialized = False self.teleopInitialized = False self.disabledInitialized = False hal.observeUserProgramAutonomous() self.autonomousPeriodic() else: # call Teleop_Init() if this is the first time # we've entered teleop_mode if not self.teleopInitialized: LiveWindow.setEnabled(False) self.teleopInit() self.teleopInitialized = True self.testInitialized = False self.autonomousInitialized = False self.disabledInitialized = False hal.observeUserProgramTeleop() self.teleopPeriodic() self.robotPeriodic()