Limit Switches

Hey guys,

We’re trying to get limit switches working, where if the limit switch is hit, the motor can only turn in the other direction or sit dead, and if the pilot tries to turn the motor in the direction of the limit switch, the motor would just stop.

I have attached the vi for the code and have attached a picture of where the code gets an error. The error occurs in the second Case structure where the limiting values are from 0, 1. The problem is that when the Joystick has a value not within the 0-1 range (somewhere from -1 to 0) it does not turn in the other direction or stop, it keeps jerking and turning in the negative direction.

Just some other information, we’re using a Victor wired to PWM 3 on Digital Sidecar at Slot 4, and are using the USB 3 Joystick port to control the motor, which is a CIM. The limit switches are in Digital I/O ports 9 & 10.

I looked at all the different points to see if the values were what I programmed them to be, and it seemed as though they were, which leads me to believe that it’s a hardware problem.

Has anyone had a similar problem or knows how to fix the problem?

Really appreciate your help.

Thank you,
Sravan





I can’t see the other cases, so I can’t really debug your code. So instead, I wrote an example that should work. It’s set up with it’s own while loop, so you can add it anywhere outside the Basic Robot Main vi. Feel free to put parts of it somewhere else, or incorporate it with your RobotData.

It’s basically a state machine. In the first state you can move the motor both left and right until you hit a limit switch. Then you’re limited to going the other direction or stopping if you go the other way. Once you hit the other limit switch, it’s vice versa.

I hope this helps you. Check out the lvmastery video on State Machines. I found it to be very helpful. Good luck!

limit switch state machine.vi (57.7 KB)


limit switch state machine.vi (57.7 KB)