|
1 | 1 | import hal
|
2 | 2 |
|
3 |
| -from wpilib.iterativerobot import IterativeRobot |
| 3 | +from wpilib.timedrobot import TimedRobot |
4 | 4 | from wpilib.command.scheduler import Scheduler
|
5 | 5 | from wpilib.livewindow import LiveWindow
|
6 | 6 |
|
7 | 7 |
|
8 |
| -class CommandBasedRobot(IterativeRobot): |
| 8 | +class CommandBasedRobot(TimedRobot): |
9 | 9 | '''
|
10 | 10 | The base class for a Command-Based Robot. To use, instantiate commands and
|
11 | 11 | trigger them.
|
12 | 12 | '''
|
13 | 13 |
|
14 | 14 | 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()""" |
22 | 16 |
|
23 | 17 | 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() |
65 | 19 |
|
66 | 20 |
|
67 | 21 | def commandPeriodic(self):
|
|
0 commit comments