-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotControllerBase.java
More file actions
137 lines (114 loc) · 4.55 KB
/
Copy pathRobotControllerBase.java
File metadata and controls
137 lines (114 loc) · 4.55 KB
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
129
130
131
132
133
134
135
136
137
package org.firstinspires.ftc.teamcode;
import com.bylazar.camerastream.PanelsCameraStream;
import com.bylazar.telemetry.JoinedTelemetry;
import com.bylazar.telemetry.PanelsTelemetry;
import com.pedropathing.follower.Follower;
import com.seattlesolvers.solverslib.command.CommandScheduler;
import com.seattlesolvers.solverslib.gamepad.GamepadEx;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.hardware.HardwareMap;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import org.firstinspires.ftc.teamcode.managers.RobotPositionManager;
import org.firstinspires.ftc.teamcode.pedropathing.Constants;
import org.firstinspires.ftc.teamcode.util.DataLogger;
import org.firstinspires.ftc.teamcode.util.opModes.SympleCommandOpMode;
public abstract class RobotControllerBase {
public final GamepadEx driverController;
public final GamepadEx actionController;
private final HardwareMap hardwareMap;
private final JoinedTelemetry telemetry;
private final DataLogger dataLogger;
private final Follower pathFollower;
public RobotControllerBase(HardwareMap hMap, Telemetry telemetry, Gamepad driverController, Gamepad actionController, String logFilePrefix, boolean logData) {
this.hardwareMap = hMap;
this.telemetry = new JoinedTelemetry(PanelsTelemetry.INSTANCE.getFtcTelemetry(), telemetry);
this.dataLogger = new DataLogger(logFilePrefix, !logData);
this.dataLogger.addData(DataLogger.DataType.INFO, "RobotController: Initializing...");
this.driverController = new GamepadEx(driverController);
this.actionController = new GamepadEx(actionController);
this.pathFollower = Constants.createFollower(hardwareMap);
// Reset the robot state
this.dataLogger.addData(DataLogger.DataType.INFO, "RobotController: resetting robot");
PanelsCameraStream.INSTANCE.stopStream();
CommandScheduler.getInstance().reset();
RobotPositionManager.init(hardwareMap);
}
/**
* Register all robot keybinds here.
* <p>
* Subclasses should implement this method to define all gamepad or controller bindings
* for robot actions.
* </p>
*/
public abstract void createKeyBindings();
/**
* Called once when the user presses the **Init** button.
* Use this to perform setup tasks before the robot starts running.
*/
public abstract void initialize();
/**
* Called repeatedly while the robot is in the **Init** phase,
* after {@link #initialize()} has been executed.
* Use this perform pre-start checks.
*/
public abstract void initializeLoop();
/**
* Called once when the user presses the **Play** button.
* Use this for any final setup before the main loop starts.
*/
public abstract void postInitialize();
/**
* Called repeatedly while the robot is running (after the **Play** button is pressed).
* This is the main loop for robot control logic during a match.
*/
public abstract void run();
/**
* Called once when the robot is stopped (after the **Stop** button is pressed).
* Use this to release resources or reset hardware states.
*/
public abstract void postRun();
/**
* See {@link Telemetry} for all the docs.
* @return {@link JoinedTelemetry}
*/
public JoinedTelemetry getTelemetry() {
return telemetry;
}
/**
* See {@link HardwareMap} for all the docs.
* @return {@link HardwareMap}
*/
public HardwareMap getHardwareMap() {
return hardwareMap;
}
/**
* See {@link HardwareMap} for all the docs.
* @return {@link DataLogger}
*/
public DataLogger getDataLogger() {
return dataLogger;
}
public Follower getPathFollower() {
return pathFollower;
}
protected static abstract class Builder {
protected HardwareMap hardwareMap;
protected Telemetry telemetry;
protected Gamepad driverController;
protected Gamepad actionController;
protected String logFilePrefix;
protected boolean logData;
public Builder() {
this.logData = true;
this.logFilePrefix = "RobotController";
}
public Builder initializeDefaults(SympleCommandOpMode opMode) {
this.hardwareMap = opMode.hardwareMap;
this.telemetry = opMode.telemetry;
this.driverController = opMode.gamepad1;
this.actionController = opMode.gamepad2;
return this;
}
public abstract RobotControllerBase build();
}
}