Magnetic sensors

So our team is thinking about using magnetic sensors as a limit switch to stop our arm from going up too far and down too far so it does not eat our robot. But I have been having trouble coding it. We are trying to use a joystick to control the speed up and down but then stop it from hitting the top, then be able to come back down again and do the same, then be able to repeat. I was wondering if anyone had some sample code I could look at. Or try to look at the code that I have made and try to fix it. I’ll post my code later today when I get to our robotics room, but if anyone has some sample code that would be wonderful.

Here’s an example: http://www.team358.org/files/programming/ControlSystem2015-2019/labview/index.php#LimitSwitch

Note: Be careful with the “In Range and Coerce” vi
It does not automatically check both limits (both diamonds must be black).
You have to tell it to check both- right click and make sure both limits are checked.

CoerceLimit.jpg

Clarification on the behavior of the ‘In Range and Coerce’ function:

This function always evaluates both limits. The ‘Include upper limit’ and Include lower limit’ options are used to specify whether the limit values should be included as ‘in range’.

So, with the default configuration having a check next to ‘Include lower limit’ and no check next to ‘Include upper limit’, if we wire a 0 to the ‘lower limit’ input terminal and wire a 10 to the ‘upper limit’ terminal, we will get the following result:

If we add a check next to ‘Include upper limit’, we get the following result:

Thanks for the clarification.