Ejemplo n.º 1
0
    def __init__(self, moduleNumber):
        """Constructor.

        :param moduleNumber: The PCM CAN ID
        """
        self.moduleNumber = moduleNumber

        if moduleNumber not in self.all_ports:
            self.all_ports[moduleNumber] = []

            for i in range(SensorBase.kSolenoidChannels):
                port = hal.getPortWithModule(moduleNumber, i)
                self.all_ports[moduleNumber].append(
                    hal.initializeSolenoidPort(port))

        if moduleNumber not in self.all_mutex:
            self.all_mutex[moduleNumber] = threading.Lock()

        if moduleNumber not in self.all_allocated:
            self.all_allocated[moduleNumber] = Resource(
                SensorBase.kSolenoidChannels)

        self.allocated = self.all_allocated[moduleNumber]
        self.ports = self.all_ports[moduleNumber]
        self.mutex = self.all_mutex[moduleNumber]
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - channel
        - moduleNumber, channel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The CAN ID of the PCM the solenoid is attached to
        :type moduleNumber: int
        :param channel: The channel on the PCM to control (0..7)
        :type channel: int
        """
        # keyword arguments
        channel = kwargs.pop("channel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn("unknown keyword arguments: %s" % kwargs.keys(),
                          RuntimeWarning)

        # positional arguments
        if len(args) == 1:
            channel = args[0]
        elif len(args) == 2:
            moduleNumber, channel = args
        elif len(args) != 0:
            raise ValueError(
                "don't know how to handle %d positional arguments" % len(args))

        if moduleNumber is None:
            moduleNumber = SensorBase.getDefaultSolenoidModule()
        if channel is None:
            raise ValueError("must specify channel")

        super().__init__(moduleNumber)
        self.channel = channel
        self.valueEntry = None

        SensorBase.checkSolenoidModule(moduleNumber)
        SensorBase.checkSolenoidChannel(channel)

        portHandle = hal.getPortWithModule(moduleNumber, channel)
        self._solenoidHandle = hal.initializeSolenoidPort(portHandle)

        LiveWindow.addActuatorModuleChannel("Solenoid", moduleNumber, channel,
                                            self)
        hal.report(hal.UsageReporting.kResourceType_Solenoid, channel,
                   moduleNumber)

        self.__finalizer = weakref.finalize(self, _freeSolenoid,
                                            self._solenoidHandle)

        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - channel
        - moduleNumber, channel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The CAN ID of the PCM the solenoid is attached to
        :type moduleNumber: int
        :param channel: The channel on the PCM to control (0..7)
        :type channel: int
        """
        # keyword arguments
        channel = kwargs.pop("channel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn("unknown keyword arguments: %s" % kwargs.keys(),
                          RuntimeWarning)

        # positional arguments
        if len(args) == 1:
            channel = args[0]
        elif len(args) == 2:
            moduleNumber, channel = args
        elif len(args) != 0:
            raise ValueError("don't know how to handle %d positional arguments" % len(args))

        if moduleNumber is None:
            moduleNumber = SensorBase.getDefaultSolenoidModule()
        if channel is None:
            raise ValueError("must specify channel")

        SensorBase.checkSolenoidModule(moduleNumber)
        SensorBase.checkSolenoidChannel(channel)

        super().__init__(moduleNumber)
        self.channel = channel

        try:
            self.allocated.allocate(self, channel)
        except IndexError as e:
            raise IndexError("Solenoid channel %d on module %d is already allocated" % (channel, moduleNumber)) from e

        modulePort = hal.getPortWithModule(moduleNumber, channel)
        self._port = hal.initializeSolenoidPort(modulePort)

        LiveWindow.addActuatorModuleChannel("Solenoid", moduleNumber, channel,
                                            self)
        hal.HALReport(hal.HALUsageReporting.kResourceType_Solenoid, channel,
                      moduleNumber)
        
        self.__finalizer = weakref.finalize(self, _freeSolenoid, modulePort, self._port)
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs) -> None:
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - channel
        - moduleNumber, channel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The CAN ID of the PCM the solenoid is attached to
        :type moduleNumber: int
        :param channel: The channel on the PCM to control (0..7)
        :type channel: int
        """
        # keyword arguments
        channel = kwargs.pop("channel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn(
                "unknown keyword arguments: %s" % kwargs.keys(), RuntimeWarning
            )

        # positional arguments
        if len(args) == 1:
            channel = args[0]
        elif len(args) == 2:
            moduleNumber, channel = args
        elif len(args) != 0:
            raise ValueError(
                "don't know how to handle %d positional arguments" % len(args)
            )

        if moduleNumber is None:
            moduleNumber = SensorUtil.getDefaultSolenoidModule()
        if channel is None:
            raise ValueError("must specify channel")

        super().__init__(moduleNumber)
        self.channel = channel

        SensorUtil.checkSolenoidModule(moduleNumber)
        SensorUtil.checkSolenoidChannel(channel)

        portHandle = hal.getPortWithModule(moduleNumber, channel)
        self.solenoidHandle = hal.initializeSolenoidPort(portHandle)

        hal.report(hal.UsageReporting.kResourceType_Solenoid, channel, moduleNumber)
        self.setName("Solenoid", self.moduleNumber, self.channel)

        self.__finalizer = weakref.finalize(self, _freeSolenoid, self.solenoidHandle)

        # Need this to free on unit test wpilib reset
        Resource._add_global_resource(self)
Ejemplo n.º 5
0
    def __init__(self, moduleNumber):
        """Constructor.

        :param moduleNumber: The PCM CAN ID
        """
        self.moduleNumber = moduleNumber

        if moduleNumber not in self.all_ports:
            self.all_ports[moduleNumber] = []

            for i in range(SensorBase.kSolenoidChannels):
                port = hal.getPortWithModule(moduleNumber, i)
                self.all_ports[moduleNumber].append(hal.initializeSolenoidPort(port))

        if moduleNumber not in self.all_mutex:
            self.all_mutex[moduleNumber] = threading.Lock()

        if moduleNumber not in self.all_allocated:
            self.all_allocated[moduleNumber] = Resource(SensorBase.kSolenoidChannels)

        self.allocated = self.all_allocated[moduleNumber]
        self.ports = self.all_ports[moduleNumber]
        self.mutex = self.all_mutex[moduleNumber]
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - forwardChannel, reverseChannel
        - moduleNumber, forwardChannel, reverseChannel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The module number of the solenoid module to use.
        :param forwardChannel: The forward channel number on the module to control (0..7)
        :param reverseChannel: The reverse channel number on the module to control  (0..7)
        """
        # keyword arguments
        forwardChannel = kwargs.pop("forwardChannel", None)
        reverseChannel = kwargs.pop("reverseChannel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn("unknown keyword arguments: %s" % kwargs.keys(),
                          RuntimeWarning)

        # positional arguments
        if len(args) == 2:
            forwardChannel, reverseChannel = args
        elif len(args) == 3:
            moduleNumber, forwardChannel, reverseChannel = args
        elif len(args) != 0:
            raise ValueError("don't know how to handle %d positional arguments" % len(args))

        if moduleNumber is None:
            moduleNumber = SensorBase.getDefaultSolenoidModule()
        if forwardChannel is None:
            raise ValueError("must specify forward channel")
        if reverseChannel is None:
            raise ValueError("must specify reverse channel")

        super().__init__(moduleNumber)
        
        self.valueEntry = None
        SensorBase.checkSolenoidModule(moduleNumber)
        SensorBase.checkSolenoidChannel(forwardChannel)
        SensorBase.checkSolenoidChannel(reverseChannel)

        portHandle = hal.getPortWithModule(moduleNumber, forwardChannel)
        self.forwardHandle = hal.initializeSolenoidPort(portHandle)
        
        try:
            portHandle = hal.getPortWithModule(moduleNumber, reverseChannel)
            self.reverseHandle = hal.initializeSolenoidPort(portHandle)
        except Exception:
            # free the forward handle on exception, then rethrow
            hal.freeSolenoidPort(self.forwardHandle)
            self.forwardHandle = None
            self.reverseHandle = None
            raise

        self.forwardMask = 1 << forwardChannel
        self.reverseMask = 1 << reverseChannel

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

        hal.report(hal.UsageReporting.kResourceType_Solenoid,
                      forwardChannel, moduleNumber)
        hal.report(hal.UsageReporting.kResourceType_Solenoid,
                      reverseChannel, moduleNumber)

        LiveWindow.addActuatorModuleChannel("DoubleSolenoid", moduleNumber,
                                            forwardChannel, self)
        
        self.__finalizer = weakref.finalize(self, _freeSolenoid,
                                            self.forwardHandle, self.reverseHandle)
Ejemplo n.º 7
0
    def __init__(self, *args, **kwargs) -> None:
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - forwardChannel, reverseChannel
        - moduleNumber, forwardChannel, reverseChannel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The module number of the solenoid module to use.
        :param forwardChannel: The forward channel number on the module to control (0..7)
        :param reverseChannel: The reverse channel number on the module to control  (0..7)
        """
        # keyword arguments
        forwardChannel = kwargs.pop("forwardChannel", None)
        reverseChannel = kwargs.pop("reverseChannel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn(
                "unknown keyword arguments: %s" % kwargs.keys(), RuntimeWarning
            )

        # positional arguments
        if len(args) == 2:
            forwardChannel, reverseChannel = args
        elif len(args) == 3:
            moduleNumber, forwardChannel, reverseChannel = args
        elif len(args) != 0:
            raise ValueError(
                "don't know how to handle %d positional arguments" % len(args)
            )

        if moduleNumber is None:
            moduleNumber = SensorUtil.getDefaultSolenoidModule()
        if forwardChannel is None:
            raise ValueError("must specify forward channel")
        if reverseChannel is None:
            raise ValueError("must specify reverse channel")

        super().__init__(moduleNumber)

        self.valueEntry = None
        SensorUtil.checkSolenoidModule(moduleNumber)
        SensorUtil.checkSolenoidChannel(forwardChannel)
        SensorUtil.checkSolenoidChannel(reverseChannel)

        portHandle = hal.getPortWithModule(moduleNumber, forwardChannel)
        self.forwardHandle = hal.initializeSolenoidPort(portHandle)

        try:
            portHandle = hal.getPortWithModule(moduleNumber, reverseChannel)
            self.reverseHandle = hal.initializeSolenoidPort(portHandle)
        except Exception:
            # free the forward handle on exception, then rethrow
            hal.freeSolenoidPort(self.forwardHandle)
            self.forwardHandle = None
            self.reverseHandle = None
            raise

        self.forwardMask = 1 << forwardChannel
        self.reverseMask = 1 << reverseChannel

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

        hal.report(
            hal.UsageReporting.kResourceType_Solenoid, forwardChannel, moduleNumber
        )
        hal.report(
            hal.UsageReporting.kResourceType_Solenoid, reverseChannel, moduleNumber
        )

        self.setName("DoubleSolenoid", moduleNumber, forwardChannel)

        self.__finalizer = weakref.finalize(
            self, _freeSolenoid, self.forwardHandle, self.reverseHandle
        )
    def __init__(self, *args, **kwargs):
        """Constructor.

        Arguments can be supplied as positional or keyword.  Acceptable
        positional argument combinations are:
        
        - forwardChannel, reverseChannel
        - moduleNumber, forwardChannel, reverseChannel

        Alternatively, the above names can be used as keyword arguments.

        :param moduleNumber: The module number of the solenoid module to use.
        :param forwardChannel: The forward channel number on the module to control (0..7)
        :param reverseChannel: The reverse channel number on the module to control  (0..7)
        """
        # keyword arguments
        forwardChannel = kwargs.pop("forwardChannel", None)
        reverseChannel = kwargs.pop("reverseChannel", None)
        moduleNumber = kwargs.pop("moduleNumber", None)

        if kwargs:
            warnings.warn("unknown keyword arguments: %s" % kwargs.keys(),
                          RuntimeWarning)

        # positional arguments
        if len(args) == 2:
            forwardChannel, reverseChannel = args
        elif len(args) == 3:
            moduleNumber, forwardChannel, reverseChannel = args
        elif len(args) != 0:
            raise ValueError("don't know how to handle %d positional arguments" % len(args))

        if moduleNumber is None:
            moduleNumber = SensorBase.getDefaultSolenoidModule()
        if forwardChannel is None:
            raise ValueError("must specify forward channel")
        if reverseChannel is None:
            raise ValueError("must specify reverse channel")

        SensorBase.checkSolenoidModule(moduleNumber)
        SensorBase.checkSolenoidChannel(forwardChannel)
        SensorBase.checkSolenoidChannel(reverseChannel)

        super().__init__(moduleNumber)
        try:
            self.allocated.allocate(self, forwardChannel)
        except IndexError as e:
            raise IndexError("Solenoid channel %d on module %d is already allocated" % (forwardChannel, moduleNumber)) from e
        try:
            self.allocated.allocate(self, reverseChannel)
        except IndexError as e:
            raise IndexError("Solenoid channel %d on module %d is already allocated" % (reverseChannel, moduleNumber)) from e

        portHandle = hal.getPortWithModule(moduleNumber, forwardChannel)
        self.forwardHandle = hal.initializeSolenoidPort(portHandle)
        portHandle = hal.getPortWithModule(moduleNumber, reverseChannel)
        self.reverseHandle = hal.initializeSolenoidPort(portHandle)

        self.forwardChannel = forwardChannel
        self.reverseChannel = reverseChannel
        self.forwardMask = 1 << forwardChannel
        self.reverseMask = 1 << reverseChannel

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

        hal.report(hal.UsageReporting.kResourceType_Solenoid,
                      forwardChannel, moduleNumber)
        hal.report(hal.UsageReporting.kResourceType_Solenoid,
                      reverseChannel, moduleNumber)

        LiveWindow.addActuatorModuleChannel("DoubleSolenoid", moduleNumber,
                                            forwardChannel, self)
Ejemplo n.º 9
0
 def __init__(self, channel):
     portHandle = hal.getPortWithModule(0, channel)
     handle, status = hal.initializeSolenoidPort(portHandle)
     if status != 0:
         raise HALError(status)
     self.solenoidHandle = handle