|
Re: Limit Switches
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.
|