Basic Limit Switch

Our team wants to have basically a kill switch so that when our arms reach a certain point, they trip the limit switch and make it so we can’t move them any further out. Does anyone have an example or explanation for how to code something like this? Thanks
Edit: We are using Gear Motors, which apparently have sensors built in to add this type of control. Does anyone know how this works?

Here is a limit switch example.

The newest AndyMark PG motor/gearboxes have an integrated encoder.
If you start from a known position then it’s possible to measure to a certain point. There are pitfalls and drawbacks to using an encoder for this. A limit switch is usually more dependable.
Here is an encoder example

There are also working examples of both of these installed with LabVIEW.
From the Getting Started window look underSupport -> Find FRC Example… -> FRC Robotics -> roboRIO-> Sensors

Take a look at Team 358’s Limit Switch example.

The “In Range and Coerce” function will limit the motor output so that it can’t drive forward if the “forward limit” switch is active, and it can’t drive backward if the “backward limit” switch is active. If you don’t have both switches, replace the DIO Get and associated select with a constant 1 or -1 into the In Range and Coerce input.

Ok, thanks everyone. It looks like we are going with the encoder for this, but will need to set up a limit switch for something else anyways. Can someone please explain what the values mean for the encoder example and how to connect it to the motor control in the teleop?

Note that it’s common to pair limit switches and encoders in a scenario like yours – the limit switches are used to detect when the arm is in a known position, which allows you to better interpret the result of the encoder.

I’ve figured out how to setup the normal limit switch, however, I am not sure on how to set it up so you can have a button override what the switch does when pressed. Someone helped us set up something similar last year at competition, but our old code got messed up.

The attached file is only meant to be suggestive, but would accomplish the task of an override.
It assumes a limit switch that is true if not, remove the not gate.

Basically an override boils down to the limit is not pressed or the override is.

Note: on the comment going to the motor, the value is otherwise zero.

Thanks for replying everyone. We have it setup how we want now. We ended up going with two limit switches set as upper and lower limits with the in range and coerce function on labview.