-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeleOpRobotController.java
More file actions
147 lines (116 loc) · 5.79 KB
/
Copy pathTeleOpRobotController.java
File metadata and controls
147 lines (116 loc) · 5.79 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
138
139
140
141
142
143
144
145
146
147
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.seattlesolvers.solverslib.command.button.Trigger;
import com.seattlesolvers.solverslib.gamepad.GamepadKeys;
import org.firstinspires.ftc.robotcore.external.Telemetry;
import org.firstinspires.ftc.teamcode.subsystems.driveTrain.MecanumDriveSubsystem;
import org.firstinspires.ftc.teamcode.subsystems.driveTrain.commands.mecanumDrive.MecanumArcadeDriveCommand;
import org.firstinspires.ftc.teamcode.subsystems.gate.GateSubsystem;
import org.firstinspires.ftc.teamcode.subsystems.intake.IntakeSubsystem;
import org.firstinspires.ftc.teamcode.subsystems.storage.StorageSubsystem;
import org.firstinspires.ftc.teamcode.subsystems.shooter.ShooterSubsystem;
import org.firstinspires.ftc.teamcode.util.TeamColor;
import org.firstinspires.ftc.teamcode.util.controlcommands.ActuatorCommands;
import org.firstinspires.ftc.teamcode.util.controlcommands.DriverCommands;
import org.firstinspires.ftc.teamcode.util.opModes.SympleCommandOpMode;
public class TeleOpRobotController extends RobotControllerBase {
private final MecanumDriveSubsystem mecanumDriveSubsystem;
private final IntakeSubsystem intakeSubsystem;
private final GateSubsystem gateSubsystem;
private final StorageSubsystem storageSubsystem;
private final ShooterSubsystem shooterSubsystem;
private final DriverCommands driverCommands;
private final ActuatorCommands actuatorCommands;
private TeleOpRobotController(HardwareMap hMap, Telemetry telemetry, Gamepad driverController, Gamepad actionController, TeamColor teamColor, String logFilePrefix, boolean logData) {
super(hMap, telemetry, driverController, actionController, logFilePrefix, logData);
if (teamColor == null) {
RuntimeException exception = new RuntimeException("Team color cannot be null!");
this.getDataLogger().addThrowable(exception);
throw exception;
}
this.mecanumDriveSubsystem = new MecanumDriveSubsystem(this.getHardwareMap(), this.getTelemetry(), this.getDataLogger());
this.intakeSubsystem = new IntakeSubsystem(this.getHardwareMap(), this.getTelemetry(), this.getDataLogger());
this.storageSubsystem = new StorageSubsystem(this.getHardwareMap(), this.getTelemetry(), this.getDataLogger());
this.gateSubsystem = new GateSubsystem(this.getHardwareMap(), this.getTelemetry(), this.getDataLogger());
this.shooterSubsystem = new ShooterSubsystem(this.getHardwareMap(), this.getTelemetry(), this.getDataLogger());
this.driverCommands = new DriverCommands(
this.mecanumDriveSubsystem,
this.intakeSubsystem,
this.gateSubsystem,
this.storageSubsystem,
this.shooterSubsystem
);
this.actuatorCommands = new ActuatorCommands(
this.mecanumDriveSubsystem,
this.intakeSubsystem,
this.gateSubsystem,
this.storageSubsystem,
this.shooterSubsystem
);
}
@Override
public void createKeyBindings() {
this.driverController.getGamepadButton(GamepadKeys.Button.RIGHT_BUMPER)
.whenPressed(this.driverCommands::setNormalSpeedMode);
this.driverController.getGamepadButton(GamepadKeys.Button.LEFT_BUMPER)
.whenPressed(this.driverCommands::setSlowSpeedMode);
this.driverController.getGamepadButton(GamepadKeys.Button.DPAD_UP)
.whenPressed(this.driverCommands::resetRobotAngle);
this.actionController.getGamepadButton(GamepadKeys.Button.X)
.toggleWhenPressed(
this.actuatorCommands.startIntake(),
this.actuatorCommands.stopIntake()
);
this.actionController.getGamepadButton(GamepadKeys.Button.Y)
.toggleWhenPressed(
this.actuatorCommands.storageGoToShooter(),
this.actuatorCommands.storageGoToIntake()
);
this.actionController.getGamepadButton(GamepadKeys.Button.B)
.toggleWhenPressed(
this.actuatorCommands.pushTheBall(),
this.actuatorCommands.returnToZero()
);
new Trigger(this.shooterSubsystem::isFastEnough)
.whenActive(() -> this.actionController.gamepad.rumble(500));
new Trigger(() -> this.actionController.getTrigger(GamepadKeys.Trigger.RIGHT_TRIGGER) > 0.5f)
.whileActiveContinuous(this.actuatorCommands.shootBallNow())
.whenInactive(this.actuatorCommands.returnToZero());
}
@Override
public void initialize() {
this.mecanumDriveSubsystem.setDefaultCommand(new MecanumArcadeDriveCommand(this.mecanumDriveSubsystem, this.driverController));
}
@Override
public void initializeLoop() {
}
@Override
public void postInitialize() {
}
@Override
public void run() {
}
@Override
public void postRun() {
}
public static class Builder extends RobotControllerBase.Builder {
private TeamColor teamColor;
public Builder() {
this.logFilePrefix = "TeleOp";
}
public Builder teamColor(TeamColor value) {
this.teamColor = value;
return this;
}
@Override
public Builder initializeDefaults(SympleCommandOpMode opMode) {
super.initializeDefaults(opMode);
return this;
}
@Override
public TeleOpRobotController build() {
return new TeleOpRobotController(this.hardwareMap, this.telemetry, this.driverController, this.actionController, this.teamColor, this.logFilePrefix, this.logData);
}
}
}