示例#1
0
 def prestart(self):
     """
     This hook is called right before :meth:`startCompetition`. By default, tell
     the DS that the robot is now ready to be enabled. If you don't want the
     robot to be enabled yet, you can override this method to do nothing.
     If you do so, you will need to call hal.HALNetworkCommunicationObserveUserProgramStarting()
     from your code when you are ready for the robot to be enabled.
     """
     hal.HALNetworkCommunicationObserveUserProgramStarting()
示例#2
0
    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.HALReport(hal.HALUsageReporting.kResourceType_Framework,
                      hal.HALUsageReporting.kFramework_Simple)

        self.robotMain()

        if hasattr(self, '_no_robot_main'):
            # first and one-time initialization
            LiveWindow.setEnabled(False)
            self.robotInit()

            #We call this now (not in prestart like default) so that the robot
            #won't enable until the initialization has finished. This is useful
            #because otherwise it's sometimes possible to enable the robot before
            #the code is ready.
            hal.HALNetworkCommunicationObserveUserProgramStarting()

            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)
示例#3
0
    def startCompetition(self):
        """Provide an alternate "main loop" via startCompetition()."""
        hal.HALReport(hal.HALUsageReporting.kResourceType_Framework,
                      hal.HALUsageReporting.kFramework_Iterative)

        self.robotInit()

        #We call this now (not in prestart like default) so that the robot
        #won't enable until the initialization has finished. This is useful
        #because otherwise it's sometimes possible to enable the robot before
        #the code is ready.
        hal.HALNetworkCommunicationObserveUserProgramStarting()

        # loop forever, calling the appropriate mode-dependent function
        LiveWindow.setEnabled(False)
        while True:
            # 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
                if self.nextPeriodReady():
                    hal.HALNetworkCommunicationObserveUserProgramDisabled()
                    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
                if self.nextPeriodReady():
                    hal.HALNetworkCommunicationObserveUserProgramTest()
                    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
                if self.nextPeriodReady():
                    hal.HALNetworkCommunicationObserveUserProgramAutonomous()
                    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
                if self.nextPeriodReady():
                    hal.HALNetworkCommunicationObserveUserProgramTeleop()
                    self.teleopPeriodic()
            self.ds.waitForData()