Skip to content

Commit 24047d6

Browse files
committed
Air Compresor Pause added and IR sensor code
1 parent a969116 commit 24047d6

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

src/main/java/org/mayheminc/robot2020/commands/AirCompressorDefault.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import edu.wpi.first.wpilibj2.command.CommandBase;
1313

1414
public class AirCompressorDefault extends CommandBase {
15+
boolean value;
16+
1517
/**
1618
* Creates a new AirCompressorDefault.
1719
*/
@@ -20,11 +22,18 @@ public AirCompressorDefault() {
2022
addRequirements(RobotContainer.compressor);
2123
}
2224

25+
public AirCompressorDefault(boolean b) {
26+
// Use addRequirements() here to declare subsystem dependencies.
27+
addRequirements(RobotContainer.compressor);
28+
value = b;
29+
30+
}
31+
2332
// Called when the command is initially scheduled.
2433
@Override
2534
public void initialize() {
2635
// robot.is
27-
RobotContainer.compressor.setCompressor(true);
36+
RobotContainer.compressor.setCompressor(value);
2837
}
2938

3039
// Called every time the scheduler runs while the command is scheduled.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*----------------------------------------------------------------------------*/
2+
/* Copyright (c) 2019 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 org.mayheminc.robot2020.commands;
9+
10+
import org.mayheminc.robot2020.RobotContainer;
11+
12+
import edu.wpi.first.wpilibj2.command.InstantCommand;
13+
14+
public class AirCompressorPause extends InstantCommand {
15+
/**
16+
* Creates a new AirCompressorSet.
17+
*/
18+
public AirCompressorPause() {
19+
// Use addRequirements() here to declare subsystem dependencies.
20+
addRequirements(RobotContainer.compressor);
21+
}
22+
23+
// Called when the command is initially scheduled.
24+
@Override
25+
public void initialize() {
26+
RobotContainer.compressor.setCompressor(false);
27+
}
28+
29+
}

src/main/java/org/mayheminc/robot2020/subsystems/AirCompressor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
package org.mayheminc.robot2020.subsystems;
99

1010
import edu.wpi.first.wpilibj.Compressor;
11+
import edu.wpi.first.wpilibj.Timer;
1112
import edu.wpi.first.wpilibj2.command.SubsystemBase;
1213

1314
public class AirCompressor extends SubsystemBase {
1415
Compressor compressor = new Compressor();
16+
Timer m_Timer = new Timer();
1517

1618
/**
1719
* Creates a new compressor.
@@ -21,17 +23,25 @@ public AirCompressor() {
2123
setCompressor(true);
2224
}
2325

26+
final double COPRESSOR_PAUSE_TIME = 10.0;
27+
2428
public void setCompressor(boolean b) {
2529
// b = false;
2630
if (b) {
2731
compressor.start();
2832
} else {
2933
compressor.stop();
34+
m_Timer.start();
3035
}
3136
}
3237

3338
@Override
3439
public void periodic() {
3540
// This method will be called once per scheduler run
41+
42+
// if the timer expires, turn on the compressor.
43+
if (m_Timer.hasPeriodPassed(COPRESSOR_PAUSE_TIME)) {
44+
setCompressor(true);
45+
}
3646
}
3747
}

src/main/java/org/mayheminc/robot2020/subsystems/Chimney.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212

1313
import org.mayheminc.robot2020.Constants;
1414
import org.mayheminc.util.MayhemTalonSRX;
15+
import org.mayheminc.util.RangeFinder_GP2D120;
1516

1617
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1718
import edu.wpi.first.wpilibj2.command.SubsystemBase;
1819

1920
public class Chimney extends SubsystemBase {
2021
private final MayhemTalonSRX chimneyTalon = new MayhemTalonSRX(Constants.Talon.MAGAZINE_CHIMNEY);
22+
private final RangeFinder_GP2D120 frontIR = new RangeFinder_GP2D120(2, 0);
23+
private final RangeFinder_GP2D120 middleIR = new RangeFinder_GP2D120(3, 0);
2124

2225
/**
2326
* Creates a new Chimney.
@@ -34,11 +37,15 @@ public void periodic() {
3437
// This method will be called once per scheduler run
3538
updateSmartDashboard();
3639
monitorTurntableMovement();
40+
frontIR.periodic();
41+
middleIR.periodic();
3742
}
3843

3944
void updateSmartDashboard() {
4045
SmartDashboard.putNumber("Chimney Speed", chimneyTalon.getSpeed());
4146
SmartDashboard.putNumber("Chimney Current", chimneyTalon.getStatorCurrent());
47+
SmartDashboard.putBoolean("Chimney FrontIR", frontIR.isObjectClose());
48+
SmartDashboard.putBoolean("Chimney MidddleIR", middleIR.isObjectClose());
4249
}
4350

4451
void monitorTurntableMovement() {
@@ -47,4 +54,12 @@ void monitorTurntableMovement() {
4754
public void setChimneySpeed(double speed) {
4855
chimneyTalon.set(ControlMode.PercentOutput, speed);
4956
}
57+
58+
public boolean isBallInFrontOfChimney() {
59+
return frontIR.isObjectClose();
60+
}
61+
62+
public boolean isBallInMiddleOfChimney() {
63+
return middleIR.isObjectClose();
64+
}
5065
}

0 commit comments

Comments
 (0)