Esempio n. 1
0
    def setIndexSource(self,
                       source,
                       indexing_type=IndexingType.kResetOnRisingEdge):
        """
        Set the index source for the encoder. When this source rises, the encoder count automatically resets.

        :param source: Either an initialized DigitalSource or a DIO channel number
        :type: Either a :class:`wpilib.DigitalInput` or number
        :param indexing_type: The state that will cause the encoder to reset
        :type: A value from :class:`wpilib.DigitalInput.IndexingType`
        """
        if hasattr(source, "getChannelForRouting"):
            self.indexSource = source
        else:
            self.indexSource = DigitalInput(source)

        activeHigh = (indexing_type == self.IndexingType.kResetWhileHigh
                      or indexing_type == self.IndexingType.kResetOnRisingEdge)
        edgeSensitive = (indexing_type == self.IndexingType.kResetOnFallingEdge
                         or indexing_type
                         == self.IndexingType.kResetOnRisingEdge)

        hal.setEncoderIndexSource(
            self.encoder, self.indexSource.getChannelForRouting(),
            self.indexSource.getAnalogTriggerForRouting(), activeHigh,
            edgeSensitive)
Esempio n. 2
0
    def setIndexSource(self, source, indexing_type=IndexingType.kResetOnRisingEdge):
        """
        Set the index source for the encoder. When this source rises, the encoder count automatically resets.

        :param source: Either an initialized DigitalSource or a DIO channel number
        :type source: :class:`.DigitalInput` or int
        :param indexing_type: The state that will cause the encoder to reset
        :type indexing_type: :class:`.IndexingType`
        """
        if hasattr(source, "getPortHandleForRouting"):
            self.indexSource = source
        else:
            self.indexSource = DigitalInput(source)

        hal.setEncoderIndexSource(self.encoder, self.indexSource.getPortHandleForRouting(),
                                  self.indexSource.getAnalogTriggerTypeForRouting(), indexing_type)
Esempio n. 3
0
    def setIndexSource(self, source, indexing_type=IndexingType.kResetOnRisingEdge):
        """
        Set the index source for the encoder. When this source rises, the encoder count automatically resets.

        :param source: Either an initialized DigitalSource or a DIO channel number
        :type: Either a :class:`wpilib.DigitalInput` or number
        :param indexing_type: The state that will cause the encoder to reset
        :type: A value from :class:`wpilib.DigitalInput.IndexingType`
        """
        if hasattr(source, "getPortHandleForRouting"):
            self.indexSource = source
        else:
            self.indexSource = DigitalInput(source)

        hal.setEncoderIndexSource(self.encoder, self.indexSource.getPortHandleForRouting(),
                                  self.indexSource.getAnalogTriggerTypeForRouting(), indexing_type)
Esempio n. 4
0
    def setIndexSource(
        self,
        source: Union[int, DigitalInput],
        indexing_type: IndexingType = IndexingType.kResetOnRisingEdge,
    ) -> None:
        """
        Set the index source for the encoder. When this source rises, the encoder count automatically resets.

        :param source: Either an initialized DigitalSource or a DIO channel number
        :param indexing_type: The state that will cause the encoder to reset
        """
        if hasattr(source, "getPortHandleForRouting"):
            self.indexSource = source
        else:
            self.indexSource = DigitalInput(source)

        hal.setEncoderIndexSource(
            self.encoder,
            self.indexSource.getPortHandleForRouting(),
            self.indexSource.getAnalogTriggerTypeForRouting(),
            indexing_type,
        )