Doing "something" with my encoder inputs.
March 30, 2012
I have a Rover 5 with the Dagu red back spider and motor controller. I have connected 2 encoders (one on each side) to the motor controller / red back spider. I found the encoder library, and tested it. I now have 2 working encoders and can read the value of them with the example sketches of the encoder library. So far so good.
Now I wanted to make a sketch so that when my Rover detects an object it does a 90° turn. I'll use an ultrasonic sensor on a servo to decide between left and right. I already have the code for the ultrasonic sensor and servo. But the thing that I can't figure out is how to code a "void turnleft()" That function should make my robot turn 90°. With some testing I can easily find how many "pulses" from the encoder a 90° turn is. But how can I program this function? It must spin the motors for xxxx number of encoder pulses.
Another possible issue is also that the encoders have to count very fast so they sometimes jump by 2 at once.