From 0781814f47ce59c8614cc7edc2385736d3c40bb6 Mon Sep 17 00:00:00 2001 From: Meryem Esa Date: Tue, 9 Feb 2016 21:57:38 -0800 Subject: [PATCH] create and implement code for DriveForTime command --- .../team3501/robot/commands/DriveForTime.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 src/org/usfirst/frc/team3501/robot/commands/DriveForTime.java 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() { + } +} -- 2.30.2