![]() |
Programming Limit Switches
Hello FRC Community,
We were putting some Limit Switches on our robot. I was trying some different interpretations of what I found here: https://wpilib.screenstepslive.com/s...ntrol-behavior But I cant seem to understand it. What I basically need to do is set a motor value to 0 when the switch is hit. Any help would be appreciated. Thanks in Advance. |
Re: Programming Limit Switches
What you want to do is use code that is sort of like the following:
if(limitSwitch.get() == true){ motorName.stopMotor(); } This code waits for a limit switch to be pressed. When it is pressed it turns true, triggering the contents of the if statement. The contents call the WPI method stopMotor on the motor. Hopefully this helped. |
Re: Programming Limit Switches
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 { |
Re: Programming Limit Switches
Also, be aware to check the limit switch before turning on a motor, not just when to turn it off. So, for example, button A raises a lift when held for example. When the lift hits a limit switch, it stops without having the operator releasing the button. Now the lift is at the top. But, if the operator presses the same button again the lift shouldn't move. This is one condition that our new programmers don't think about. They would start the motor and then check to limit switch in the IsFinished method. Which caused the lift to start slowly pulsing up. So, they learned to check the limit switch before starting the motor, and then check in the IsFinished.
This is a great learning experience for them. As I say at work "Programming the Happy path is easy. It's how you handle the unexpected is what makes it hard." Great way for them to learn to think beyond the requirements, to the undocumented requirements. Brian |
Re: Programming Limit Switches
Quote:
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? |
Re: Programming Limit Switches
Quote:
Quote:
Code:
motor.set(TopLimitSwitch.get() ? -1 : BottomLimitSwitch.get() ? 1 : 0);Code:
if (TopLimitSwitch.get() {Quote:
|
Re: Programming Limit Switches
Quote:
|
Re: Programming Limit Switches
Just a FYI: The limit switches I have return true when not pressed, and false when pressed.
|
Re: Programming Limit Switches
Quote:
|
Re: Programming Limit Switches
Always add an option to your drivers station to remotely disable all limit switches. If a switch is damaged in a match you might want to override them so you can keep playing and your drivers will just need ro be more careful than usual for that march.
|
| All times are GMT -5. The time now is 10:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi