Skip to content

Commit 8e9737e

Browse files
kevinzwangbrettle
authored andcommitted
update hatch code (#97)
* add new hatch mech code * minor changes and add comments * hardcode no delay for hatch eject * change naming for clarity * re-delete files from merge * delete the imports of removed files
1 parent 3a0cb32 commit 8e9737e

5 files changed

Lines changed: 45 additions & 73 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
import frc.robot.commands.ActuateClimberRails;
1515
import frc.robot.commands.Climb;
1616
import frc.robot.commands.EjectCargo;
17-
import frc.robot.commands.EjectHatch;
17+
import frc.robot.commands.ToggleHatchEject;
1818
import frc.robot.commands.IntakeCargo;
19-
import frc.robot.commands.IntakeHatch;
19+
import frc.robot.commands.ToggleHatchIntake;
2020
import frc.robot.commands.ManualClimb;
2121
import frc.robot.commands.NormalDrive;
2222
import frc.robot.commands.ResetWobble;
@@ -70,9 +70,9 @@ public class OI {
7070
normDriveBtn.whileHeld(new NormalDrive());
7171

7272
hatchIntakeBtn = new JoystickButton(manipulator, Manip.X);
73-
hatchIntakeBtn.whenPressed(new IntakeHatch(hp));
73+
hatchIntakeBtn.whenPressed(new ToggleHatchIntake(hp));
7474
hatchEjectBtn = new JoystickButton(manipulator, Manip.Y);
75-
hatchEjectBtn.whenPressed(new EjectHatch(hp));
75+
hatchEjectBtn.whenPressed(new ToggleHatchEject(hp));
7676

7777
cargoIntakeBtn = new JoystickButton(manipulator, Manip.A); // TODO: set ports to correct values
7878
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo));

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

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*----------------------------------------------------------------------------*/
2+
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
3+
/* Open Source Software - may be modified and shared by FRC teams. The code */
4+
/* must be accompanied by the FIRST BSD license file in the root directory of */
5+
/* the project. */
6+
/*----------------------------------------------------------------------------*/
7+
8+
package frc.robot.commands;
9+
10+
import edu.wpi.first.wpilibj.command.InstantCommand;
11+
import frc.robot.subsystems.HatchPanel;
12+
13+
public class ToggleHatchEject extends InstantCommand {
14+
private HatchPanel hp;
15+
16+
/**
17+
* Toggles the eject pistons of the hatch panel mechanism, also closes the
18+
* grabbing piston when ejecting
19+
*/
20+
public ToggleHatchEject(HatchPanel hp) {
21+
requires(hp);
22+
this.hp = hp;
23+
}
24+
25+
@Override
26+
protected void initialize() {
27+
// If the pistons are currently extend them, retract them back, otherwise
28+
// release and then eject
29+
if (hp.state == HatchPanel.State.EJECTING) {
30+
hp.reset();
31+
} else {
32+
hp.reset();
33+
hp.eject();
34+
}
35+
}
36+
}

Robot2019/src/main/java/frc/robot/commands/IntakeHatch.java renamed to Robot2019/src/main/java/frc/robot/commands/ToggleHatchIntake.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import edu.wpi.first.wpilibj.command.InstantCommand;
1111
import frc.robot.subsystems.HatchPanel;
1212

13-
public class IntakeHatch extends InstantCommand {
13+
public class ToggleHatchIntake extends InstantCommand {
1414
private HatchPanel hp;
1515

1616
/**
1717
* Toggles the grabbing piston of the hatch mechanism
1818
*/
19-
public IntakeHatch(HatchPanel hp) {
19+
public ToggleHatchIntake(HatchPanel hp) {
2020
requires(hp);
2121
this.hp = hp;
2222
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ public void reset() {
3434
grabPiston.set(DoubleSolenoid.Value.kReverse);
3535
ejectPistons.set(DoubleSolenoid.Value.kReverse);
3636
state = State.DEFAULT;
37+
SmartDashboard.putString("Hatch Piston State", state.name());
3738
}
3839

3940
public void grab() {
4041
grabPiston.set(DoubleSolenoid.Value.kForward);
4142
ejectPistons.set(DoubleSolenoid.Value.kReverse);
4243
state = State.GRABBING;
44+
SmartDashboard.putString("Hatch Piston State", state.name());
4345
}
4446

4547
public void eject() {
4648
grabPiston.set(DoubleSolenoid.Value.kReverse);
4749
ejectPistons.set(DoubleSolenoid.Value.kForward);
4850
state = State.EJECTING;
51+
SmartDashboard.putString("Hatch Piston State", state.name());
4952
}
5053

5154
@Override

0 commit comments

Comments
 (0)