Exemplo n.º 1
0
    def __init__(self, channel):
        """Allocate a PWM given a channel.

        :param channel: The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
        :type channel: int
        """
        SensorBase.checkPWMChannel(channel)
        self.channel = channel
        self._port = hal.initializeDigitalPort(hal.getPort(channel))
        
        self.freq = 1/self.kDefaultPwmPeriod * 1000

        print('PWM::__init__  channel: {0}, freq: {1}'.format( channel, self.freq))

        if not hal.allocatePWMChannel(self._port):
            raise IndexError("PWM channel %d is already allocated" % channel)
        #self.pwmObj = hal_data['pwm'][digital_port.pin]['pwmObj']
        
        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)

        hal.setPWM(self._port, 0)

        self.__finalizer = weakref.finalize(self, _freePWM, self._port)

        self.eliminateDeadband = True

        hal.HALReport(hal.HALUsageReporting.kResourceType_PWM, channel)
Exemplo n.º 2
0
    def __init__(self, channel):
        """Constructor for an analog trigger given a channel number or analog
        input.

        :param channel: the port index or :class:`.AnalogInput` to use for the analog
            trigger.  Treated as an AnalogInput if the provided object has a
            getChannel function.
        """
        super().__init__()
        if not hasattr(channel, "getChannel"):
            self.analogInput = AnalogInput(channel)
            self.ownsAnalog = True
            self.addChild(self.analogInput)
        else:
            self.analogInput = channel

        port = hal.getPort(channel)
        self._port, self.index = hal.initializeAnalogTrigger(port)
        self.__finalizer = \
            weakref.finalize(self, _freeAnalogTrigger, self._port)

        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)

        hal.report(hal.UsageReporting.kResourceType_AnalogTrigger, channel)

        self.setName("AnalogTrigger", self.analogInput.getChannel())
Exemplo n.º 3
0
    def __init__(self, channel: int) -> None:
        """Allocate a PWM given a channel.

        :param channel: The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
        """
        super().__init__()
        SendableBase.__init__(self)

        SensorUtil.checkPWMChannel(channel)
        self.channel = channel

        self._handle = hal.initializePWMPort(hal.getPort(channel))
        self.__finalizer = weakref.finalize(self, _freePWM, self._handle)

        self.setDisabled()

        hal.setPWMEliminateDeadband(self.handle, False)

        hal.report(hal.UsageReporting.kResourceType_PWM, channel)
        self.setName("PWM", channel)

        self.setSafetyEnabled(False)

        # Python-specific: Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)
Exemplo n.º 4
0
    def __init__(self, channel: int) -> None:
        """Allocate a PWM given a channel.

        :param channel: The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
        """
        super().__init__()
        SendableBase.__init__(self)

        SensorUtil.checkPWMChannel(channel)
        self.channel = channel

        self.handle = hal.initializePWMPort(hal.getPort(channel))
        self.__finalizer = weakref.finalize(self, _freePWM, self.handle)

        self.setDisabled()

        hal.setPWMEliminateDeadband(self.handle, False)

        hal.report(hal.UsageReporting.kResourceType_PWM, channel)
        self.setName("PWM", channel)

        self.setSafetyEnabled(False)

        # Python-specific: Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)
Exemplo n.º 5
0
    def __init__(self, channel):
        """Construct an analog output on a specified MXP channel.

        :param channel: The channel number to represent.
        """
        if not hal.checkAnalogOutputChannel(channel):
            raise IndexError(
                "Analog output channel %d cannot be allocated. Channel is not present."
                % channel)
        try:
            AnalogOutput.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Analog output channel %d is already allocated" %
                             channel) from e

        self.channel = channel

        port = hal.getPort(channel)
        self._port = hal.initializeAnalogOutputPort(port)

        LiveWindow.addSensorChannel("AnalogOutput", channel, self)
        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
                      channel, 1)

        self.__finalizer = weakref.finalize(self, _freeAnalogOutput,
                                            self._port)
Exemplo n.º 6
0
    def _initRelay(self) -> None:
        SensorUtil.checkRelayChannel(self.channel)
        portHandle = hal.getPort(self.channel)

        try:
            if (
                self.direction == self.Direction.kBoth
                or self.direction == self.Direction.kForward
            ):
                Relay.relayChannels.allocate(self, self.channel * 2)
                self._forwardHandle = hal.initializeRelayPort(portHandle, True)
                hal.report(hal.UsageReporting.kResourceType_Relay, self.channel)

            if (
                self.direction == self.Direction.kBoth
                or self.direction == self.Direction.kReverse
            ):
                Relay.relayChannels.allocate(self, self.channel * 2 + 1)
                self._reverseHandle = hal.initializeRelayPort(portHandle, False)
                hal.report(hal.UsageReporting.kResourceType_Relay, self.channel + 128)
        except IndexError as e:
            raise IndexError(
                "Relay channel %d is already allocated" % self.channel
            ) from e

        self.__finalizer = weakref.finalize(
            self, _freeRelay, self._forwardHandle, self._reverseHandle
        )

        self.setSafetyEnabled(False)

        self.setName("Relay", self.channel)
Exemplo n.º 7
0
    def _initRelay(self) -> None:
        SensorUtil.checkRelayChannel(self.channel)
        portHandle = hal.getPort(self.channel)

        try:
            if (
                self.direction == self.Direction.kBoth
                or self.direction == self.Direction.kForward
            ):
                Relay.relayChannels.allocate(self, self.channel * 2)
                self.forwardHandle = hal.initializeRelayPort(portHandle, True)
                hal.report(hal.UsageReporting.kResourceType_Relay, self.channel)

            if (
                self.direction == self.Direction.kBoth
                or self.direction == self.Direction.kReverse
            ):
                Relay.relayChannels.allocate(self, self.channel * 2 + 1)
                self.reverseHandle = hal.initializeRelayPort(portHandle, False)
                hal.report(hal.UsageReporting.kResourceType_Relay, self.channel + 128)
        except IndexError as e:
            raise IndexError(
                "Relay channel %d is already allocated" % self.channel
            ) from e

        self.__finalizer = weakref.finalize(
            self, _freeRelay, self.forwardHandle, self.reverseHandle
        )

        self.setSafetyEnabled(False)

        self.setName("Relay", self.channel)
Exemplo n.º 8
0
    def __init__(self, channel: int) -> None:
        """Create an instance of a Digital Input class. Creates a digital
        input given a channel.

        :param channel: the DIO channel for the digital input. 0-9 are on-board, 10-25 are on the MXP
        """

        super().__init__()
        SensorUtil.checkDigitalChannel(channel)
        self.channel = channel

        self.handle = hal.initializeDIOPort(hal.getPort(channel), True)

        hal.report(hal.UsageReporting.kResourceType_DigitalInput, channel)
        self.setName("DigitalInput", channel)
Exemplo n.º 9
0
    def __init__(self, channel: int) -> None:
        """Create an instance of a digital output.

        :param channel: the DIO channel for the digital output. 0-9 are on-board, 10-25 are on the MXP
        """

        super().__init__()
        self.pwmGenerator = None
        self._pwmGenerator_finalizer = None

        SensorUtil.checkDigitalChannel(channel)
        self.channel = channel

        self.handle = hal.initializeDIOPort(hal.getPort(channel), False)

        hal.report(hal.UsageReporting.kResourceType_DigitalOutput, channel)
        self.setName("DigitalOutput", channel)
Exemplo n.º 10
0
    def __init__(self, channel):
        """Create an instance of a digital output.

        :param channel: the DIO channel for the digital output. 0-9 are on-board, 10-25 are on the MXP
        """

        super().__init__()
        self._pwmGenerator = None
        self._pwmGenerator_finalizer = None

        SensorUtil.checkDigitalChannel(channel)
        self.channel = channel

        self.handle = hal.initializeDIOPort(hal.getPort(channel), False)

        hal.report(hal.UsageReporting.kResourceType_DigitalOutput, channel)
        self.setName("DigitalOutput", channel)
Exemplo n.º 11
0
    def __init__(self, channel):
        """Construct an analog output on a specified MXP channel.

        :param channel: The channel number to represent.
        """
        SensorBase.checkAnalogOutputChannel(channel)
        
        self.channel = channel

        port = hal.getPort(channel)
        self._port = hal.initializeAnalogOutputPort(port)

        LiveWindow.addSensorChannel("AnalogOutput", channel, self)
        hal.report(hal.UsageReporting.kResourceType_AnalogChannel,
                      channel, 1)
        
        self.__finalizer = weakref.finalize(self, _freeAnalogOutput, self._port)
Exemplo n.º 12
0
    def __init__(self, channel: int) -> None:
        """Construct an analog output on a specified MXP channel.

        :param channel: The channel number to represent.
        """
        super().__init__()
        SensorUtil.checkAnalogOutputChannel(channel)

        self.channel = channel

        port = hal.getPort(channel)
        self.port = hal.initializeAnalogOutputPort(port)

        self.setName("AnalogOutput", channel)
        hal.report(hal.UsageReporting.kResourceType_AnalogChannel, channel, 1)

        self.__finalizer = weakref.finalize(self, _freeAnalogOutput, self.port)
Exemplo n.º 13
0
    def __init__(self, channel):
        """Construct an analog channel.
        :param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
        """

        SensorBase.checkAnalogInputChannel(channel)

        self.channel = channel
        self.accumulatorOffset = 0
        self.pidSource = self.PIDSourceType.kDisplacement

        port = hal.getPort(channel)
        self._port = hal.initializeAnalogInputPort(port)

        LiveWindow.addSensorChannel("AnalogInput", channel, self)
        hal.report(hal.UsageReporting.kResourceType_AnalogChannel, channel)

        self.__finalizer = weakref.finalize(self, _freeAnalogInput, self._port)
Exemplo n.º 14
0
    def _initRelay(self):
        SensorBase.checkRelayChannel(self.channel)
        try:
            if (self.direction == self.Direction.kBoth or
                self.direction == self.Direction.kForward):
                Relay.relayChannels.allocate(self, self.channel * 2)
                hal.HALReport(hal.HALUsageReporting.kResourceType_Relay,
                              self.channel)
            if (self.direction == self.Direction.kBoth or
                self.direction == self.Direction.kReverse):
                Relay.relayChannels.allocate(self, self.channel * 2 + 1)
                hal.HALReport(hal.HALUsageReporting.kResourceType_Relay,
                              self.channel + 128)
        except IndexError as e:
            raise IndexError("Relay channel %d is already allocated" % self.channel) from e

        self._port = hal.initializeDigitalPort(hal.getPort(self.channel))
        self._port_finalizer = weakref.finalize(self, _freeRelay, self._port)
    def __init__(self, channel, input):
        """
            :param channel: Port for the digital input
            :type  channel: int
            :param input: True if input, False otherwise
            :type  input: int
        """
        super().__init__()

        SensorBase.checkDigitalChannel(channel)
        self.channel = channel
        self._handle = hal.initializeDIOPort(hal.getPort(channel), input)

        try:
            DigitalSource.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Digital input %d is already allocated" % self.channel) from e

        self.__finalizer = weakref.finalize(self, _freeDigitalSource, self._handle)
Exemplo n.º 16
0
    def __init__(self, channel, input):
        """
            :param channel: Port for the digital input
            :type  channel: int
            :param input: True if input, False otherwise
            :type  input: int
        """
        super().__init__()

        SensorBase.checkDigitalChannel(channel)
        self.channel = channel
        self._handle = hal.initializeDIOPort(hal.getPort(channel), input)

        try:
            DigitalSource.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Digital input %d is already allocated" % self.channel) from e

        self.__finalizer = weakref.finalize(self, _freeDigitalSource, self._handle)
Exemplo n.º 17
0
    def __init__(self, channel):
        """Construct an analog output on a specified MXP channel.

        :param channel: The channel number to represent.
        """
        if not hal.checkAnalogOutputChannel(channel):
            raise IndexError("Analog output channel %d cannot be allocated. Channel is not present." % channel)
        try:
            AnalogOutput.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Analog output channel %d is already allocated" % channel) from e

        self.channel = channel

        port = hal.getPort(channel)
        self.port = hal.initializeAnalogOutputPort(port)

        LiveWindow.addSensorChannel("AnalogOutput", channel, self)
        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
                      channel, 1)
Exemplo n.º 18
0
    def __init__(self, channel):
        """Construct an analog channel.
        :param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
        """
        if not hal.checkAnalogInputChannel(channel):
            raise IndexError("Analog input channel %d cannot be allocated. Channel is not present." % channel)
        try:
            AnalogInput.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Analog input channel %d is already allocated" % channel) from e

        self.channel = channel
        self.accumulatorOffset = 0

        port = hal.getPort(channel)
        self.port = hal.initializeAnalogInputPort(port)

        LiveWindow.addSensorChannel("AnalogInput", channel, self)
        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
                      channel)
Exemplo n.º 19
0
    def _initRelay(self):
        SensorBase.checkRelayChannel(self.channel)
        try:
            if (self.direction == self.Direction.kBoth or
                self.direction == self.Direction.kForward):
                Relay.relayChannels.allocate(self, self.channel * 2)
                hal.HALReport(hal.HALUsageReporting.kResourceType_Relay,
                              self.channel)
            if (self.direction == self.Direction.kBoth or
                self.direction == self.Direction.kReverse):
                Relay.relayChannels.allocate(self, self.channel * 2 + 1)
                hal.HALReport(hal.HALUsageReporting.kResourceType_Relay,
                              self.channel + 128)
        except IndexError as e:
            raise IndexError("Relay channel %d is already allocated" % self.channel) from e

        self._port = hal.initializeDigitalPort(hal.getPort(self.channel))
        self._port_finalizer = weakref.finalize(self, _freeRelay, self._port)

        self.setSafetyEnabled(False)
Exemplo n.º 20
0
    def __init__(self, channel: int) -> None:
        """Construct an analog channel.

        :param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
        """

        super().__init__()
        hal.checkAnalogInputChannel(channel)

        self.channel = channel
        self.accumulatorOffset = 0
        self.pidSource = self.PIDSourceType.kDisplacement

        port = hal.getPort(channel)
        self.port = hal.initializeAnalogInputPort(port)

        hal.report(hal.UsageReporting.kResourceType_AnalogChannel, channel)
        self.setName("AnalogInput", self.channel)

        self.__finalizer = weakref.finalize(self, _freeAnalogInput, self.port)
Exemplo n.º 21
0
    def __init__(self, channel: int) -> None:
        """Construct an analog channel.

        :param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
        """

        super().__init__()
        hal.checkAnalogInputChannel(channel)

        self.channel = channel
        self.accumulatorOffset = 0
        self.pidSource = self.PIDSourceType.kDisplacement

        port = hal.getPort(channel)
        self._port = hal.initializeAnalogInputPort(port)

        hal.report(hal.UsageReporting.kResourceType_AnalogChannel, channel)
        self.setName("AnalogInput", self.channel)

        self.__finalizer = weakref.finalize(self, _freeAnalogInput, self._port)
Exemplo n.º 22
0
    def __init__(self, channel):
        """Constructor for an analog trigger given a channel number or analog
        input.

        :param channel: the port index or :class:`.AnalogInput` to use for the analog
            trigger.  Treated as an AnalogInput if the provided object has a
            getChannel function.
        """
        if hasattr(channel, "getChannel"):
            channel = channel.getChannel()

        port = hal.getPort(channel)
        self._port, self.index = hal.initializeAnalogTrigger(port)
        self.__finalizer = \
                weakref.finalize(self, _freeAnalogTrigger, self._port)
                
        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)

        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogTrigger,
                      channel)
Exemplo n.º 23
0
    def __init__(self, channel):
        """Constructor for an analog trigger given a channel number or analog
        input.

        :param channel: the port index or :class:`.AnalogInput` to use for the analog
            trigger.  Treated as an AnalogInput if the provided object has a
            getChannel function.
        """
        if hasattr(channel, "getChannel"):
            channel = channel.getChannel()

        port = hal.getPort(channel)
        self._port, self.index = hal.initializeAnalogTrigger(port)
        self.__finalizer = \
                weakref.finalize(self, _freeAnalogTrigger, self._port)

        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)

        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogTrigger,
                      channel)
Exemplo n.º 24
0
    def __init__(self, channel, input):
        """
            :param channel: Port for the digital input
            :type  channel: int
            :param input: True if input, False otherwise
            :type  input: int
        """
        super().__init__()

        self.channel = channel

        # XXX: Replace with hal.checkDigitalChannel when implemented
        SensorBase.checkDigitalChannel(channel)

        try:
            DigitalSource.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Digital input %d is already allocated" % self.channel) from e

        self._port = hal.initializeDigitalPort(hal.getPort(channel))
        hal.allocateDIO(self._port, True if input else False)

        self._port_finalizer = weakref.finalize(self, hal.freeDIO, self._port)
Exemplo n.º 25
0
    def __init__(self, channel):
        """Allocate a PWM given a channel.

        :param channel: The PWM channel number. 0-9 are on-board, 10-19 are on the MXP port
        :type channel: int
        """
        SensorBase.checkPWMChannel(channel)
        self.channel = channel
        self._port = hal.initializeDigitalPort(hal.getPort(channel))

        if not hal.allocatePWMChannel(self._port):
            raise IndexError("PWM channel %d is already allocated" % channel)
        
        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)

        hal.setPWM(self._port, 0)

        self._pwm_finalizer = weakref.finalize(self, _freePWM, self._port)

        self.eliminateDeadband = False

        hal.HALReport(hal.HALUsageReporting.kResourceType_PWM, channel)
Exemplo n.º 26
0
    def __init__(self, channel):
        """Construct an analog channel.
        :param channel: The channel number to represent. 0-3 are on-board 4-7 are on the MXP port.
        """
        if not hal.checkAnalogInputChannel(channel):
            raise IndexError(
                "Analog input channel %d cannot be allocated. Channel is not present."
                % channel)
        try:
            AnalogInput.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Analog input channel %d is already allocated" %
                             channel) from e

        self.channel = channel
        self.accumulatorOffset = 0

        port = hal.getPort(channel)
        self.port = hal.initializeAnalogInputPort(port)

        LiveWindow.addSensorChannel("AnalogInput", channel, self)
        hal.HALReport(hal.HALUsageReporting.kResourceType_AnalogChannel,
                      channel)
Exemplo n.º 27
0
    def __init__(self, channel, input):
        """
            :param channel: Port for the digital input
            :type  channel: int
            :param input: True if input, False otherwise
            :type  input: int
        """
        super().__init__()

        self.channel = channel

        # XXX: Replace with hal.checkDigitalChannel when implemented
        SensorBase.checkDigitalChannel(channel)

        try:
            DigitalSource.channels.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Digital input %d is already allocated" %
                             self.channel) from e

        self._port = hal.initializeDigitalPort(hal.getPort(channel))
        hal.allocateDIO(self._port, True if input else False)

        self._port_finalizer = weakref.finalize(self, hal.freeDIO, self._port)