Skip to content

Commit 2c1a5d9

Browse files
SaltyJokebrettle
authored andcommitted
Issue 99 (#100)
* started fix * Continue fix until code compiles * Have color labels correspond correctly to hatch and cargo * Set light colors using cargo commands * Make requested changes * Attempt to interpret rainbow climbing lights * Make more requested changes
1 parent 63c0d4c commit 2c1a5d9

8 files changed

Lines changed: 71 additions & 53 deletions

File tree

Robot2019/src/main/java/frc/robot/OI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@ public class OI {
7575
hatchEjectBtn.whenPressed(new ToggleHatchEject(hp));
7676

7777
cargoIntakeBtn = new JoystickButton(manipulator, Manip.A); // TODO: set ports to correct values
78-
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo));
78+
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo, lights));
7979
cargoEjectBtn = new JoystickButton(manipulator, Manip.B); // TODO: set ports to correct values
8080
cargoEjectBtn.whenPressed(new EjectCargo(cargo));
8181

8282
climberRailBtn = new JoystickButton(manipulator, Manip.LB_lShoulder);
8383
climberRailBtn.whenPressed(new ToggleClimberRails(climber));
8484

8585
autoClimbBtn = new JoystickButton(manipulator, Manip.RT_rTrigger);
86-
autoClimbBtn.toggleWhenPressed(new Climb(climber, dt, leftJoy));
86+
autoClimbBtn.toggleWhenPressed(new Climb(climber, dt, leftJoy, lights));
8787

8888
manualClimbBtn = new JoystickButton(manipulator, Manip.LT_lTrigger);
89-
manualClimbBtn.toggleWhenPressed(new ManualClimb(climber, manipulator));
89+
manualClimbBtn.toggleWhenPressed(new ManualClimb(climber, manipulator, lights));
9090

9191
toggleCameraBtn = new JoystickButton(leftJoy, 2);
9292
toggleCameraBtn.whenPressed(new ToggleCamera(driveCamera, hatchCamera, cameraServer));

Robot2019/src/main/java/frc/robot/RobotMap.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import edu.wpi.first.wpilibj.DoubleSolenoid;
2323
import edu.wpi.first.wpilibj.Encoder;
2424
import edu.wpi.first.wpilibj.PowerDistributionPanel;
25+
import edu.wpi.first.wpilibj.Relay;
2526
import edu.wpi.first.wpilibj.SPI;
2627
import edu.wpi.first.wpilibj.VictorSP;
2728

@@ -41,7 +42,7 @@ public class RobotMap {
4142
static VictorSP cargoRoller;
4243
static Encoder leftEnc, rightEnc;
4344
static String driveMode;
44-
static VictorSP lights;
45+
static Relay lights;
4546
static AHRS ahrs;
4647
static PowerDistributionPanel pdp;
4748
static UsbCamera driveCamera, hatchCamera;
@@ -77,7 +78,7 @@ public class RobotMap {
7778
rightEnc = new Encoder(new DigitalInput(2), new DigitalInput(3));
7879

7980
// Initialize lights
80-
lights = new VictorSP(3); // TODO: Set this to correct port
81+
lights = new Relay(0); // TODO: Set this to correct port
8182

8283
ahrs = new AHRS(SPI.Port.kMXP);
8384
pdp = new PowerDistributionPanel();

Robot2019/src/main/java/frc/robot/commands/Climb.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
import edu.wpi.first.wpilibj.command.Command;
1111
import frc.robot.subsystems.Climber;
12+
import frc.robot.subsystems.Lights;
1213
import frc.robot.subsystems.Drivetrain;
1314
import edu.wpi.first.wpilibj.Joystick;
1415

1516
public class Climb extends Command {
1617
private Climber climber;
1718
private Drivetrain dt;
19+
private Lights lights;
1820
private Joystick dtJoy;
1921
private State state;
2022

@@ -26,20 +28,23 @@ public class Climb extends Command {
2628
private final double retractGoal = 15; // This only needs to be off the ground. Climb is 19 inches.
2729
private final double offGroundHeight = 10;
2830

29-
public Climb(Climber climber, Drivetrain dt, Joystick joy) {
31+
public Climb(Climber climber, Drivetrain dt, Joystick joy, Lights lights) {
3032
// Use requires() here to declare subsystem dependencies
3133
this.climber = climber;
3234
this.dt = dt;
35+
this.lights = lights;
3336
dtJoy = joy;
3437
requires(climber);
3538
requires(dt);
39+
requires(lights);
3640
}
3741

3842
// Called just before this Command runs the first time
3943
@Override
4044
protected void initialize() {
4145
state = State.CLIMBING;
4246
climber.resetEncoder();
47+
lights.setLights(Lights.LightState.HATCH);
4348
}
4449

4550
// Called repeatedly when this Command is scheduled to run

Robot2019/src/main/java/frc/robot/commands/EjectCargo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import edu.wpi.first.wpilibj.command.Command;
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313
import frc.robot.subsystems.Cargo;
14-
1514
public class EjectCargo extends Command {
1615

1716
final double ejectDuration = 0.5; // seconds

Robot2019/src/main/java/frc/robot/commands/IntakeCargo.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,27 @@
1111
import edu.wpi.first.wpilibj.command.Command;
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313
import frc.robot.subsystems.Cargo;
14+
import frc.robot.subsystems.Lights;
1415

1516
public class IntakeCargo extends Command {
1617
Timer timer;
1718
Cargo cargo;
19+
Lights lights;
1820
boolean overdraw;
1921

20-
public IntakeCargo(Cargo cargo) {
22+
public IntakeCargo(Cargo cargo, Lights lights) {
2123
requires(cargo);
24+
requires(lights);
2225
this.cargo = cargo;
26+
this.lights = lights;
2327
timer = new Timer();
2428
overdraw = false;
2529
}
2630

2731
@Override
2832
protected void initialize() {
2933
timer.reset();
34+
lights.setLights(Lights.LightState.CARGO);
3035
}
3136

3237
@Override

Robot2019/src/main/java/frc/robot/commands/ManualClimb.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
import edu.wpi.first.wpilibj.command.Command;
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313
import frc.robot.subsystems.Climber;
14+
import frc.robot.subsystems.Lights;
1415

1516
public class ManualClimb extends Command {
1617
private Climber climber;
18+
private Lights lights;
1719
private Joystick manip;
1820

1921
final private double retractDist = 0;
2022
final private double climbDist = 24.46; // In inches
2123

2224
final private int climbJoyAxis = 1;
2325

24-
public ManualClimb(Climber climber, Joystick manip) {
26+
public ManualClimb(Climber climber, Joystick manip, Lights lights) {
2527
// Use requires() here to declare subsystem dependencies
2628
// eg. requires(chassis);
2729
requires(climber);
30+
requires(lights);
2831

2932
this.climber = climber;
33+
this.lights = lights;
3034
this.manip = manip;
3135
}
3236

@@ -36,6 +40,7 @@ protected void initialize() {
3640
SmartDashboard.putNumber("Current Angle", 0);
3741
SmartDashboard.putNumber("Max Angle", 0);
3842
SmartDashboard.putNumber("Min Angle", 0);
43+
lights.setLights(Lights.LightState.CLIMBER);
3944
}
4045

4146
// Called repeatedly when this Command is scheduled to run

Robot2019/src/main/java/frc/robot/commands/SetLight.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,25 @@
77

88
package frc.robot.commands;
99

10-
import edu.wpi.first.wpilibj.command.Command;
10+
import edu.wpi.first.wpilibj.command.InstantCommand;
1111
import frc.robot.subsystems.Lights;
1212

13-
public class SetLight extends Command {
13+
public class SetLight extends InstantCommand {
1414
private Lights lights;
15+
private Lights.LightState state;
1516

16-
public SetLight(Lights lights) {
17+
public SetLight(Lights lights, Lights.LightState state) {
1718
// Use requires() here to declare subsystem dependencies
1819
// eg. requires(chassis);
1920
this.lights = lights;
2021
requires(lights);
22+
this.state = state;
2123
}
2224

2325
// Called just before this Command runs the first time
2426
@Override
2527
protected void initialize() {
28+
lights.setLights(state);
2629
}
2730

28-
// Called repeatedly when this Command is scheduled to run
29-
@Override
30-
protected void execute() {
31-
lights.setLights();
32-
}
33-
34-
// Make this return true when this Command no longer needs to run execute()
35-
@Override
36-
protected boolean isFinished() {
37-
return false;
38-
}
39-
40-
// Called once after isFinished returns true
41-
@Override
42-
protected void end() {
43-
}
44-
45-
// Called when another command which requires one or more of the same
46-
// subsystems is scheduled to run
47-
@Override
48-
protected void interrupted() {
49-
end();
50-
}
5131
}

Robot2019/src/main/java/frc/robot/subsystems/Lights.java

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
package frc.robot.subsystems;
99

10-
import edu.wpi.first.wpilibj.VictorSP;
10+
import edu.wpi.first.wpilibj.Relay;
11+
import edu.wpi.first.wpilibj.Relay.Value;
1112
import edu.wpi.first.wpilibj.command.Subsystem;
1213
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1314
import frc.robot.commands.SetLight;
@@ -16,44 +17,66 @@
1617
* Add your docs here.
1718
*/
1819
public class Lights extends Subsystem {
20+
21+
public enum LightState {
22+
OFF,
23+
CARGO,
24+
HATCH,
25+
CLIMBER
26+
}
1927
// Put methods for controlling this subsystem
2028
// here. Call these from Commands.
21-
private VictorSP lights;
22-
private double lightsValue = 0;
29+
private Relay lights;
30+
private LightState lightsState;
2331

2432
/**
2533
* 0 is off 0.5 is orange 1 is yellow
2634
*/
2735

28-
public Lights(VictorSP lights) {
36+
public Lights(Relay lights) {
2937
this.lights = lights;
38+
lightsState = LightState.HATCH;
3039
}
3140

32-
public void setLights() {
33-
lights.set(lightsValue);
34-
String color;
35-
if (lightsValue == 0) {
41+
public void setLights(LightState newState) {
42+
String color = "";
43+
switch (newState) {
44+
case OFF:
45+
lights.set(Relay.Value.kOff);
3646
color = "None";
37-
} else if (lightsValue == 0.5) {
38-
color = "Yellow";
39-
} else {
47+
break;
48+
case CARGO:
49+
lights.set(Relay.Value.kForward);
4050
color = "Orange";
51+
break;
52+
case HATCH:
53+
lights.set(Relay.Value.kReverse);
54+
color = "Blue";
55+
break;
56+
case CLIMBER:
57+
lights.set(Relay.Value.kOn);
58+
color = "Rainbow";
59+
break;
4160
}
61+
lightsState = newState;
4262
SmartDashboard.putString("Lights Current Color", color);
4363
}
4464

4565
public void toggleLights() {
46-
if (lightsValue == 0) {
47-
lightsValue = 0.5;
48-
} else if (lightsValue == 0.5) {
49-
lightsValue = 1;
50-
} else {
51-
lightsValue = 0;
66+
if (lightsState == LightState.OFF) {
67+
lightsState = LightState.CARGO;
68+
} else if (lightsState == LightState.CARGO) {
69+
lightsState = LightState.HATCH;
70+
} else if (lightsState == LightState.HATCH) {
71+
lightsState = LightState.CLIMBER;
72+
}
73+
else {
74+
lightsState = LightState.OFF;
5275
}
5376
}
5477

5578
@Override
5679
public void initDefaultCommand() {
57-
setDefaultCommand(new SetLight(this));
80+
setDefaultCommand(new SetLight(this, LightState.HATCH));
5881
}
5982
}

0 commit comments

Comments
 (0)