We have a limit switch that stops a Cam at a certain point in its rotation. We noticed that there can be a visible delay between the limit switching changing states and when the robot program reacts and turns off the motor output, and sometimes there is no delay at all. The sensor is polled in a completly separate loop.
There are two questions here:
1. What would you recommend to solve this problem?
2. Could I use an Interrupt to do this? If so, How do the interrupts in the utiliies of the WPILib Work? (they do not seem intuitive)
How long is the noticeable delay? What is the polling rate on the limit switch? You could use an interrupt to ensure that this process is handled whenever it occurs but know that depending on the priority this could disrupt other functions. Here are some specific definitions of the WPI Interrupt VIs. There are also notes on Architecture at the bottom of the Wait VI.
It sounds like interrupts are the right way to solve this problem. The primary benefit you get is that your interrupt code will not use any CPU when the switch is not being pressed. You can also use digital filtering to debounce the switch before the interrupt is generated. Have a look at the Digital Input->Advanced palette.
The interrupts function as a simple blocking call. This means that it will fit into your code as is very easily. Instead of poling and having a delay in your loop, remove the delay and call the Wait VI.
I attached a snippet demonstrating how I would expect this to work. Naturallly this is simplified and could be split between begin and periodic tasks.