rover 5 hall effect encoder testing
I'm a beginner to robotics control so everything I posted here may be wrong. I'd appreciate any comments.
Long story in short. It all begin when I bought a 4WD arduino robotics car from dx.com a month ago(http://dx.com/p/multi-function-4wd-arduino-robot-raider-car-kits-128715). It was a pretty good deal at that time. After learning arduino, I programmed robotics car to move without problem. However when I started to do basic line tracking, I found that there is no way to make the car perform in the expected way. For example, a simple command like move it in straigh line is not easy (nor even mention turn a speicific degree). Then I did my search on control theory and learned some odometry, PID and encoder.
I realized that I need a encoder first to do real feed back adjustment. So I looked up encoder solution. All are quite expensive... I found rover 5 which only cost less than $60 with 4 quadracture encoder.
When it arrived, I opened the motor inside immediately. I found that optical encoder was replaced by hall effect encoder. There is a manetic ring tied to the gear next to motor. There are four wires: red (5V), black(gnd), yellow (s1) and white (s2). I read the article about quadratic encoder from http://letsmakerobots.com/node/24031 . I wrote the following arduino to test if all 4 encoder works.
The test is to connect yellow and white to pin 2 and pin3 of arduino uno. Rotate wheel for 360 degree ( can't measure it exactly but it doesn't really matter to my concern).
static long s1_counter=0;
static long s2_counter=0;
attachInterrupt(0, write_s1, CHANGE); /* attach interrupt to pin 2*/
attachInterrupt(1, write_s2, CHANGE); /* attach interrupt to pin 3*/
I roated almost 360 degree for each of them.
For L1 wheel, I got counter 85 times for S1 and 160 for S2. There' pattern of S1 and S2 change. S1,S2, S1,S2, S1, S2, S2, S1, S2, S2, S2, S2 (it repeats this pattern)
For L2 wheel, I got counter 165 times for S1 and 166 for S2. The pattern is S1, S2, S1, S2...
For R1 wheel, I got 165 times for S1 and 205 for S2. I can't find the pattern.
For R2 whell, I got counter 167 times for S1 and 168 for S2. The pattern is S1, S2,S1, S2..
I repated the test for couple times. The counter either equal to each other as L2 and R2 or quite bizzard as L1 and R1.
My question: Are L1 and R1 are defective items as counter doens't match to each other?
First of all, the test program is based on my instinct. I haven't read the enocder library to figure out what they are doing. But in genearl, counting the pulse in one round. But I'm not sure if counting makes more sense when applying XOR gate to yellow and white wire.
My tools are limited. So if you have any clues, I'd really appreciate it.