How to use the wpilib.wpilib.sendablebase.SendableBase function in wpilib

To help you get started, we’ve selected a few wpilib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robotpy / robotpy-wpilib / wpilib / wpilib / buttons / trigger.py View on Github external
# validated: 2018-10-30 EN 0a2ab4f0d782 edu/wpi/first/wpilibj/buttons/Trigger.java
# ----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2017. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
# must be accompanied by the FIRST BSD license file in the root directory of
# the project.
# ----------------------------------------------------------------------------

from ..command import command
from ..sendablebase import SendableBase
from ..sendablebuilder import SendableBuilder

__all__ = ["Trigger"]


class Trigger(SendableBase):
    """This class provides an easy way to link commands to inputs.

    It is very easy to link a button to a command.  For instance, you could
    link the trigger button of a joystick to a "score" command.

    It is encouraged that teams write a subclass of Trigger if they want to
    have something unusual (for instance, if they want to react to the user
    holding a button while the robot is reading a certain sensor input).
    For this, they only have to write the :func:`get` method to get the full
    functionality of the Trigger class.
    """

    def get(self) -> bool:
        """Returns whether or not the trigger is active

        This method will be called repeatedly a command is linked to the
github robotpy / robotpy-wpilib / wpilib / wpilib / speedcontrollergroup.py View on Github external
def __init__(
        self, speedController: SpeedController, *args: SpeedController
    ) -> None:
        """Create a new SpeedControllerGroup with the provided SpeedControllers.

        :param args: SpeedControllers to add
        """
        SendableBase.__init__(self)
        SpeedController.__init__(self)

        self.speedControllers = [speedController] + list(args)

        for speedcontroller in self.speedControllers:
            self.addChild(speedcontroller)

        self.isInverted = False

        SpeedControllerGroup.instances += 1
        self.setName("SpeedControllerGroup", self.instances)
github robotpy / robotpy-wpilib / wpilib / wpilib / digitalglitchfilter.py View on Github external
from typing import Union

import hal
import threading

from .digitalsource import DigitalSource
from .encoder import Encoder
from .counter import Counter
from .sendablebuilder import SendableBuilder
from .sensorutil import SensorUtil
from .sendablebase import SendableBase

__all__ = ["DigitalGlitchFilter"]


class DigitalGlitchFilter(SendableBase):
    """
    Class to enable glitch filtering on a set of digital inputs.
    This class will manage adding and removing digital inputs from a FPGA glitch
    filter. The filter lets the user configure the time that an input must remain
    high or low before it is classified as high or low.
    """

    mutex = threading.Lock()
    filterAllocated = [False] * 3

    def __init__(self) -> None:
        super().__init__()
        self.channelIndex = -1
        with self.mutex:
            for i, v in enumerate(self.filterAllocated):
                if not v:
github robotpy / robotpy-wpilib / wpilib / wpilib / analogtrigger.py View on Github external
import hal
from .analoginput import AnalogInput
from .analogtriggeroutput import AnalogTriggerOutput
from .resource import Resource
from .sendablebase import SendableBase
from .sendablebuilder import SendableBuilder

__all__ = ["AnalogTrigger"]


def _freeAnalogTrigger(port: hal.AnalogTriggerHandle) -> None:
    hal.cleanAnalogTrigger(port)


class AnalogTrigger(SendableBase):
    """
        Converts an analog signal into a digital signal
        
        An analog trigger is a way to convert an analog signal into a digital
        signal using resources built into the FPGA. The resulting digital
        signal can then be used directly or fed into other digital components
        of the FPGA such as the counter or encoder modules. The analog trigger
        module works by comparing analog signals to a voltage range set by
        the code. The specific return types and meanings depend on the analog
        trigger mode in use.
        
        .. not_implemented: initTrigger
    """

    AnalogTriggerType = AnalogTriggerOutput.AnalogTriggerType
github robotpy / robotpy-wpilib / wpilib / wpilib / analogoutput.py View on Github external
import hal
import weakref

from .resource import Resource
from .sendablebase import SendableBase
from .sensorutil import SensorUtil
from .sendablebuilder import SendableBuilder

__all__ = ["AnalogOutput"]


def _freeAnalogOutput(port: hal.AnalogOutputHandle) -> None:
    hal.freeAnalogOutputPort(port)


class AnalogOutput(SendableBase):
    """Analog output"""

    channels = Resource(SensorUtil.kAnalogOutputChannels)

    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)
github robotpy / robotpy-wpilib / wpilib / wpilib / sensorbase.py View on Github external
# validated: 2018-01-01 EN f9bece2ffbf7 edu/wpi/first/wpilibj/SensorBase.java
# ----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2016. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
# must be accompanied by the FIRST BSD license file in the root directory of
# the project.
# ----------------------------------------------------------------------------

import hal

from .sendablebase import SendableBase

__all__ = ["SensorBase"]


class SensorBase(SendableBase):
    """Base class for all sensors
    
    Stores most recent status information as well as containing utility
    functions for checking channels and error processing.
    """

    #: Ticks per microsecond
    kSystemClockTicksPerMicrosecond = hal.getSystemClockTicksPerMicrosecond()

    #: Number of digital channels per roboRIO
    kDigitalChannels = hal.getNumDigitalChannels()

    #: Number of analog input channels per roboRIO
    kAnalogInputChannels = hal.getNumAnalogInputs()

    #: Number of analog output channels per roboRIO
github robotpy / robotpy-wpilib / wpilib / wpilib / drive / robotdrivebase.py View on Github external
# ----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2017. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
# must be accompanied by the FIRST BSD license file in the root directory of
# the project.
# ----------------------------------------------------------------------------
import enum
from typing import List

from ..motorsafety import MotorSafety
from ..sendablebase import SendableBase

__all__ = ["RobotDriveBase"]


class RobotDriveBase(SendableBase, MotorSafety):
    """Common base class for drive platforms"""

    class MotorType(enum.IntEnum):
        """The location of a motor on the robot for the purpose of driving."""

        #: Front left
        kFrontLeft = 0

        #: Front right
        kFrontRight = 1

        #: Rear left
        kRearLeft = 2

        #: Rear right
        kRearRight = 3
github robotpy / robotpy-wpilib / wpilib / wpilib / adxl345_i2c.py View on Github external
# the project.
# ----------------------------------------------------------------------------
import enum

from typing import Tuple, Optional

import hal
from .i2c import I2C
from .sendablebase import SendableBase
from .interfaces import Accelerometer
from .sendablebuilder import SendableBuilder

__all__ = ["ADXL345_I2C"]


class ADXL345_I2C(SendableBase):
    """
        ADXL345 accelerometer device via i2c
    """

    kAddress = 0x1D
    kPowerCtlRegister = 0x2D
    kDataFormatRegister = 0x31
    kDataRegister = 0x32
    kGsPerLSB = 0.00390625

    kPowerCtl_Link = 0x20
    kPowerCtl_AutoSleep = 0x10
    kPowerCtl_Measure = 0x08
    kPowerCtl_Sleep = 0x04

    kDataFormat_SelfTest = 0x80
github robotpy / robotpy-wpilib / wpilib / wpilib / adxl345_spi.py View on Github external
# the project.
# ----------------------------------------------------------------------------
import enum
from typing import Tuple

import hal

from .interfaces import Accelerometer
from .spi import SPI
from .sendablebase import SendableBase
from .sendablebuilder import SendableBuilder

__all__ = ["ADXL345_SPI"]


class ADXL345_SPI(SendableBase):
    """
        ADXL345 accelerometer device via spi
        
        .. not_implemented: init
    """

    kPowerCtlRegister = 0x2D
    kDataFormatRegister = 0x31
    kDataRegister = 0x32
    kGsPerLSB = 0.00390625

    kAddress_Read = 0x80
    kAddress_MultiByte = 0x40

    kPowerCtl_Link = 0x20
    kPowerCtl_AutoSleep = 0x10
github robotpy / robotpy-wpilib / wpilib / wpilib / counter.py View on Github external
def _freeCounter(counterObj: "Counter") -> None:
    hal.setCounterUpdateWhenEmpty(counterObj.counter, True)

    counterObj.clearUpSource()
    counterObj.clearDownSource()

    hal.freeCounter(counterObj.counter)

    counterObj.upSource = None
    counterObj.downSource = None
    counterObj.counter = None


class Counter(SendableBase):
    """Counts the number of ticks on a :class:`.DigitalInput` channel.
    
    This is a general purpose class for counting repetitive events. It can return
    the number of counts, the period of the most recent cycle, and detect when
    the signal being counted has stopped by supplying a maximum cycle time.

    All counters will immediately start counting - :meth:`reset` them if you need
    them to be zeroed before use.
    
    .. not_implemented: initCounter
    """

    class Mode(enum.IntEnum):
        """Mode determines how and what the counter counts"""

        #: two pulse mode