Thread: Delay Problem
View Single Post
  #9   Spotlight this post!  
Unread 12-02-2014, 14:16
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Delay Problem

Quote:
Originally Posted by krieck View Post
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();
    }
    
}
We just discovered the timeout ability for commands this year and I keep forgetting that you can do it. We're using it to timeout our hot goal processing in case we don't find a target we don't end up sitting for the entire autonomous period.
Reply With Quote