Skip to content

Commit 01607b1

Browse files
kevinzwangbrettle
authored andcommitted
add new hatch mech code (#86)
* add new hatch mech code * minor changes and add comments
1 parent cb053d7 commit 01607b1

File tree

8 files changed

+125
-131
lines changed

8 files changed

+125
-131
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
import frc.robot.commands.ActuateClimberRails;
1515
import frc.robot.commands.Climb;
1616
import frc.robot.commands.EjectCargo;
17-
import frc.robot.commands.IntakeOnlyCargo;
17+
import frc.robot.commands.EjectHatch;
18+
import frc.robot.commands.IntakeCargo;
19+
import frc.robot.commands.IntakeHatch;
1820
import frc.robot.commands.ManualClimb;
1921
import frc.robot.commands.NormalDrive;
2022
import frc.robot.commands.ResetWobble;
2123
import frc.robot.commands.SetArcadeOrTank;
2224
import frc.robot.commands.SlowDrive;
2325
import frc.robot.commands.ToggleCamera;
24-
import frc.robot.commands.ToggleHatch;
2526
import frc.robot.commands.ToggleLight;
2627
import frc.robot.commands.WobbleDrive;
2728
import frc.robot.subsystems.Cargo;
@@ -40,7 +41,7 @@ public class OI {
4041
JoystickButton leftSlowBtn, rightSlowBtn;
4142
JoystickButton arcadeOrTankBtn;
4243
JoystickButton normDriveBtn;
43-
JoystickButton toggleHatchBtn;
44+
JoystickButton hatchIntakeBtn, hatchEjectBtn;
4445
JoystickButton cargoIntakeBtn, cargoEjectBtn;
4546
JoystickButton climberRailBtn;
4647
JoystickButton autoClimbBtn;
@@ -68,12 +69,14 @@ public class OI {
6869
normDriveBtn = new JoystickButton(leftJoy, 3);
6970
normDriveBtn.whileHeld(new NormalDrive());
7071

71-
toggleHatchBtn = new JoystickButton(manipulator, Manip.X);
72-
toggleHatchBtn.whenPressed(new ToggleHatch(hp));
72+
hatchIntakeBtn = new JoystickButton(manipulator, Manip.X);
73+
hatchIntakeBtn.whenPressed(new IntakeHatch(hp));
74+
hatchEjectBtn = new JoystickButton(manipulator, Manip.Y);
75+
hatchEjectBtn.whenPressed(new EjectHatch(hp));
7376

74-
cargoIntakeBtn = new JoystickButton(manipulator, Manip.A);
75-
cargoIntakeBtn.whenPressed(new IntakeOnlyCargo(cargo, hp, dt));
76-
cargoEjectBtn = new JoystickButton(manipulator, Manip.B);
77+
cargoIntakeBtn = new JoystickButton(manipulator, Manip.A); // TODO: set ports to correct values
78+
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo));
79+
cargoEjectBtn = new JoystickButton(manipulator, Manip.B); // TODO: set ports to correct values
7780
cargoEjectBtn.whenPressed(new EjectCargo(cargo));
7881

7982
climberRailBtn = new JoystickButton(manipulator, Manip.LB_lShoulder);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Robot extends TimedRobot {
3333
public void robotInit() {
3434
dt = new Drivetrain(RobotMap.leftMaster, RobotMap.leftSlave1, RobotMap.leftSlave2, RobotMap.rightMaster,
3535
RobotMap.rightSlave1, RobotMap.rightSlave2, RobotMap.leftEnc, RobotMap.rightEnc, RobotMap.ahrs);
36-
hp = new HatchPanel(RobotMap.hatchPistons);
36+
hp = new HatchPanel(RobotMap.hatchGrabberPiston, RobotMap.hatchEjectPistons);
3737
cargo = new Cargo(RobotMap.cargoRoller, RobotMap.pdp, RobotMap.cargoPDPPort);
3838
climber = new Climber(RobotMap.climberMotor, RobotMap.climberEncoder, RobotMap.ahrs, RobotMap.climberPistons);
3939
lights = new Lights(RobotMap.lights);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class RobotMap {
3737
static VictorSP climberMotor;
3838
static Encoder climberEncoder;
3939
static DoubleSolenoid climberPistons;
40-
static DoubleSolenoid hatchPistons;
40+
static DoubleSolenoid hatchGrabberPiston, hatchEjectPistons;
4141
static VictorSP cargoRoller;
4242
static Encoder leftEnc, rightEnc;
4343
static String driveMode;
@@ -70,7 +70,8 @@ public class RobotMap {
7070
cargoRoller = new VictorSP(0);
7171

7272
// Initialize solenoid on hatch panel mech
73-
hatchPistons = new DoubleSolenoid(7, 0); // 7 is A/Forward, 0 is B/Reverse
73+
hatchGrabberPiston = new DoubleSolenoid(7, 0); // 7 is A/Forward, 0 is B/Reverse
74+
hatchEjectPistons = new DoubleSolenoid(6, 1);
7475

7576
leftEnc = new Encoder(new DigitalInput(0), new DigitalInput(1));
7677
rightEnc = new Encoder(new DigitalInput(2), new DigitalInput(3));
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.Timer;
11+
import edu.wpi.first.wpilibj.command.Command;
12+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
13+
import frc.robot.subsystems.HatchPanel;
14+
15+
public class EjectHatch extends Command {
16+
private HatchPanel hp;
17+
private Timer timey;
18+
private boolean ejecting;
19+
20+
/**
21+
* Toggles the eject pistons of the hatch panel mechanism
22+
*/
23+
public EjectHatch(HatchPanel hp) {
24+
requires(hp);
25+
this.hp = hp;
26+
27+
timey = new Timer();
28+
29+
if (!SmartDashboard.containsKey("Hatch Eject Delay")) {
30+
SmartDashboard.putNumber("Hatch Eject Delay", 0.5);
31+
}
32+
}
33+
34+
@Override
35+
protected void initialize() {
36+
// If the pistons are currently extend them, retract them back, otherwise release and then eject
37+
if (hp.state == HatchPanel.State.EJECTING) {
38+
hp.reset();
39+
ejecting = false;
40+
} else {
41+
hp.reset();
42+
ejecting = true;
43+
44+
timey.reset();
45+
timey.start();
46+
}
47+
}
48+
49+
@Override
50+
protected boolean isFinished() {
51+
// if it's ejecting, wait until end of delay to extend pistons after release
52+
return !ejecting || (timey.get() > SmartDashboard.getNumber("Hatch Eject Delay", 0.5));
53+
}
54+
55+
@Override
56+
protected void end() {
57+
if (ejecting) {
58+
hp.eject();
59+
}
60+
}
61+
62+
@Override
63+
protected void execute() {}
64+
65+
@Override
66+
protected void interrupted() {}
67+
}

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

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

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

16-
public ToggleHatch(HatchPanel hp) {
17-
super();
16+
/**
17+
* Toggles the grabbing piston of the hatch mechanism
18+
*/
19+
public IntakeHatch(HatchPanel hp) {
1820
requires(hp);
19-
2021
this.hp = hp;
2122
}
2223

23-
// Called once when the command executes
2424
@Override
2525
protected void initialize() {
26-
hp.toggle();
26+
switch(hp.state) {
27+
case EJECTING:
28+
case DEFAULT:
29+
hp.grab();
30+
break;
31+
case GRABBING:
32+
hp.reset();
33+
break;
34+
}
2735
}
28-
2936
}

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,48 @@
1212
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1313

1414
public class HatchPanel extends Subsystem {
15-
private DoubleSolenoid pistons;
16-
private String pistonState;
15+
private DoubleSolenoid grabPiston, ejectPistons;
16+
public State state;
1717

1818
/**
1919
* Subsystem for controlling the hatch panel mechanism
2020
*
21-
* @param pistons the solenoid that controls all three pistons on the mechanism
21+
* @param grabPiston the center piston that is used to grab the hatch panel through the hole
22+
* @param ejectPistons the two side pistons that facilitate ejecting the hatch panel
2223
*/
23-
public HatchPanel(DoubleSolenoid pistons) {
24-
this.pistons = pistons;
25-
pistonState = "IN";
26-
pistons.set(DoubleSolenoid.Value.kReverse);
27-
SmartDashboard.putString("Hatch Piston State", pistonState);
24+
public HatchPanel(DoubleSolenoid grabPiston, DoubleSolenoid ejectPistons) {
25+
this.grabPiston = grabPiston;
26+
this.ejectPistons = ejectPistons;
27+
28+
reset();
29+
30+
SmartDashboard.putString("Hatch Piston State", state.name());
2831
}
2932

30-
/**
31-
* toggles the hatch panel pistons
32-
*
33-
* @return if the pistons are extended after the call
34-
*/
35-
public boolean toggle() {
36-
if (pistons.get() == DoubleSolenoid.Value.kForward) {
37-
pistons.set(DoubleSolenoid.Value.kReverse);
38-
pistonState = "IN";
39-
SmartDashboard.putString("Hatch Piston State", pistonState);
40-
return false;
41-
} else {
42-
pistons.set(DoubleSolenoid.Value.kForward);
43-
pistonState = "OUT";
44-
SmartDashboard.putString("Hatch Piston State", pistonState);
45-
return true;
46-
}
33+
public void reset() {
34+
grabPiston.set(DoubleSolenoid.Value.kReverse);
35+
ejectPistons.set(DoubleSolenoid.Value.kReverse);
36+
state = State.DEFAULT;
4737
}
4838

49-
public void setIn() {
50-
pistons.set(DoubleSolenoid.Value.kReverse);
51-
pistonState = "IN";
52-
SmartDashboard.putString("Hatch Piston State", pistonState);
39+
public void grab() {
40+
grabPiston.set(DoubleSolenoid.Value.kForward);
41+
ejectPistons.set(DoubleSolenoid.Value.kReverse);
42+
state = State.GRABBING;
5343
}
5444

55-
public void setOut() {
56-
pistons.set(DoubleSolenoid.Value.kForward);
57-
pistonState = "OUT";
58-
SmartDashboard.putString("Hatch Piston State", pistonState);
45+
public void eject() {
46+
grabPiston.set(DoubleSolenoid.Value.kReverse);
47+
ejectPistons.set(DoubleSolenoid.Value.kForward);
48+
state = State.EJECTING;
5949
}
6050

6151
@Override
62-
public void initDefaultCommand() {
52+
public void initDefaultCommand() {}
53+
54+
public enum State {
55+
DEFAULT,
56+
GRABBING,
57+
EJECTING
6358
}
6459
}

0 commit comments

Comments
 (0)