import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;
-import edu.wpi.first.wpilibj.I2C;
-import edu.wpi.first.wpilibj.I2C.Port;
/**
* The Constants stores constant values for all subsystems. This includes the
*/
public class Constants {
+ public final static int PCM_MODULE_A = 9;
+ public final static int PCM_MODULE_B = 10;
+
public static class OI {
// Computer Ports
public final static int LEFT_STICK_PORT = 0;
public final static int ENCODER_RIGHT_A = 9;
public final static int ENCODER_RIGHT_B = 8;
- public static final double INCHES_PER_PULSE = ((3.66 / 5.14) * 6 * Math.PI)
- / 256;
+ public static final double INCHES_PER_PULSE = ((3.66 / 5.14) * 6 * Math.PI) / 256;
public static double kp = 0.013, ki = 0.000015, kd = -0.002;
public static double gp = 0.018, gi = 0.000015, gd = 0;
}
public static class Shooter {
- public static final int PORT = 0;
- public static final int PUNCH_FORWARD = 5;
- public static final int PUNCH_REVERSE = 1;
- public static final int ANGLE_ADJUSTER_PORT = 0;
-
- public static final DoubleSolenoid.Value punch = DoubleSolenoid.Value.kForward;
- public static final DoubleSolenoid.Value retract = DoubleSolenoid.Value.kReverse;
-
- // Encoder port
- public static final int ENCODER_PORT_A = 0;
- public static final int ENCODER_PORT_B = 0;
- public static final int RIGHT_HOOD_FORWARD = 2;
- public static final int RIGHT_HOOD_REVERSE = 4;
- public static final int LEFT_HOOD_FORWARD = 4;
- public static final int LEFT_HOOD_REVERSE = 2;
-
- public static final double DEFAULT_SHOOTER_SPEED = 0.5;
-
- public static final Value open = Value.kReverse;
- public static final Value closed = Value.kForward;
-
- public static final Port LIDAR_I2C_PORT = I2C.Port.kMXP;
-
- public static enum State {
- RUNNING, STOPPED;
- }
+ public static final int CATAPULT1_MODULE = PCM_MODULE_A;
+ public static final int CATAPULT1_FORWARD = 0;
+ public static final int CATAPULT1_REVERSE = 1;
+ public static final int CATAPULT2_MODULE = PCM_MODULE_B;
+ public static final int CATAPULT2_FORWARD = 2;
+ public static final int CATAPULT2_REVERSE = 3;// TODO Determine actual
+ // shooter ports
+
+ public static final Value shoot = Value.kForward;
+ public static final Value reset = Value.kReverse;
+ public static final double WAIT_TIME = 2.0; // In seconds
}
public static class IntakeArm {
import org.usfirst.frc.team3501.robot.commands.scaler.StopWinch;
import org.usfirst.frc.team3501.robot.commands.scaler.ToggleScaling;
import org.usfirst.frc.team3501.robot.commands.shooter.Shoot;
-import org.usfirst.frc.team3501.robot.commands.shooter.runShooter;
import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
import edu.wpi.first.wpilibj.DigitalInput;
leftJoystick = new Joystick(Constants.OI.LEFT_STICK_PORT);
rightJoystick = new Joystick(Constants.OI.RIGHT_STICK_PORT);
- passPortcullis = new DigitalButton(
- new DigitalInput(Constants.OI.PASS_PORTCULLIS_PORT));
+ passPortcullis = new DigitalButton(new DigitalInput(
+ Constants.OI.PASS_PORTCULLIS_PORT));
passPortcullis.whenPressed(new PassPortcullis());
- passChevalDeFrise = new DigitalButton(
- new DigitalInput(Constants.OI.PASS_CHEVAL_DE_FRISE_PORT));
+ passChevalDeFrise = new DigitalButton(new DigitalInput(
+ Constants.OI.PASS_CHEVAL_DE_FRISE_PORT));
passChevalDeFrise.whenPressed(new PassChevalDeFrise());
- passDrawbridge = new DigitalButton(
- new DigitalInput(Constants.OI.PASS_DRAWBRIDGE_PORT));
+ passDrawbridge = new DigitalButton(new DigitalInput(
+ Constants.OI.PASS_DRAWBRIDGE_PORT));
passDrawbridge.whenPressed(new PassDrawBridge());
- passSallyPort = new DigitalButton(
- new DigitalInput(Constants.OI.PASS_SALLYPORT_PORT));
+ passSallyPort = new DigitalButton(new DigitalInput(
+ Constants.OI.PASS_SALLYPORT_PORT));
passSallyPort.whenPressed(new PassSallyPort());
- lowerChevalDeFrise = new DigitalButton(
- new DigitalInput(Constants.OI.ARCADE_INTAKEARM_LEVEL_ONE_PORT));
+ lowerChevalDeFrise = new DigitalButton(new DigitalInput(
+ Constants.OI.ARCADE_INTAKEARM_LEVEL_ONE_PORT));
lowerChevalDeFrise.whenPressed(new MoveIntakeArmToAngle(
IntakeArm.potAngles[0], IntakeArm.moveIntakeArmSpeed));
- moveToIntakeBoulder = new DigitalButton(
- new DigitalInput(Constants.OI.ARCADE_INTAKEARM_LEVEL_TWO_PORT));
+ moveToIntakeBoulder = new DigitalButton(new DigitalInput(
+ Constants.OI.ARCADE_INTAKEARM_LEVEL_TWO_PORT));
moveToIntakeBoulder.whenPressed(new MoveIntakeArmToAngle(
IntakeArm.potAngles[1], IntakeArm.moveIntakeArmSpeed));
- poiseAboveChevalDeFrise = new DigitalButton(
- new DigitalInput(Constants.OI.ARCADE_INTAKEARM_LEVEL_THREE_PORT));
+ poiseAboveChevalDeFrise = new DigitalButton(new DigitalInput(
+ Constants.OI.ARCADE_INTAKEARM_LEVEL_THREE_PORT));
poiseAboveChevalDeFrise.whenPressed(new MoveIntakeArmToAngle(
IntakeArm.potAngles[2], IntakeArm.moveIntakeArmSpeed));
- moveIntakeArmInsideRobot = new DigitalButton(
- new DigitalInput(Constants.OI.ARCADE_INTAKEARM_LEVEL_FOUR_PORT));
+ moveIntakeArmInsideRobot = new DigitalButton(new DigitalInput(
+ Constants.OI.ARCADE_INTAKEARM_LEVEL_FOUR_PORT));
moveIntakeArmInsideRobot.whenPressed(new MoveIntakeArmToAngle(
IntakeArm.potAngles[3], IntakeArm.moveIntakeArmSpeed));
toggleShooter = new JoystickButton(leftJoystick,
Constants.OI.LEFT_JOYSTICK_TRIGGER_PORT);
- SpinRobot180_1 = new JoystickButton(leftJoystick,
- Constants.OI.SPIN1_PORT);
+ SpinRobot180_1 = new JoystickButton(leftJoystick, Constants.OI.SPIN1_PORT);
SpinRobot180_1.whenPressed(new Turn180());
- SpinRobot180_2 = new JoystickButton(leftJoystick,
- Constants.OI.SPIN2_PORT);
+ SpinRobot180_2 = new JoystickButton(leftJoystick, Constants.OI.SPIN2_PORT);
SpinRobot180_2.whenPressed(new Turn180());
compactRobot_1 = new JoystickButton(leftJoystick,
shootBoulder = new JoystickButton(rightJoystick,
Constants.OI.RIGHT_JOYSTICK_THUMB_PORT);
- toggleScaling = new DigitalButton(
- new DigitalInput(Constants.OI.TOGGLE_SCALING_PORT));
+ toggleScaling = new DigitalButton(new DigitalInput(
+ Constants.OI.TOGGLE_SCALING_PORT));
toggleScaling.whenPressed(new ToggleScaling());
if (!Constants.Scaler.SCALING) {
- toggleShooter.toggleWhenPressed(new runShooter());
compactRobot_1.whenPressed(new CompactRobot());
compactRobot_2.whenPressed(new CompactRobot());
package org.usfirst.frc.team3501.robot;
import org.usfirst.frc.team3501.robot.Constants.Defense;
+import org.usfirst.frc.team3501.robot.commands.shooter.ResetCatapult;
import org.usfirst.frc.team3501.robot.subsystems.DefenseArm;
import org.usfirst.frc.team3501.robot.subsystems.DriveTrain;
import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
SmartDashboard.putData("Position Two Defense Chooser", positionTwoDefense);
SmartDashboard.putData("Position Three Defense Chooser",
positionThreeDefense);
- SmartDashboard.putData("Position Four Defense Chooser",
- positionFourDefense);
- SmartDashboard.putData("Position Five Defense Chooser",
- positionFiveDefense);
+ SmartDashboard
+ .putData("Position Four Defense Chooser", positionFourDefense);
+ SmartDashboard
+ .putData("Position Five Defense Chooser", positionFiveDefense);
- SmartDashboard.putData("Position Four Defense Chooser",
- positionFourDefense);
- SmartDashboard.putData("Position Five Defense Chooser",
- positionFiveDefense);
+ SmartDashboard
+ .putData("Position Four Defense Chooser", positionFourDefense);
+ SmartDashboard
+ .putData("Position Five Defense Chooser", positionFiveDefense);
shooter = new Shooter();
@Override
public void teleopInit() {
+ Scheduler.getInstance().add(new ResetCatapult()); // Reset catapult at start
+ // of each match.
}
@Override
package org.usfirst.frc.team3501.robot.commands.auton;
-import org.usfirst.frc.team3501.robot.Robot;
import org.usfirst.frc.team3501.robot.commands.intakearm.MoveIntakeArmToAngle;
import org.usfirst.frc.team3501.robot.subsystems.IntakeArm;
public CompactRobot() {
addSequential(new MoveIntakeArmToAngle(IntakeArm.potAngles[3],
IntakeArm.moveIntakeArmSpeed));
- Robot.shooter.lowerHood();
}
}
+++ /dev/null
-package org.usfirst.frc.team3501.robot.commands.shooter;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class ChangeShooterSpeed extends Command {
- double change = 0;
-
- public ChangeShooterSpeed(double change) {
- this.change = change;
- }
-
- @Override
- protected void initialize() {
- Robot.shooter.changeSpeed(change);
- }
-
- @Override
- protected void execute() {
-
- }
-
- @Override
- protected boolean isFinished() {
- return true;
- }
-
- @Override
- protected void end() {
-
- }
-
- @Override
- protected void interrupted() {
- }
-
-}
+++ /dev/null
-package org.usfirst.frc.team3501.robot.commands.shooter;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class ExtendPunch extends Command {
-
- @Override
- protected void initialize() {
- Robot.shooter.extendPunch();
- }
-
- @Override
- protected void execute() {
-
- }
-
- @Override
- protected boolean isFinished() {
- return true;
- }
-
- @Override
- protected void end() {
-
- }
-
- @Override
- protected void interrupted() {
-
- }
-
-}
--- /dev/null
+package org.usfirst.frc.team3501.robot.commands.shooter;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+public class FireCatapult extends Command {
+
+ public FireCatapult() {
+ requires(Robot.shooter);
+ }
+
+ @Override
+ protected void initialize() {
+ Robot.shooter.fireCatapult();
+ }
+
+ @Override
+ protected void execute() {
+
+ }
+
+ @Override
+ protected boolean isFinished() {
+ return true;
+ }
+
+ @Override
+ protected void end() {
+
+ }
+
+ @Override
+ protected void interrupted() {
+
+ }
+
+}
--- /dev/null
+package org.usfirst.frc.team3501.robot.commands.shooter;
+
+import org.usfirst.frc.team3501.robot.Robot;
+
+import edu.wpi.first.wpilibj.command.Command;
+
+public class ResetCatapult extends Command {
+
+ public ResetCatapult() {
+ requires(Robot.shooter);
+ }
+
+ @Override
+ protected void initialize() {
+ Robot.shooter.resetCatapult();
+ }
+
+ @Override
+ protected void execute() {
+
+ }
+
+ @Override
+ protected boolean isFinished() {
+ return true;
+ }
+
+ @Override
+ protected void end() {
+
+ }
+
+ @Override
+ protected void interrupted() {
+
+ }
+
+}
+++ /dev/null
-package org.usfirst.frc.team3501.robot.commands.shooter;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class RetractPunch extends Command {
-
- @Override
- protected void initialize() {
- Robot.shooter.retractPunch();
- }
-
- @Override
- protected void execute() {
-
- }
-
- @Override
- protected boolean isFinished() {
- return true;
- }
-
- @Override
- protected void end() {
-
- }
-
- @Override
- protected void interrupted() {
-
- }
-
-}
+++ /dev/null
-package org.usfirst.frc.team3501.robot.commands.shooter;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-public class SetShooterSpeed extends Command {
- double speed = 0.0;
-
- public SetShooterSpeed(double speed) {
- this.speed = speed;
- }
-
- @Override
- protected void initialize() {
- Robot.shooter.setSpeed(speed);
- }
-
- @Override
- protected void execute() {
-
- }
-
- @Override
- protected boolean isFinished() {
- return true;
- }
-
- @Override
- protected void end() {
-
- }
-
- @Override
- protected void interrupted() {
-
- }
-
-}
package org.usfirst.frc.team3501.robot.commands.shooter;
+import org.usfirst.frc.team3501.robot.Constants;
import org.usfirst.frc.team3501.robot.Robot;
import edu.wpi.first.wpilibj.command.CommandGroup;
public boolean usePhotogate;
+ /**
+ * Fires catapult, then resets after a pause. If robot is set to use photogate
+ * and no ball is detected, nothing happens.
+ *
+ * Precondition: catapult is in reset position, and ball is loaded in
+ * catapult.
+ */
public Shoot() {
- addSequential(new WaitCommand(3.0));
- addSequential(new runShooter());
- addSequential(new WaitCommand(3.0));
if (Robot.shooter.usePhotogate()) {
if (Robot.shooter.isBallInside()) {
- addSequential(new ExtendPunch());
- addSequential(new WaitCommand(5.0));
- addSequential(new RetractPunch());
+ addSequential(new FireCatapult());
+ addSequential(new WaitCommand(Constants.Shooter.WAIT_TIME));
+ addSequential(new ResetCatapult());
}
} else {
- addSequential(new ExtendPunch());
- addSequential(new WaitCommand(5.0));
- addSequential(new RetractPunch());
+ addSequential(new FireCatapult());
+ addSequential(new WaitCommand(Constants.Shooter.WAIT_TIME));
+ addSequential(new ResetCatapult());
}
-
}
}
+++ /dev/null
-package org.usfirst.frc.team3501.robot.commands.shooter;
-
-import org.usfirst.frc.team3501.robot.Robot;
-
-import edu.wpi.first.wpilibj.command.Command;
-
-/**
- *
- */
-public class runShooter extends Command {
-
- public runShooter() {
-
- }
-
- // default shooter speed is used to shoot when in front of the batter
- @Override
- protected void initialize() {
- Robot.shooter.setSpeed(0.5);
- }
-
- @Override
- protected void execute() {
- }
-
- @Override
- protected boolean isFinished() {
- return true;
- }
-
- @Override
- protected void end() {
- Robot.shooter.stop();
- }
-
- @Override
- protected void interrupted() {
- }
-}
package org.usfirst.frc.team3501.robot.subsystems;
import org.usfirst.frc.team3501.robot.Constants;
-import org.usfirst.frc.team3501.robot.sensors.Lidar;
import org.usfirst.frc.team3501.robot.sensors.Photogate;
-import edu.wpi.first.wpilibj.CANTalon;
-import edu.wpi.first.wpilibj.CounterBase.EncodingType;
import edu.wpi.first.wpilibj.DoubleSolenoid;
-import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.command.Subsystem;
/***
* motors. The piston controlling the platform pushes the ball onto the wheel.
* The wheel is controlled by a motor, which is running before the ball is
* pushed onto the wheel. The spinning wheel propels the ball.
- *
+ *
* @author superuser
- *
+ *
*/
public class Shooter extends Subsystem {
- private CANTalon shooter;
- private DoubleSolenoid hood1, hood2, punch;
- private Encoder encoder;
- private Lidar lidar;
+ private DoubleSolenoid catapult1, catapult2;
private Photogate photogate;
private boolean usePhotoGate;
public Shooter() {
- shooter = new CANTalon(Constants.Shooter.PORT);
- hood1 = new DoubleSolenoid(10, Constants.Shooter.RIGHT_HOOD_FORWARD,
- Constants.Shooter.RIGHT_HOOD_REVERSE); // right
- hood2 = new DoubleSolenoid(9, Constants.Shooter.LEFT_HOOD_FORWARD,
- Constants.Shooter.LEFT_HOOD_REVERSE);// left
- punch = new DoubleSolenoid(9, Constants.Shooter.PUNCH_FORWARD,
- Constants.Shooter.PUNCH_REVERSE);
-
- encoder = new Encoder(Constants.Shooter.ENCODER_PORT_A,
- Constants.Shooter.ENCODER_PORT_B, false, EncodingType.k4X);
- usePhotoGate = true;
+ catapult1 = new DoubleSolenoid(Constants.Shooter.CATAPULT1_MODULE,
+ Constants.Shooter.CATAPULT1_FORWARD,
+ Constants.Shooter.CATAPULT1_REVERSE);
+ catapult2 = new DoubleSolenoid(Constants.Shooter.CATAPULT2_MODULE,
+ Constants.Shooter.CATAPULT2_FORWARD,
+ Constants.Shooter.CATAPULT2_REVERSE);
+ usePhotoGate = false;
}
/***
* This method checks to see if the ball has successfully passed through the
* intake rollers and is inside.
- *
+ *
* @return whether the presence of the ball is true or false and returns the
* state of the condition (true or false).
*/
public boolean isBallInside() {
-
if (usePhotogate())
return photogate.isBallPresent();
else
return true;
-
- }
-
- public void setSpeed(double speed) {
- if (speed > 1.0)
- shooter.set(1.0);
- else if (speed < -1.0)
- shooter.set(-1.0);
- else
- shooter.set(speed);
}
- public void stop() {
- this.setSpeed(0.0);
+ // Catapult Commands
+ public void fireCatapult() {
+ catapult1.set(Constants.Shooter.shoot);
+ catapult2.set(Constants.Shooter.shoot);
}
- public double getSpeed() {
- return encoder.getRate();
- }
-
- /*
- * We are going to map a lidar distance to a shooter speed that will be set to
- * the shooter. This function does not yet exist so we will just use y=x but
- * when testing commences we shall create the function
- */
- public double getShooterSpeed() {
- double distanceToGoal = lidar.getDistance();
- double shooterSpeed = distanceToGoal; // Function to be determined
- return shooterSpeed;
- }
-
- // Use negative # for decrement. Positive for increment.
-
- public void changeSpeed(double change) {
- double newSpeed = getSpeed() + change;
- setSpeed(newSpeed);
- }
-
- // Punch Commands
- public void extendPunch() {
- punch.set(Constants.Shooter.punch);
- }
-
- public void retractPunch() {
- punch.set(Constants.Shooter.retract);
- }
-
- public void raiseHood() {
- hood1.set(Constants.Shooter.open);
- hood2.set(Constants.Shooter.open);
- }
-
- public void lowerHood() {
- hood1.set(Constants.Shooter.closed);
- hood2.set(Constants.Shooter.closed);
- }
-
- public boolean isHoodDown() {
- if (hood1.get() == Constants.Shooter.open
- && hood2.get() == Constants.Shooter.open)
- return true;
- return false;
+ public void resetCatapult() {
+ catapult1.set(Constants.Shooter.reset);
+ catapult2.set(Constants.Shooter.reset);
}
public boolean usePhotogate() {