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 under
Support -> Find FRC Example... -> FRC Robotics -> roboRIO-> Sensors