I am writing some logic for a PID controlled catapult (In order to improve precision). That is all fine and well. However, if, for some reason, the encoder wire disconnects, the motor spins continuously in the opposite direction, which breaks my catapult. To solve this, I would like to write a function to catch the failure of the wire, and use that to switch the runmode to not using the encoder. I have both control functions working properly. My issue is the transition. How can I detect when an encoder disconnects.
Note: I have thought about writing a function to checks the return value of the encoder to see if it is disconnected, but I no not know what is returned by the getPosition function when the encoder is disconnected. Is it 0, is it null, or is it something else entirely?