Skip to content

Commit ba673dd

Browse files
Create branch and add basic limelight functionality
2 parents b4b4578 + 296f924 commit ba673dd

22 files changed

Lines changed: 543 additions & 126 deletions

Robot2019/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id "java"
3-
id "edu.wpi.first.GradleRIO" version "2019.3.2"
3+
id "edu.wpi.first.GradleRIO" version "2019.4.1"
44
}
55

66
def ROBOT_MAIN_CLASS = "frc.robot.Main"

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
import edu.wpi.cscore.VideoSink;
1212
import edu.wpi.first.wpilibj.Joystick;
1313
import edu.wpi.first.wpilibj.buttons.JoystickButton;
14-
import frc.robot.commands.ToggleClimberRails;
1514
import frc.robot.commands.Climb;
1615
import frc.robot.commands.EjectCargo;
17-
import frc.robot.commands.ToggleHatchEject;
16+
import frc.robot.commands.GradualDrive;
1817
import frc.robot.commands.IntakeCargo;
19-
import frc.robot.commands.ToggleHatchIntake;
18+
import frc.robot.commands.IntakeHatch;
2019
import frc.robot.commands.ManualClimb;
2120
import frc.robot.commands.NormalDrive;
21+
import frc.robot.commands.SlowClimb;
2222
import frc.robot.commands.ResetWobble;
2323
import frc.robot.commands.SetArcadeOrTank;
2424
import frc.robot.commands.SlowDrive;
2525
import frc.robot.commands.ToggleCamera;
26+
import frc.robot.commands.ToggleClimberRails;
27+
import frc.robot.commands.ToggleHatchEject;
2628
import frc.robot.commands.ToggleLight;
2729
import frc.robot.commands.WobbleDrive;
2830
import frc.robot.subsystems.Cargo;
@@ -41,11 +43,13 @@ public class OI {
4143
JoystickButton leftSlowBtn, rightSlowBtn;
4244
JoystickButton arcadeOrTankBtn;
4345
JoystickButton normDriveBtn;
46+
JoystickButton gradDriveBtn;
4447
JoystickButton hatchIntakeBtn, hatchEjectBtn;
4548
JoystickButton cargoIntakeBtn, cargoEjectBtn;
4649
JoystickButton climberRailBtn;
4750
JoystickButton autoClimbBtn;
4851
JoystickButton manualClimbBtn;
52+
JoystickButton slowClimbBtn;
4953
JoystickButton toggleCameraBtn;
5054
JoystickButton wobbleDriveBtn;
5155
JoystickButton cycleLightBtn;
@@ -67,26 +71,32 @@ public class OI {
6771
arcadeOrTankBtn = new JoystickButton(leftJoy, 4);
6872
arcadeOrTankBtn.whenPressed(new SetArcadeOrTank());
6973
normDriveBtn = new JoystickButton(leftJoy, 3);
70-
normDriveBtn.whileHeld(new NormalDrive());
74+
normDriveBtn.whenPressed(new NormalDrive());
75+
gradDriveBtn = new JoystickButton(leftJoy, 5);
76+
gradDriveBtn.whenPressed(new GradualDrive());
7177

7278
hatchIntakeBtn = new JoystickButton(manipulator, Manip.X);
73-
hatchIntakeBtn.whenPressed(new ToggleHatchIntake(hp));
79+
hatchIntakeBtn.whenPressed(new IntakeHatch(hp, dt));
7480
hatchEjectBtn = new JoystickButton(manipulator, Manip.Y);
7581
hatchEjectBtn.whenPressed(new ToggleHatchEject(hp));
7682

7783
cargoIntakeBtn = new JoystickButton(manipulator, Manip.A); // TODO: set ports to correct values
78-
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo));
84+
cargoIntakeBtn.whenPressed(new IntakeCargo(cargo, lights));
7985
cargoEjectBtn = new JoystickButton(manipulator, Manip.B); // TODO: set ports to correct values
8086
cargoEjectBtn.whenPressed(new EjectCargo(cargo));
8187

82-
climberRailBtn = new JoystickButton(manipulator, Manip.LB_lShoulder);
88+
climberRailBtn = new JoystickButton(manipulator, Manip.RB_rShoulder);
8389
climberRailBtn.whenPressed(new ToggleClimberRails(climber));
8490

85-
autoClimbBtn = new JoystickButton(manipulator, Manip.RT_rTrigger);
86-
autoClimbBtn.toggleWhenPressed(new Climb(climber, dt, leftJoy));
91+
autoClimbBtn = new JoystickButton(manipulator, Manip.LT_lTrigger);
92+
autoClimbBtn.toggleWhenPressed(new Climb(climber, dt, leftJoy, lights));
93+
94+
manualClimbBtn = new JoystickButton(manipulator, Manip.RT_rTrigger);
95+
manualClimbBtn.toggleWhenPressed(new ManualClimb(climber, manipulator, lights));
96+
8797

88-
manualClimbBtn = new JoystickButton(manipulator, Manip.LT_lTrigger);
89-
manualClimbBtn.toggleWhenPressed(new ManualClimb(climber, manipulator));
98+
slowClimbBtn = new JoystickButton(manipulator, Manip.LB_lShoulder);
99+
slowClimbBtn.whileHeld(new SlowClimb());
90100

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import frc.robot.subsystems.Drivetrain;
2020
import frc.robot.subsystems.HatchPanel;
2121
import frc.robot.subsystems.Lights;
22+
import edu.wpi.first.wpilibj.Timer;
2223

2324
public class Robot extends TimedRobot {
2425
private static Drivetrain dt;
@@ -28,6 +29,7 @@ public class Robot extends TimedRobot {
2829
private static Climber climber;
2930
private static Lights lights;
3031
private static String fname1, fname2, fname3, fname4;
32+
private static Timer timey;
3133

3234
@Override
3335
public void robotInit() {
@@ -56,6 +58,9 @@ public void robotInit() {
5658

5759
dt.setDefaultCommand(new TeleopDrive(dt, oi.leftJoy, oi.rightJoy));
5860
SmartDashboard.putNumber("Max Acceleration", dt.getMaxSpeed() / 1.0);
61+
62+
SmartDashboard.putBoolean("Outreach Mode", false);
63+
timey = new Timer();
5964
}
6065

6166
/**
@@ -83,15 +88,22 @@ public void disabledPeriodic() {
8388

8489
@Override
8590
public void autonomousInit() {
91+
timey.reset();
92+
timey.start();
93+
hp.grab();
8694
}
8795

8896
@Override
8997
public void autonomousPeriodic() {
9098
Scheduler.getInstance().run();
99+
100+
SmartDashboard.putNumber("Time left", (int) (15 - timey.get() + 1));
91101
}
92102

93103
@Override
94104
public void teleopInit() {
105+
timey.reset();
106+
timey.start();
95107
// This makes sure that the autonomous stops running when
96108
// teleop starts running. If you want the autonomous to
97109
// continue until interrupted by another command, remove
@@ -101,6 +113,8 @@ public void teleopInit() {
101113
@Override
102114
public void teleopPeriodic() {
103115
Scheduler.getInstance().run();
116+
117+
SmartDashboard.putNumber("Time left", (int) (135 - timey.get() + 1));
104118
}
105119

106120
@Override

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

Lines changed: 4 additions & 3 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();
@@ -120,7 +121,7 @@ private static WPI_TalonSRX createConfiguredTalon(int port) {
120121
catchError(tsrx.configPeakCurrentLimit(0, 0));
121122
catchError(tsrx.configPeakCurrentDuration(0, 0));
122123
// 40 Amps is the amp limit of a CIM. lThe PDP has 40 amp circuit breakers,
123-
catchError(tsrx.configContinuousCurrentLimit(40, 0));
124+
catchError(tsrx.configContinuousCurrentLimit(30, 0));
124125
tsrx.enableCurrentLimit(true);
125126
catchError(tsrx.configNeutralDeadband(0.001, 10));
126127
tsrx.setNeutralMode(NeutralMode.Brake);

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
package frc.robot.commands;
99

1010
import edu.wpi.first.wpilibj.command.Command;
11+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1112
import frc.robot.subsystems.Climber;
13+
import frc.robot.subsystems.Lights;
1214
import frc.robot.subsystems.Drivetrain;
1315
import edu.wpi.first.wpilibj.Joystick;
1416

1517
public class Climb extends Command {
1618
private Climber climber;
1719
private Drivetrain dt;
20+
private Lights lights;
1821
private Joystick dtJoy;
1922
private State state;
2023

@@ -26,52 +29,57 @@ public class Climb extends Command {
2629
private final double retractGoal = 15; // This only needs to be off the ground. Climb is 19 inches.
2730
private final double offGroundHeight = 10;
2831

29-
public Climb(Climber climber, Drivetrain dt, Joystick joy) {
32+
public Climb(Climber climber, Drivetrain dt, Joystick joy, Lights lights) {
3033
// Use requires() here to declare subsystem dependencies
3134
this.climber = climber;
3235
this.dt = dt;
36+
this.lights = lights;
3337
dtJoy = joy;
3438
requires(climber);
3539
requires(dt);
40+
requires(lights);
3641
}
3742

3843
// Called just before this Command runs the first time
3944
@Override
4045
protected void initialize() {
4146
state = State.CLIMBING;
4247
climber.resetEncoder();
48+
lights.setLights(Lights.LightState.HATCH);
4349
}
4450

4551
// Called repeatedly when this Command is scheduled to run
4652
@Override
4753
protected void execute() {
48-
switch (state) {
49-
case CLIMBING:
50-
dt.drive(backDrive, backDrive);
51-
climber.runClimber(climbUp);
52-
if (!climber.needToClimb()) {
53-
state = State.LEVELING;
54+
if (!SmartDashboard.getBoolean("Outreach Mode", false)) {
55+
switch (state) {
56+
case CLIMBING:
57+
dt.drive(backDrive, backDrive);
58+
climber.runClimber(climbUp);
59+
if (!climber.needToClimb()) {
60+
state = State.LEVELING;
61+
}
62+
if (robotOnPlatform())
63+
state = State.RETRACTING;
64+
break;
65+
case LEVELING:
66+
dt.drive(backDrive, backDrive);
67+
climber.runClimber(climbDown);
68+
if (!climber.canDrop()) {
69+
state = State.CLIMBING;
70+
}
71+
if (robotOnPlatform())
72+
state = State.RETRACTING;
73+
break;
74+
case RETRACTING:
75+
climber.runClimber(retract);
76+
if (climber.getEncDistance() <= retractGoal) {
77+
state = State.FINISHED;
78+
}
79+
break;
80+
case FINISHED:
81+
end();
5482
}
55-
if (robotOnPlatform())
56-
state = State.RETRACTING;
57-
break;
58-
case LEVELING:
59-
dt.drive(backDrive, backDrive);
60-
climber.runClimber(climbDown);
61-
if (!climber.canDrop()) {
62-
state = State.CLIMBING;
63-
}
64-
if (robotOnPlatform())
65-
state = State.RETRACTING;
66-
break;
67-
case RETRACTING:
68-
climber.runClimber(retract);
69-
if (climber.getEncDistance() <= retractGoal) {
70-
state = State.FINISHED;
71-
}
72-
break;
73-
case FINISHED:
74-
end();
7583
}
7684
}
7785

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
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
12+
13+
/**
14+
* Add your docs here.
15+
*/
16+
public class GradualDrive extends InstantCommand {
17+
/**
18+
* Add your docs here.
19+
*/
20+
public GradualDrive() {
21+
super();
22+
// Use requires() here to declare subsystem dependencies
23+
// eg. requires(chassis);
24+
}
25+
26+
// Called once when the command executes
27+
@Override
28+
protected void initialize() {
29+
SmartDashboard.putBoolean("Gradual Drive", !SmartDashboard.getBoolean("Gradual Drive", true));
30+
}
31+
32+
}

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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.CommandGroup;
11+
import frc.robot.subsystems.Drivetrain;
12+
import frc.robot.subsystems.HatchPanel;
13+
14+
public class IntakeHatch extends CommandGroup {
15+
/**
16+
* Add your docs here.
17+
*/
18+
public IntakeHatch(HatchPanel hp, Drivetrain dt) {
19+
// Add Commands here:
20+
// e.g. addSequential(new Command1());
21+
// addSequential(new Command2());
22+
// these will run in order.
23+
24+
// To run multiple commands at the same time,
25+
// use addParallel()
26+
// e.g. addParallel(new Command1());
27+
// addSequential(new Command2());
28+
// Command1 and Command2 will run in parallel.
29+
30+
// A command group will require all of the subsystems that each member
31+
// would require.
32+
// e.g. if Command1 requires chassis, and Command2 requires arm,
33+
// a CommandGroup containing them would require both the chassis and the
34+
// arm.
35+
addSequential(new ToggleHatchIntake(hp));
36+
addSequential(new WaitTime(dt, 0.25));
37+
addSequential(new MoveBack(dt, 0.25));
38+
}
39+
}

0 commit comments

Comments
 (0)