From 00f515a1e32e2ef2217aa5c981a860ec584f16f1 Mon Sep 17 00:00:00 2001 From: Cindy Zhang Date: Sat, 4 Feb 2017 11:01:04 -0800 Subject: [PATCH] move setmotorvalues to execute and set wheels to constant speeds --- .../robot/commands/shooter/RunFlyWheel.java | 9 ++------- .../shooter/RunFlyWheelContinuous.java | 9 +++++---- .../robot/commands/shooter/RunIndexWheel.java | 19 +++++++------------ .../shooter/RunIndexWheelContinuous.java | 4 ++-- .../team3501/robot/subsystems/Shooter.java | 1 + 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java index 7850688..6ac5d69 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java +++ b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheel.java @@ -3,7 +3,6 @@ package org.usfirst.frc.team3501.robot.commands.shooter; import org.usfirst.frc.team3501.robot.Robot; import org.usfirst.frc.team3501.robot.subsystems.Shooter; -import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; /** @@ -14,7 +13,6 @@ import edu.wpi.first.wpilibj.command.Command; */ public class RunFlyWheel extends Command { private Shooter shooter = Robot.getShooter(); - Timer timer; private double time; /** @@ -27,21 +25,18 @@ public class RunFlyWheel extends Command { */ public RunFlyWheel(double time) { requires(shooter); - - timer = new Timer(); this.time = time; } // Called just before this Command runs the first time @Override protected void initialize() { - timer.start(); - shooter.setFlyWheelMotorVal(shooter.CURRENT_SHOOTING_SPEED); } // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + shooter.setFlyWheelMotorVal(shooter.CURRENT_SHOOTING_SPEED); } // Called once after isFinished returns true @@ -59,7 +54,7 @@ public class RunFlyWheel extends Command { @Override protected boolean isFinished() { - return timer.get() >= time; + return timeSinceInitialized() >= time; } } diff --git a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheelContinuous.java b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheelContinuous.java index cc07893..af77483 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheelContinuous.java +++ b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunFlyWheelContinuous.java @@ -1,6 +1,7 @@ package org.usfirst.frc.team3501.robot.commands.shooter; import org.usfirst.frc.team3501.robot.Robot; +import org.usfirst.frc.team3501.robot.subsystems.Shooter; import edu.wpi.first.wpilibj.command.Command; @@ -17,7 +18,7 @@ import edu.wpi.first.wpilibj.command.Command; * @author Shaina */ public class RunFlyWheelContinuous extends Command { - private double motorVal; + private Shooter shooter = Robot.getShooter(); /** * See JavaDoc comment in class for details @@ -25,19 +26,19 @@ public class RunFlyWheelContinuous extends Command { * @param motorVal * value range from -1 to 1 */ - public RunFlyWheelContinuous(double motorVal) { - this.motorVal = motorVal; + public RunFlyWheelContinuous() { + requires(shooter); } // Called just before this Command runs the first time @Override protected void initialize() { - Robot.getShooter().setFlyWheelMotorVal(motorVal); } // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + shooter.setFlyWheelMotorVal(shooter.CURRENT_SHOOTING_SPEED); } // Called once after isFinished returns true diff --git a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheel.java b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheel.java index 4c8cd54..6838354 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheel.java +++ b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheel.java @@ -1,8 +1,8 @@ package org.usfirst.frc.team3501.robot.commands.shooter; import org.usfirst.frc.team3501.robot.Robot; +import org.usfirst.frc.team3501.robot.subsystems.Shooter; -import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.command.Command; /** @@ -14,9 +14,8 @@ import edu.wpi.first.wpilibj.command.Command; * @author Shaina */ public class RunIndexWheel extends Command { - Timer timer; + private Shooter shooter = Robot.getShooter(); private double time; - private double motorVal; /** * See JavaDoc comment in class for details @@ -26,30 +25,26 @@ public class RunIndexWheel extends Command { * @param time * in seconds, amount of time to run index wheel motor */ - public RunIndexWheel(double motorVal, double time) { - requires(Robot.getShooter()); - - timer = new Timer(); - this.motorVal = motorVal; + public RunIndexWheel(double time) { + requires(shooter); this.time = time; } // Called just before this Command runs the first time @Override protected void initialize() { - timer.start(); - Robot.getShooter().setIndexWheelMotorVal(motorVal); } // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + shooter.setIndexWheelMotorVal(shooter.DEFAULT_INDEXING_SPEED); } // Called once after isFinished returns true @Override protected void end() { - Robot.getShooter().stopIndexWheel(); + shooter.stopIndexWheel(); } // Called when another command which requires one or more of the same @@ -61,7 +56,7 @@ public class RunIndexWheel extends Command { @Override protected boolean isFinished() { - return timer.get() >= time; + return timeSinceInitialized() >= time; } } diff --git a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheelContinuous.java b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheelContinuous.java index 1bf1c6f..bf9af68 100644 --- a/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheelContinuous.java +++ b/src/org/usfirst/frc/team3501/robot/commands/shooter/RunIndexWheelContinuous.java @@ -27,18 +27,18 @@ public class RunIndexWheelContinuous extends Command { * value range from -1 to 1 */ public RunIndexWheelContinuous() { - + requires(shooter); } // Called just before this Command runs the first time @Override protected void initialize() { - shooter.setIndexWheelMotorVal(shooter.CURRENT_SHOOTING_SPEED); } // Called repeatedly when this Command is scheduled to run @Override protected void execute() { + shooter.setIndexWheelMotorVal(shooter.DEFAULT_INDEXING_SPEED); } // Called once after isFinished returns true diff --git a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java index 73c1b23..ba0f51c 100644 --- a/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java +++ b/src/org/usfirst/frc/team3501/robot/subsystems/Shooter.java @@ -10,6 +10,7 @@ public class Shooter extends Subsystem { private static Shooter shooter; private final CANTalon flyWheel, indexWheel; + public static final double DEFAULT_INDEXING_SPEED = 0; public static final double DEFAULT_SHOOTING_SPEED = 0; public static double CURRENT_SHOOTING_SPEED; -- 2.30.2