forked from SteelRidgeRobotics/2024MetalMelody
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
78 lines (59 loc) · 3.01 KB
/
robot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/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
import commands2
import typing
from robotcontainer import RobotContainer
class MetalMelody(commands2.TimedCommandRobot):
"""
Command v2 robots are encouraged to inherit from TimedCommandRobot, which
has an implementation of robotPeriodic which runs the scheduler for you
"""
autonomousCommand: typing.Optional[commands2.Command] = None
def __init__(self, period = wpilib.TimedRobot.kDefaultPeriod / 1000):
super().__init__(period)
# Instantiate our RobotContainer. This will perform all our button bindings, and put our
# autonomous chooser on the dashboard.
self.container = RobotContainer()
wpilib.DriverStation.silenceJoystickConnectionWarning(not wpilib.DriverStation.isFMSAttached())
def robotPeriodic(self) -> None:
"""This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
that you want ran during disabled, autonomous, teleoperated and test.
This runs after the mode specific periodic functions, but before LiveWindow and
SmartDashboard integrated updating."""
# Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
# commands, running already-scheduled commands, removing finished or interrupted commands,
# and running subsystem periodic() methods. This must be called from the robot's periodic
# block in order for anything in the Command-based framework to work.
commands2.CommandScheduler.getInstance().run()
def disabledInit(self) -> None:
"""This function is called once each time the robot enters Disabled mode."""
pass
def disabledPeriodic(self) -> None:
"""This function is called periodically when disabled"""
pass
def autonomousInit(self) -> None:
"""This autonomous runs the autonomous command selected by your RobotContainer class."""
self.autonomousCommand = self.container.getAutonomousCommand()
if self.autonomousCommand:
self.autonomousCommand.schedule()
def autonomousPeriodic(self) -> None:
"""This function is called periodically during autonomous"""
pass
def teleopInit(self) -> None:
# This makes sure that the autonomous stops running when
# teleop starts running. If you want the autonomous to
# continue until interrupted by another command, remove
# this line or comment it out.
if self.autonomousCommand:
self.autonomousCommand.cancel()
def teleopPeriodic(self) -> None:
"""This function is called periodically during operator control"""
pass
def testInit(self) -> None:
# Cancels all running commands at the start of test mode
commands2.CommandScheduler.getInstance().cancelAll()