Two limit switches, one button

Hey guys, this is my second year programming and have never programmed limit switches before. I know that there are a few other limit switch questions, but I want to use two switches (A top and bottom) and one button to control our lift motor. I was wondering if anyone could provide me with an example of how I could do this or if it is even possible. Anything is highly appreciated! Thanks!

You could use a state machine (in Teleop or Periodic Tasks) or a sequence (in Periodic Tasks only).

  • push button
  • run up until limit switch is hit and stop
  • push same button (or a different one)
  • run down until limit switch is hit and stop

If one button, then use a feedback node or shift registers to remember the previous direction.

How can I do this with one motor? Whenever i try to connect them both, the wire breaks. I have tried using a “or” boolean but with no luck.

Do you want to control a motor using only one joystick button?

Tell us a story. Pretend that the program and wiring are done, and describe for us what the person at the controls does and what the robot does in response. Use phrases like “presses the button for a half second then releases it” and “lift starts moving up and doesn’t stop until the top limit switch is activated.” Make sure you cover every case that you want to handle. Then add some cases that you don’t expect but might still happen, like “holds the button down even after the lift has reached the bottom” or “presses the button again while the lift is already moving upward”.

Once we know what you want the robot to do in response to the operator’s actions, we can show you how to create code that will do it.

How would you feel about using different buttons for up and for down?
I worry that with a single button you won’t be able to control the direction the elevator is moving in, especially if a limit switch shifts or breaks.
Do you have a mechanical brake to prevent the elevator from dropping without power when loaded with a tote (or not)?

-hold the up button and it rises until the button is released or the limit switch is contacted.

-hold the down button and it drops until the button is released or the limit switch is contacted.

We would be fine to use two buttons. We would like to push a button and have the motor move up and half speed and stop when the limit switch is hit, then hitting the same button (or another) and having the motor go down until the bottom limit switch is hit, and never stopping in the middle. I hope that clears up what we would like to!

The “never stopping in the middle” can be a problem if one of your limit switches doesn’t work properly. You might want to rethink your decision to let the lift keep running after the button is released.

How much other stuff is the operator going to need to do while the lift is in transit? Would it be too much trouble for him or her to be required to keep the button pressed in order for the lift to keep moving? That would make the lift a lot less likely to destroy itself if something failed.

After talking to my mentor, I had miss understood the intent of the limit switch, we DO want to want to have the motor run as long as the button is held, or the limit switch is hit, whichever comes first. I have figured out how to run the motor (up with button 1 and down with button 2) I could just use some help figuring out how to incorporate the two limit switches to turn the motor off. Any example would be highly appreciated!

There are 6 possible states for a button and 2 limit switches that can’t be true at the same time. What do you want the motor to do for each of them?

  • Button not pressed, Switch 1 false, Switch 2 false
  • Button pressed, Switch 1 false, Switch 2 false
  • Button not pressed, Switch 1 true, Switch 2 false
  • Button pressed, Switch 1 true, Switch 2 false
  • Button not pressed, Switch 1 false, Switch 2 true
  • Button pressed, Switch 1 false, Switch 2 true

To tell you the truth, I’m not sure. We want the limit switches as a safety to stop the motor from from hitting the sprockets. I’m not sure what needs to be true and what needs to be false. I hope that helps?

Here’s a strong hint: use a boolean AND function to combine the “up” button value with the “top” limit switch value, so that the result is true only when the button is pressed and the limit switch is not activated. Do the same thing with the “down” button and “bottom” switch.

Now you have two boolean values, one saying “move up” and the other saying “move down”. If you can’t figure out how to use those values to control your lift motor, ask for more help.

I suggest that when you test this you do it at some minimal power, e.g., .4, and hold each limit switch down at the start to verify that the switch matches the button direction.

The limit switch can be wired either Normal-Closed or Normally-Open and the boolean generated might be reversed from what you expect, i.e., it may be True when you expected False.

So when the mechanical system overshoots due to lag in the control system, and the limit switch releases, up becomes a valid command again?

We are scraping for documentation on the new Switch VI’s. Are these implemented using the FPGA hardware, so it is sampling quick enough that any mostly full range edge is caught? Does the counter reset on system reset? Can we reset the counter? Any debouncing built in?

Inquiring minds,
Tim

The limit switch is a simple wrapper over the DIO functions that were already available. They were added primarily for simulation. In order for a simulated robot to be able to identify how a digital line should toggle when something moves, it is useful to identify the switch, tell the physics engine where it is, how it is wired, etc. This is also true of the potentiometer. It is a simple wrapper over AI.

So the FPGA is doing the low level read and filter of the switch, but it is the RT side that is responsible for modifying a motor or other actuator in response. There is no new way to “tie things together” in the FPGA.

Greg McKaskle

If the hardware is built so that the limit switch is not active when the mechanism is at the end of its travel, then what you describe is possible. I wouldn’t suggest designing it that way.

Thanks. More “I needed to know that”

The system in question is pretty quick, and I’m not sure I’ll get the nice long lever necessary. I’m thinking some latching & resetting by other actions may be in order. I was looking for a state machine this year…

Thank you,
Tim

So, given “Normally Open” port true on open (and wiring GND to Signal on the DIO through the switch) and a 2.0V ish to 0.8 ish transition holding below 0.8V for more than 20nS, we will see WPI_SwitchGetLimitValueReturn true, and WPI_SwitchGetCount will increment.

When does WPI_SwitchGetLimitValueReturn reset? On a transition from -0.8V to 2.0V longer than 20nS?

The counter resets to zero on the call to Begin? And between autonomous and teleop?

I keep getting challenged (good questions, mostly) on stuff like this, so the ducks need to line up

TIA,

Tim

There have been some good comments posted here that I would recommend reading them - especially the one by cgmv123.

For those who are looking for more of a tutorial of one way of accomplishing this task - currently up while button 1 and not top limit switch else down while button 2 and not bottom limit switch -
Please refer to this tutorial that I have made, Click here for tutorial It is under limit switch tutorial, although the state machine tutorial is a similar scenario.

Thanks so much to everyone who gave their impute! They work like a charm!