Skip to content

Commit 6a34403

Browse files
authored
Merge pull request #93 from FRC2539/timed
Makes CommandBasedRobot extend TimedRobot
2 parents 3011e3f + a30dffa commit 6a34403

File tree

1 file changed

+4
-50
lines changed

1 file changed

+4
-50
lines changed

commandbased/commandbasedrobot.py

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,21 @@
11
import hal
22

3-
from wpilib.iterativerobot import IterativeRobot
3+
from wpilib.timedrobot import TimedRobot
44
from wpilib.command.scheduler import Scheduler
55
from wpilib.livewindow import LiveWindow
66

77

8-
class CommandBasedRobot(IterativeRobot):
8+
class CommandBasedRobot(TimedRobot):
99
'''
1010
The base class for a Command-Based Robot. To use, instantiate commands and
1111
trigger them.
1212
'''
1313

1414
def startCompetition(self):
15-
"""
16-
Provide an alternate "main loop" via startCompetition(). Rewritten
17-
from IterativeRobot for readability and to initialize scheduler.
18-
"""
19-
20-
hal.report(hal.HALUsageReporting.kResourceType_Framework,
21-
hal.HALUsageReporting.kFramework_Iterative)
15+
"""Initalizes the scheduler before starting robotInit()"""
2216

2317
self.scheduler = Scheduler.getInstance()
24-
self.robotInit()
25-
26-
# Tell the DS that the robot is ready to be enabled
27-
hal.observeUserProgramStarting()
28-
29-
# loop forever, calling the appropriate mode-dependent function
30-
while True:
31-
if self.ds.isDisabled():
32-
hal.observeUserProgramDisabled()
33-
self.disabledInit()
34-
while self.ds.isDisabled():
35-
self.disabledPeriodic()
36-
self.ds.waitForData()
37-
38-
elif self.ds.isAutonomous():
39-
hal.observeUserProgramAutonomous()
40-
self.autonomousInit()
41-
while self.ds.isEnabled() and self.ds.isAutonomous():
42-
self.autonomousPeriodic()
43-
self.ds.waitForData()
44-
45-
elif self.ds.isTest():
46-
hal.observeUserProgramTest()
47-
LiveWindow.setEnabled(True)
48-
49-
self.testInit()
50-
while self.ds.isEnabled() and self.ds.isTest():
51-
self.testPeriodic()
52-
self.ds.waitForData()
53-
54-
LiveWindow.setEnabled(False)
55-
56-
else:
57-
hal.observeUserProgramTeleop()
58-
self.teleopInit()
59-
# isOperatorControl checks "not autonomous or test", so we need
60-
# to check isEnabled as well, since otherwise it will continue
61-
# looping while disabled.
62-
while self.ds.isEnabled() and self.ds.isOperatorControl():
63-
self.teleopPeriodic()
64-
self.ds.waitForData()
18+
super().startCompetition()
6519

6620

6721
def commandPeriodic(self):

0 commit comments

Comments
 (0)