|
Re: How to program a limit switch?
I've attached screenshots of how our team used limit switches to limit movement in 2011. The first screenshot shows how we initialized our limit switches, and the second shows how we implemented them in our Teleop code.
The VI with the arrow and question mark in the second screenshot is In Range And Coerce, which is a VI many people don't know about - primarily the Coerce part. It takes whatever number you input (in this case, our motor signal) and forces it inside a specified range if it falls outside the limits.
In our code, if the upper limit switch is pressed, it sets the upper end of the range to 0 so we can't move up any farther. (So our range is -1 to 0.) Likewise, if the lower switch is pressed, we set the lower end to 0 (range: 0 to 1).
|