Ejemplo n.º 1
0
    def isDSAttached(self):
        """Is the driver station attached to the robot?

        :returns: True if the robot is being controlled by a driver station.
        """
        controlWord = hal.HALGetControlWord()
        return controlWord.dsAttached != 0
Ejemplo n.º 2
0
    def isFMSAttached(self):
        """Is the driver station attached to a Field Management System?

        :returns: True if the robot is competing on a field being controlled
            by a Field Management System
        """
        controlWord = hal.HALGetControlWord()
        return controlWord.fmsAttached != 0
Ejemplo n.º 3
0
    def isTest(self):
        """Gets a value indicating whether the Driver Station requires the
        robot to be running in test mode.

        :returns: True if test mode should be enabled, False otherwise.
        """
        controlWord = hal.HALGetControlWord()
        return controlWord.test != 0
Ejemplo n.º 4
0
    def isEnabled(self):
        """Gets a value indicating whether the Driver Station requires the
        robot to be enabled.

        :returns: True if the robot is enabled, False otherwise.
        """
        controlWord = hal.HALGetControlWord()
        return controlWord.enabled != 0 and controlWord.dsAttached != 0
Ejemplo n.º 5
0
    def isOperatorControl(self):
        """Gets a value indicating whether the Driver Station requires the
        robot to be running in operator-controlled mode.

        :returns: True if operator-controlled mode should be enabled,
            False otherwise.
        """
        controlWord = hal.HALGetControlWord()
        return not (controlWord.autonomous != 0 or controlWord.test != 0)
Ejemplo n.º 6
0
    def reportError(error, printTrace):
        """Report error to Driver Station, and also prints error to `sys.stderr`.
        Optionally appends stack trace to error message.

        :param printTrace: If True, append stack trace to error string
        """
        errorString = error
        if printTrace:
            exc = sys.exc_info()[0]
            stack = traceback.extract_stack()[:-1]  # last one is this func
            if exc is not None:  # i.e. if an exception is present
                # remove call of full_stack, the printed exception
                # will contain the caught exception caller instead
                del stack[-1]
            trc = 'Traceback (most recent call last):\n'
            stackstr = trc + ''.join(traceback.format_list(stack))
            if exc is not None:
                stackstr += '  ' + traceback.format_exc().lstrip(trc)
            errorString += ':\n' + stackstr
        #print(errorString, file=sys.stderr)
        controlWord = hal.HALGetControlWord()
        if controlWord.dsAttached != 0:
            hal.HALSetErrorData(errorString, 0)