We want to use a limit switch on a motor to keep it from turning past a certain point. Does anyone know how we can program a limit switches. Any help would be appreciated. Thank you in advance.
Sure, it’s pretty straightforward. First you’re going to want to run a PWM cable from the limit switch to a DIO port on your digital sidecar (or decide which port location you’re planning to run the cable later).
If you’re in the basic framework, you need to put a DIO Open (WPI Library -> IO -> DigitalInput -> DIO IN Open) over on the left where the rest of the opens are. Create constants on the DIO Module and Channel inputs that indicate where you plugged the thing in. Put a DIO Close on the right side of the case statements.
Next, set a DIO In Get in the area of code you want to check (for example, inside the Teleop Execute case of the case statement). Run a wire from the DigitalInputDevRef output of the Open to the same input on the Get so that the code knows which device you’re getting the value from. Run a wire from the DigitalInputDevRef output of the Get to the same input on the Close to ensure it exits cleanly.
The “Value” output of the Get is going to be a boolean (true/false) value, that you can run into some logic commands to decide what to do next. For example, you might do a Select (Programming -> Comparison -> Select) that shuts down the motors on True and does what it would have done without the limit switch on False.
We had a couple of the IEC rotary limit switches set up this way using the Normally Closed outputs. That setup returned True when the switch was disconnected from the DIO or when the switch had been triggered. Doing it this way made sure we would fail safe - if the cable was damaged or not plugged in, the motors would not run.
If you’re in the advanced framework or you need more help, PM me and I’ll be happy to help.
Once you get past the opening and getting of the value of the switch, there’s a bit of boolean mess to get it so it will work. Just using a single select won’t quite do (unless you use an AND statement to check if the motor is actually trying to go past the limit and not away from it), as it will shut down the motor permanently unless something physically knocks the motor from pressing the switch.
I used a case select on an “In Range and Coerce” block where the upper and lower limits are set by case statements controlled by a digital input and the input is the motor speed, assuming the motor is run by a speed controller.
For example, the upper limit would be 1. When the switch is tripped, the upper limit becomes 0, thus preventing the motor from driving in that direction. The lower limit would be -1 until the switch is tripped and the lower limit is set to 0.
I like it.
I would use boolean selectors instead of case blocks. I also suggest turning the whole chunk of limit switch logic into a subVI. It would act just like a regular motor control VI, but with a pair of limit switch inputs added.
We ran into a little stumbling block. Well, it’s pretty much what gwytheyrn described. We tried programming a case structure so that it rotated away from the switch when it recieved a value, but that did absolutely nothing, so we’re stuck.
Read post # 8 in this thread. I uploaded a vi. that works just fine. You will need to modify the inputs to point to your switches. Also, verify that the ccw and cw limits are correct for your wiring, if not swap the two values.
Did you try looking at the values on the relevant wires in debug mode so you could see whether the problem was how you had built your case or the values heading into it?
You can either click the lightbulb to highlight execution all the way through (which will really bog down the CRIO’s response time), or you can click on a specific wire or wires with the code running to get a popup with the current value (runs a lot closer to normal speed).
I strongly suggest trying the method in post number 4, as it is quite an elegant way to program for this, imho. Dunno about billbo’s post; I don’t have labview on this computer, but I guess it works in a similar fashion
From a cursory reading of ebmonon36’s post, it sounds exactly like what I posted in the vi. It is simple and quite effective. We used this exact method, except the limit switches were replaced with comparators coming off a pot, to limit the travel of our turret this year.