View Single Post
  #9   Spotlight this post!  
Unread 16-02-2015, 20:03
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Re: Programming Limit Switches

Quote:
Originally Posted by GeeTwo View Post
Unless you are making a one-shot device, you need to be a bit more subtle. For argument sake, and since it's the more common case for limit switches this year, I'll assume your actuator is moving up and down. I'll also assume that motion in the positive direction is up, and the negative direction is down.

If the top limit switch is set, you want to limit your applied force so that it can only be zero or negative; you may want to "come down" later.

If the bottom limit switch is set, you want to limit your applied force so that it can only be zero or positive; you may want to "go up" later.

Just doing the full initializer and the set() methods, it would look something like:
Code:
Class MyWinchController extends Talon {
    DigitalInput topLimitSwitch;
    DigitalInput bottomLimitSwitch;

    MyWinchController(int PWM, int topLimitDIO, int bottomLimitDIO) {
        super(PWM);
        topLimitSwitch = new DigitalInput (topLimitDIO);
        bottomLimitSwitch = new DigitalInput (bottomLimitDIO);
    }

    set(double speed) {
        if (topLimitSwitch.get() && (speed>0.0)) speed = 0.0;
        if (bottomLimitSwitch.get() && (speed<0.0)) speed = 0.0;
        super.set(speed);
    }
}
If I am using a simple motor for my elevator system, would I need the && statements for speed?

If I wanted the elevator to go in the opposite direction for about 1 second based on which switch is pressed, what would that look like?

And what is 'super(PWM)' represent?
Reply With Quote