View Single Post
  #6   Spotlight this post!  
Unread 09-02-2012, 16:57
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Set command to run for a certain amount of time

Also if you don't need interrupts it may be helpful to have a timed command class:

This class is designed for commands that don't have interrupts and have static motor speeds.

If you wanted dynamic motor speeds you wouldn't want to override execute.

Code:
public abstract class TimedCommand extends Command{
    
    public TimedCommand(double time){
        super(time);
    }
    
    @Override
    protected void execute() {
        //do nothing
    }

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


    @Override
    protected void interrupted() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
Code:
public class RunMotor extends TimedCommand{
    
    private static double time = 1.0;
    
    public RunMotor(){
        super(time);
    }

    @Override
    protected void initialize() {
        motor.set(1);
    }

    @Override
    protected void end() {
        motor.set(0);
    }
}
__________________
"Never let your schooling interfere with your education" -Mark Twain

Last edited by mwtidd : 09-02-2012 at 16:59.
Reply With Quote