August 14, 2013 Leave a comment
I have been doing some testing on my robot, in particular the wheels. I noticed, as expected, that the wheels do not turn at the same speed even when given the same command. This is a common problem and means that the robot does not drive in a straight line. The problem is even more evident when the robot is driving on carpet, as the rear castor takes a while to straighten up, meaning the robot drives on a curved trajectory. The solution to this issue is to add wheel encoders. I have designed and built encoders in the past so I had a pretty good idea of what was required. I once designed an encoder that fits inside a servo housing, replacing the original electronics. The servos motor could be driven via a motor controller, as you would a normal motor, and the encoder would give feedback of the speed, allowing closed loop control. This design used an infra-red reflective sensor shining onto one of the gears inside the servo which had alternating black and white stripes painted onto it. When combined with a schmitt trigger, this set-up gave a series of pulses, the frequency of which was proportional to the speed of the motor. I didn’t want to use this exact design on my humanoid robot. I didn’t want to modify the servo to run as a normal motor as more hardware would be needed in the form of a motor controller. I decided to use a variation of the design but with the encoder external of the servo, shining onto the wheel itself. The resolution of the encoder would not be as good doing it this way but it was a sacrifice I was willing to make.
I decided to use the QRD1114 sensor. This is a popular sensor and is used for line following robots quite a lot. It can detect the difference between black and white surfaces, due to the way the IR light reflects or is absorbed by the surface. I wanted to incorporate a schmitt trigger into the design to ensure the output of the encoder is a clean, square wave. I have designed and build these in the past using a comparator and a bunch of resistors. However, after some research I found a buffer chip that will do the job without any external components. The part number is SN74LVC1G17DBVR. It’s a tiny, surface mount chip, perfect for the job. The circuit schematic for the encoder is shown below.
I designed the board for the encoders and fabricated them. For the wheel I needed a disk with alternate black and white stripes printed onto it. I designed the pattern, using Inkscape and printed it on a laser printer. I cut out the design and glued it to the wheel. I mounted the encoder so that the IR sensor was shining onto the striped pattern. I cut slotted holes to mount the encoder to allow for adjustment. The pictures below show the encoder mounted on the robot.
This set-up gives around 40 pulses per revolution of the wheel. I have connected the signal from the encoders to an external interrupt on the Arduino and set it up so that an interrupt occurs on a change of state. This means the count is incremented every time the encoders sees a change from black to white or vice versa.
I am happy with these encoders. The resolution is not brilliant but is more than sufficient to keep the robot driving in a straight line. I have written a control loop for each wheel, just proportional control at the moment, to keep the wheels spinning at a constant speed.