View Single Post
  #8   Spotlight this post!  
Unread 09-02-2012, 17:15
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

Or you could try this:

The nice thing about this, for all of your timed commands you only have to define what its doing when its running.

Code:
public abstract class Mechanism extends Subsystem{
    
    public abstract void stop();
    
}
Code:
public abstract class TimedCommand extends Command{
    
    private Mechanism mechanism;
    
    public TimedCommand(Mechanism mechanism, double time){
        super(time);
        this.mechanism = mechanism;
        requires(mechanism);
    }
    
    @Override
    protected void execute() {
        //do nothing
    }

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


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

    @Override
    protected void initialize() {
        RobotMap.SHOOTER.shoot();
    }
}
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote