From: Meryem Esa Date: Wed, 10 Feb 2016 05:57:38 +0000 (-0800) Subject: create and implement code for DriveForTime command X-Git-Url: http://challenge-bot.com/repos/?p=3501%2Fstronghold-2016;a=commitdiff_plain;h=0781814f47ce59c8614cc7edc2385736d3c40bb6 create and implement code for DriveForTime command --- diff --git a/src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java b/src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java new file mode 100755 index 00000000..c44590af --- /dev/null +++ b/src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java @@ -0,0 +1,55 @@ +package org.usfirst.frc.team3501.robot.commands; + +import org.usfirst.frc.team3501.robot.Robot; + +import edu.wpi.first.wpilibj.Timer; +import edu.wpi.first.wpilibj.command.Command; + +/** + * This command + */ +public class DriveForTime extends Command { + + private final static double DEFAULT_SPEED = 0.5; + private double speed; + private double seconds; + + private Timer timer; + + public DriveForTime(double seconds, double speed) { + this.seconds = seconds; + this.speed = speed; + } + + public DriveForTime(double seconds) { + this(seconds, DEFAULT_SPEED); + } + + @Override + protected void initialize() { + timer = new Timer(); + timer.start(); + + Robot.driveTrain.setMotorSpeeds(speed, speed); + } + + @Override + protected void execute() { + } + + @Override + protected boolean isFinished() { + if (timer.get() >= seconds) + return true; + return false; + } + + @Override + protected void end() { + Robot.driveTrain.setMotorSpeeds(0, 0); + } + + @Override + protected void interrupted() { + } +}