Go to Post So your gearbox failed, and your first course of action was to post about it CD? This is an interesting failure recovery plan. :) - JVN [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #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
  #2   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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:54.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi