mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[robotpy][examples] Split examples and snippets (#8944)
This also updates the bazel scripts to behave more like the C++ and Java examples, and updates the copybara scripts to be able to sync up `mostrobotpy`
This commit is contained in:
49
robotpyExamples/snippets/DigitalCommunication/robot.py
Executable file
49
robotpyExamples/snippets/DigitalCommunication/robot.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) FIRST and other WPILib contributors.
|
||||
# Open Source Software; you can modify and/or share it under the terms of
|
||||
# the WPILib BSD license file in the root directory of this project.
|
||||
#
|
||||
|
||||
import wpilib
|
||||
|
||||
|
||||
class MyRobot(wpilib.TimedRobot):
|
||||
"""
|
||||
This is a sample program demonstrating how to communicate to a light controller from the robot
|
||||
code using the roboRIO's DIO ports.
|
||||
"""
|
||||
|
||||
# define ports for digitalcommunication with light controller
|
||||
kAlliancePort = 0
|
||||
kEnabledPort = 1
|
||||
kAutonomousPort = 2
|
||||
kAlertPort = 3
|
||||
|
||||
def __init__(self):
|
||||
"""Robot initialization function"""
|
||||
super().__init__()
|
||||
|
||||
self.allianceOutput = wpilib.DigitalOutput(self.kAlliancePort)
|
||||
self.enabledOutput = wpilib.DigitalOutput(self.kEnabledPort)
|
||||
self.autonomousOutput = wpilib.DigitalOutput(self.kAutonomousPort)
|
||||
self.alertOutput = wpilib.DigitalOutput(self.kAlertPort)
|
||||
|
||||
def robotPeriodic(self):
|
||||
setAlliance = False
|
||||
alliance = wpilib.MatchState.getAlliance()
|
||||
if alliance:
|
||||
setAlliance = alliance == wpilib.Alliance.RED
|
||||
|
||||
# pull alliance port high if on red alliance, pull low if on blue alliance
|
||||
self.allianceOutput.set(setAlliance)
|
||||
|
||||
# pull enabled port high if enabled, low if disabled
|
||||
self.enabledOutput.set(wpilib.RobotState.isEnabled())
|
||||
|
||||
# pull auto port high if in autonomous, low if in teleop (or disabled)
|
||||
self.autonomousOutput.set(wpilib.RobotState.isAutonomous())
|
||||
|
||||
# pull alert port high if match time remaining is between 30 and 25 seconds
|
||||
matchTime = wpilib.MatchState.getMatchTime()
|
||||
self.alertOutput.set(30 >= matchTime >= 25)
|
||||
Reference in New Issue
Block a user