Home Sweet Home

Before I got VEX IQ, I used to work with more serious servos. One feature I was used to having was homing. Homing means getting a servo back to its exact starting position so the robot always knows where it is. I found out that in VEX IQ the servos do not have a built-in way to home themselves. At first, this was a little disappointing.
After thinking about it for a while, I came up with a workaround. The idea is simple. Put a barrier at a known location and slowly drive the motor toward it. While the motor is moving, the program constantly checks the motor current. When the motor hits the barrier, it can no longer move, so the current suddenly increases. The program detects this increase, stops the motor, and marks that spot as a known position.
This is a link to my code on GitHub - check it out, in the comments I explained a few additional tricks to make the homing more precise and repeatable.
After that, the motor can be set to any position you want. I thought this was a pretty neat solution because it does not need any extra sensors. It also showed me that if a system does not have a feature you need, sometimes you can find your own way to make it work.