View Single Post
  #5   Spotlight this post!  
Unread 10-03-2013, 22:21
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Best way to implement a timed action

If you're using Java, anonymous classes can make adding two commands seem much less annoying:
Code:
addSequential(new Command(X/1000.0) {
    protected void initialize() {
        injector.actuateForward();
    }
    protected void execute() {}
    protected boolean isFinished() {
        return isTimedOut();
    }
    protected void end() {
        injector.stopActuating();
    }
    protected void interrupted() {
        end();
    }
});
addSequential(new Command() {
    protected void initialize() {
        injector.actuateBackward();
    }
    protected void execute() {}
    protected boolean isFinished() {
        return microswitch.isTriggered();
    }
    protected void end() {
        injector.stopActuating();
    }
    protected void interrupted() {
        end();
    }
});
Unfortunately, this will only stop the injector within whatever time increment Scheduler.run() is called, which if it's being run in periodic() is the period between driver station packets are coming, or about 20ms. A thread may be a better choice if you need finer resolution.
__________________
I code stuff.