How to use the wpilib.SmartDashboard 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 / examples / examples / GearsBot / robot.py View on Github external
def robotInit(self):
        '''This function is run when the robot is first started up and should be
           used for any initialization code.'''
        
        self.drivetrain = DriveTrain(self)
        self.elevator = Elevator(self)
        self.wrist = Wrist(self)
        self.claw = Claw()
        self.oi = OI(self)

        # instantiate the command used for the autonomous period
        self.autonomousCommand = Autonomous(self)
       
        # Show what command your subsystem is running on the SmartDashboard
        wpilib.SmartDashboard.putData(self.drivetrain)
        wpilib.SmartDashboard.putData(self.elevator)
        wpilib.SmartDashboard.putData(self.wrist)
        wpilib.SmartDashboard.putData(self.claw)
github robotpy / robotpy-wpilib-utilities / magicbot / magicrobot.py View on Github external
# Load autonomous modes
        self._automodes = AutonomousModeSelector("autonomous")

        # Next, create the robot components and wire them together
        self._create_components()

        self.__nt = NetworkTables.getTable("/robot")

        self.__nt_put_is_ds_attached = self.__nt.getEntry("is_ds_attached").setBoolean
        self.__nt_put_mode = self.__nt.getEntry("mode").setString

        self.__nt.putBoolean("is_simulation", self.isSimulation())
        self.__nt_put_is_ds_attached(self.ds.isDSAttached())

        # cache these
        self.__sd_update = wpilib.SmartDashboard.updateValues
        self.__lv_update = wpilib.LiveWindow.getInstance().updateValues
        # self.__sf_update = Shuffleboard.update

        self.watchdog = SimpleWatchdog(self.control_loop_wait_time)

        self.__periodics = [(self.robotPeriodic, "robotPeriodic()")]

        if self.isSimulation():
            self._simulationInit()
            self.__periodics.append((self._simulationPeriodic, "simulationPeriodic()"))
github robotpy / robotpy-wpilib / examples / examples / pacgoat / robot.py View on Github external
def robotInit(self):
        """
        This function is run when the robot is first started up and should be
        used for any initialization code.
        """

        # Initialize the subsystems
        self.drivetrain = DriveTrain(self)
        self.collector = Collector(self)
        self.shooter = Shooter(self)
        self.pneumatics = Pneumatics(self)
        self.pivot = Pivot(self)
        wpilib.SmartDashboard.putData(self.drivetrain)
        wpilib.SmartDashboard.putData(self.collector)
        wpilib.SmartDashboard.putData(self.shooter)
        wpilib.SmartDashboard.putData(self.pneumatics)
        wpilib.SmartDashboard.putData(self.pivot)

        # This MUST be here. If the OI creates Commands (which it very likely
        # will), constructing it during the construction of CommandBase (from
        # which commands extend), subsystems are not guaranteed to be
        # yet. Thus, their requires() statements may grab null pointers. Bad
        # news. Don't move it.
        self.oi = OI(self)

        #instantiate the command used for the autonomous period
        self.autoChooser = wpilib.SendableChooser()
        self.autoChooser.addDefault("Drive and Shoot", DriveAndShootAutonomous(self))
        self.autoChooser.addObject("Drive Forward", DriveForward(self))
github wpilibsuite / frc-characterization / drive_characterization / robot / robot-python-talonsrx / robot.py View on Github external
def robotPeriodic(self):
        # feedback for users, but not used by the control program
        sd = wpilib.SmartDashboard
        sd.putNumber("l_encoder_pos", self.l_encoder_getpos())
        sd.putNumber("l_encoder_rate", self.l_encoder_getrate())
        sd.putNumber("r_encoder_pos", self.r_encoder_getpos())
        sd.putNumber("r_encoder_rate", self.r_encoder_getrate())
github robotpy / robotpy-wpilib / examples / examples / pacgoat / oi.py View on Github external
def __init__(self, robot):
        self.joystick = wpilib.Joystick(0)

        JoystickButton(self.joystick, 12).whenPressed(LowGoal(robot))
        JoystickButton(self.joystick, 10).whenPressed(Collect(robot))

        JoystickButton(self.joystick, 11).whenPressed(SetPivotSetpoint(robot, Pivot.SHOOT))
        JoystickButton(self.joystick, 9).whenPressed(SetPivotSetpoint(robot, Pivot.SHOOT_NEAR))

        DoubleButton(self.joystick, 2, 3).whenActive(Shoot(robot))

        #SmartDashboard Buttons
        SmartDashboard.putData("Drive Forward", DriveForward(robot,2.25))
        SmartDashboard.putData("Drive Backward", DriveForward(robot,-2.25))
        SmartDashboard.putData("Start Rollers", SetCollectionSpeed(robot,Collector.FORWARD))
        SmartDashboard.putData("Stop Rollers", SetCollectionSpeed(robot,Collector.STOP))
        SmartDashboard.putData("Reverse Rollers", SetCollectionSpeed(robot,Collector.REVERSE))
github robotpy / robotpy-wpilib-utilities / robotpy_ext / autonomous / selector.py View on Github external
if len(self.modes) == 0:
            logger.warning("-- no autonomous modes were loaded!")

        self.chooser.addOption("None", None)

        if len(default_modes) == 0:
            self.chooser.setDefaultOption("None", None)
        elif len(default_modes) != 1:
            if not self.ds.isFMSAttached():
                raise RuntimeError(
                    "More than one autonomous mode was specified as default! (modes: %s)"
                    % (", ".join(default_modes))
                )

        # must PutData after setting up objects
        wpilib.SmartDashboard.putData("Autonomous Mode", self.chooser)

        # XXX: Compatibility with the FRC dashboard
        wpilib.SmartDashboard.putStringArray("Auto List", mode_names)

        logger.info("Autonomous switcher initialized")
github robotpy / pynetworktables / samples / json_logger / robot.py View on Github external
def autonomousPeriodic(self):
        """Called every 20ms in autonomous mode"""
        self.useless += 1

        # Obviously, this is fabricated... do something more useful!
        data1 = self.useless
        data2 = self.useless * 2

        # Only write once per loop
        wpilib.SmartDashboard.putNumberArray(
            "log_data", [wpilib.Timer.getFPGATimestamp(), data1, data2]
        )
github robotpy / robotpy-wpilib-utilities / robotpy_ext / autonomous / selector.py View on Github external
self.chooser.addOption("None", None)

        if len(default_modes) == 0:
            self.chooser.setDefaultOption("None", None)
        elif len(default_modes) != 1:
            if not self.ds.isFMSAttached():
                raise RuntimeError(
                    "More than one autonomous mode was specified as default! (modes: %s)"
                    % (", ".join(default_modes))
                )

        # must PutData after setting up objects
        wpilib.SmartDashboard.putData("Autonomous Mode", self.chooser)

        # XXX: Compatibility with the FRC dashboard
        wpilib.SmartDashboard.putStringArray("Auto List", mode_names)

        logger.info("Autonomous switcher initialized")
github wpilibsuite / frc-characterization / elevator_characterization / robot / robot-python-spark / robot.py View on Github external
def robotPeriodic(self):
        # feedback for users, but not used by the control program
        sd = wpilib.SmartDashboard
        sd.putNumber("encoder_pos", self.encoder_getpos())
        sd.putNumber("encoder_rate", self.encoder_getrate())