Quote:
Originally Posted by TimTheGreat
So if the sensor is at 200 and I want it to go to 1000 it will go backwards 223?
|
So assuming 1024 units per rotation (analog sensor), if you want to go "backwards" set the target to -23. This will move backwards by -223 (since your current position is 200), instead of moving forward by 800 (pos200=>pos1000).
The basic idea is if you want to move forward, use the appropriate multiple of your target position in the positive direction. If you want to move reverse, use the appropriate multiple in the negative direction. If you want to servo using the shortest distance, calculate how far the target is moving forward, and moving backwards, pick the shortest one, and use that as the final set point.
Attached is an excel sheet demonstrating a few examples of how to do this.