View Single Post
  #8   Spotlight this post!  
Unread 15-03-2011, 15:09
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Double Tube Autonomous

Quote:
Originally Posted by Tom Bottiglieri View Post
If you want to see more I can send you some code snippets.
Here is the AutoModeController. You give this guy a list of commands, and then tell it to execute them.
PHP Code:
public class AutoModeController {
    
// Variables

    
NutronsQueue cmdList = new NutronsQueue();
    
AutoModeCommand curCmd null;

    
// Add commands
    
public void addCommand(AutoModeCommand cmd) {
        
cmdList.push(cmd);
    }

    public 
void flush() {
        
cmdList.removeAllElements();
        
curCmd null;
    }

    
// Execute commands
    
public void handle() {
        
boolean firstRun false;
        if(
curCmd == null) {
            
curCmd = (AutoModeCommandcmdList.pop();
            if(
curCmd != null) {
                
System.out.println("Popped a command: " curCmd);
            }
            
firstRun true;
        }

        if(
curCmd != null) {
            if(
firstRun) {
                
curCmd.init();
                
firstRun false;
            }
            if(
curCmd.doWork()) {
                
// this will happen when command is done
                // Will grab next command on next call of handle()
                
curCmd.finish();
                
curCmd null;
                
System.out.println("work done");
            }
        }
        else {
            
// Maybe add something for do nothing?
        
}
    }

Here's an example of an AutoModeCommand (In this case, it raises the elevator)
PHP Code:
public class SignalElevatorPosCommand implements AutoModeCommand {

    
double wantedPos 0;

    public 
SignalElevatorPosCommand(double pos) {
        
wantedPos pos;
    }

    public 
boolean doWork() {
        
ElevatorController.getInstance().gotoScoringPosition(wantedPos);
        return 
true;
    }

    public 
void init() {
        
// Init code for this command goes here!
    
}

    public 
void finish() {
        
// Clean up goes here!
    
}

Here's a way to set it all up:
PHP Code:
public class MyCoolAutonomousRobot extends IterativeRobot {

    
AutoModeController ac = new AutoModeController();
 
    public 
void autonomousInit() {
       
ac.flush();
       
ac.addCommand(new DriveDistanceCommand(100.7510)); // 10 feet, .75 power, 10 sec timeout
       
ac.addCommand(new SignalElevatorPosCommand(Elevator.POS_TOP_PEG)); 
       
ac.addCommand(new CapTubeCommand());
       
ac.addCommand(new DriveDistanceCommand(-10,0.75,10));
       
ac.addCommand(new TurnDegreesCommand(-1801.03.0); // 180 deg, 1.0 max power, 3s timeout
    
}

    public 
void autonomousPeriodic() {
        
ac.handle();
    }

Hope this helps!
Reply With Quote