-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobot.java
128 lines (103 loc) · 4.03 KB
/
Robot.java
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// 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.
package frc.robot;
import edu.wpi.first.wpilibj.PowerDistribution;
import edu.wpi.first.wpilibj.PowerDistribution.ModuleType;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import org.littletonrobotics.junction.LogFileUtil;
import org.littletonrobotics.junction.LoggedRobot;
import org.littletonrobotics.junction.Logger;
import org.littletonrobotics.junction.networktables.NT4Publisher;
import org.littletonrobotics.junction.wpilog.WPILOGReader;
import org.littletonrobotics.junction.wpilog.WPILOGWriter;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends LoggedRobot {
@SuppressWarnings("unused")
private RobotContainer robotContainer;
@SuppressWarnings("unused")
private PowerDistribution pdh;
public Robot() {
super(Constants.loopTime);
}
@Override
public void robotInit() {
Logger.recordMetadata("ProjectName", "2024 - 401 Comp Robot"); // TODO: Name the robot!
Logger.recordMetadata("GitDate", BuildConstants.GIT_DATE);
Logger.recordMetadata("BuildDate", BuildConstants.BUILD_DATE);
Logger.recordMetadata("GitBranch", BuildConstants.GIT_BRANCH);
if (Constants.currentMode == Constants.Mode.REAL) {
// TODO: Log data to a USB drive on the RIO
// Logger.addDataReceiver(new WPILOGWriter()); // Log to a USB stick ("/U/logs")
Logger.addDataReceiver(new NT4Publisher()); // Publish data to NetworkTables
pdh = new PowerDistribution(1, ModuleType.kRev); // Enables power distribution logging
} else if (Constants.currentMode == Constants.Mode.SIM) {
Logger.addDataReceiver(new WPILOGWriter("logs/")); // This folder is gitignored
Logger.addDataReceiver(new NT4Publisher());
} else {
setUseTiming(false); // Run as fast as possible
String logPath = LogFileUtil.findReplayLog(); // Pull the replay log from AdvantageScope
// (or prompt the user)
Logger.setReplaySource(new WPILOGReader(logPath)); // Read replay log
Logger.addDataReceiver(
new WPILOGWriter(LogFileUtil.addPathSuffix(logPath, "_sim"))); // Save
// outputs
// to
// a
// new
// log
}
Logger.start();
robotContainer = new RobotContainer();
}
@Override
public void robotPeriodic() {
CommandScheduler.getInstance().run();
robotContainer.robotPeriodic();
}
@Override
public void autonomousInit() {
CommandScheduler.getInstance().cancelAll();
robotContainer.enabledInit();
if (robotContainer.getAutonomousCommand() != null) {
robotContainer.getAutonomousCommand().schedule();
}
}
@Override
public void autonomousPeriodic() {}
@Override
public void teleopInit() {
CommandScheduler.getInstance().cancelAll();
robotContainer.enabledInit();
robotContainer.teleopInit();
}
@Override
public void teleopPeriodic() {}
@Override
public void disabledInit() {
robotContainer.disabledInit();
}
@Override
public void disabledPeriodic() {
robotContainer.disabledPeriodic();
}
@Override
public void testInit() {
CommandScheduler.getInstance().cancelAll();
robotContainer.enabledInit();
robotContainer.testInit();
}
@Override
public void testPeriodic() {
robotContainer.testPeriodic();
}
@Override
public void simulationInit() {}
@Override
public void simulationPeriodic() {}
}