@@ -0,0 +1,2588 @@
+/*%0A * To change this template, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage mechanism;%0A%0Aimport actuator.IMotor;%0Aimport core.GRTLoggedProcess;%0Aimport event.SwitchEvent;%0Aimport event.SwitchListener;%0Aimport sensor.GRTSwitch;%0A%0A/**%0A *%0A * @author dan%0A */%0Apublic class Drawbridge  extends GRTLoggedProcess implements SwitchListener%7B%0A    private IMotor motor;%0A    private GRTSwitch limitUp;%0A    private GRTSwitch limitDown;%0A    private int targetState;%0A    private static final int UP = 0;%0A    private static final int DOWN = 1;%0A    private static final int DISABLED = 2;%0A    %0A    public Drawbridge(IMotor motor, GRTSwitch limitUp, GRTSwitch limitDown, String name)%7B%0A        super(name);%0A        this.motor = motor;%0A        this.limitDown = limitDown;%0A        this.limitUp = limitUp;%0A        limitDown.addSwitchListener(this);%0A        limitUp.addSwitchListener(this);%0A    %7D%0A%0A    %0A    public void switchStateChanged(SwitchEvent e) %7B%0A        //if upper limit switch is tripped and we are going up...%0A        if((e.getSource() == limitUp) && (targetState == UP))%7B%0A            %0A            //if we are at upper limit whent trying to raise:%0A            if(e.getState() == GRTSwitch.PRESSED)       //If the upper switch is pressed, stop raising%0A                stopArm();%0A        %7D%0A        %0A        //Otherwise, if we are going down and there is a change in the lower limit switch%0A        else if((e.getSource() == limitDown) && (targetState == DOWN))%7B%0A            if(e.getState() == GRTSwitch.PRESSED)%0A                stopArm();%0A        %7D%0A    %7D%0A    %0A    public void raiseArm()%7B%0A        //Set our goal to go up%0A        targetState = UP;%0A        %0A        //If the upper limit has not been reached, keep raising%0A        System.out.println(%22Limit Up State: %22 + limitUp.getState(GRTSwitch.KEY_STATE));%0A        if(limitUp.getState(GRTSwitch.KEY_STATE) != GRTSwitch.PRESSED)%7B%0A            %0A            System.out.println(%22Raising arm%22);%0A%0A            motor.setSpeed(1.0);%0A        %7D%0A    %7D%0A%0A   %0A    /**%0A     * %0A     */%0A    public void lowerArm()%7B%0A        %0A        //We want to go down now%0A        targetState = DOWN;%0A        %0A        System.out.println(%22Limit Down State: %22 + limitDown.getState(GRTSwitch.KEY_STATE));%0A        //Set motor speed to go down if we have not reached the lower limit%0A        if(limitDown.getState(GRTSwitch.KEY_STATE) != GRTSwitch.PRESSED)%7B%0A            motor.setSpeed(-1.0);%0A            %0A            System.out.println(%22Lowering arm%22);%0A        %7D%0A    %7D%0A    %0A    public void stopArm()%7B%0A        targetState = DISABLED;%0A        motor.setSpeed(0.0);%0A    %7D%0A%7D%0A

add a drawbridge mech