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)
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 _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)
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 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.__finalizer = weakref.finalize(self, _freeDigitalSource, self._port)
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)
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)