Thread: Delay Problem
View Single Post
  #1   Spotlight this post!  
Unread 12-02-2014, 14:06
krieck's Avatar
krieck krieck is offline
Registered User
AKA: Keith
FRC #2846 (Firebears)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 49
krieck is an unknown quantity at this point
Re: Delay Problem

The Command class already has a built-in timeout function. You just set it up in the initialize() method and then stop your command in isFinished:

Code:
package org.usfirst.frcxyz.commands;

import edu.wpi.first.wpilibj.command.Command;

public class DriveTimeCommand extends Command {
    
    double timeToDriveInSeconds = 2.5;
    
    public DriveTimeCommand() {
        requires(Robot.chassis);
    }

    protected void initialize() {
        setTimeout(timeToDriveInSeconds);
    }

    protected void execute() {
        Robot.chassis.arcadeDrive(1.0, 0.0);
    }

    protected boolean isFinished() {
        return isTimedOut();
    }

    protected void end() {
        Robot.chassis.arcadeDrive(0.0, 0.0);
    }

    protected void interrupted() {
        end();
    }
    
}
Reply With Quote