Tuesday, December 3, 2013

R/C Car Quadrature Wheel Encoders

Earlier this year I developed some quadrature wheel encoders for my Traxxas Rustler 1/10 scale R/C car that I've been using for the SparkFun AVC. I've finally gotten around to writing it up.

Traxxas Rustler with 4 wheel encoders installed.

Before starting, I scoured the web for existing designs specific to R/C vehicles. I ended up going with something very similar to the "Custom Rear Wheel Encoders" at the bottom of this page describing the hardware for a 2010 Georgia Tech senior design project called P.A.C.M.A.N. This Bot-Thoughts post on wheel encoders was also very helpful and a source of inspiration.

I wanted to encode relative rotation (angle and direction) on all 4 wheels. Strictly speaking, 2 wheels would have been sufficient for odometry, but I wanted to have some redundancy and also deal with slip. The challenge with encoders for R/C cars is that there isn't much of an axle or shaft to grab on to, and so pretty much any off-the-shelf rotary encoder was out.

Optical encoders typically have 3-4 elements: an infrared LED, a rotating disc with slits or a reflective pattern, a light sensor, and maybe some electronics on the sensor. So-called reflective sensors integrate the LED and the sensor, making the job much easier. I did a survey of sensors and am listing them here for others' benefit.

ManufacturerPart NumberPricePackage
FairchildQRE1113GR$0.73SMT
HamamatsuP5587N/Aleaded
HoneywellHLC1395-001$2.21leaded
HoneywellHLC1395-002$2.14leaded
OmronEE-SY171$2.90leaded
OmronEE-SY199$2.16SMT
OmronEE-SY1200$2.42SMT
OsramSFH 9201$1.21SMT
OsramSFH 9202$1.26SMT
OsramSFH 9240$1.84SMT
VishayCNY70$1.18leaded
VishayTCND5000$2.61SMT
VishayTCNT2000$0.84SMT

Prices are from either Digi-Key or Mouser. The Hamamatsu and a couple of the Osram parts were either discontinued or being phased out.

The basic idea was to affix alternating black/white tracks on the inside surface of the wheel, and then mount a couple reflective sensors pointing at each track. The tracks are 90° out of phase and the sensors are in line with each other to make a quadrature encoder (allows sensing of both angle and direction). This is different from other designs I've seen which use a pinwheel-style circular disk. I picked 24 lines for my tracks, which in quadrature gives 96 ticks per revolution, which for my wheels is 3.4mm traveled per tick. Plenty of resolution! The tracks are printed on a laser printer and then cut out and carefully taped inside the wheel.

Wheel with encoder track taped inside.

On the electronics side of things, the reflective sensor needs a current limiting resistor in series with the LED current path and a pullup on the collector pin of the phototransistor. Also on-board is some signal conditioning to provide a sharp transition for the A and B channel outputs. Those outputs are put onto a 4-pin header with 3.3V and GND to go out to the CPU.

The first design I did, I used a surface-mount sensor (Vishay TCNT2000), a dual comparator (TI LMV393) with some hysteresis resistors, and a potentiometer to adjust the voltage output of the sensor. This ended up sort of working. I could see transitions when I put surfaces in front of the sensor, but I could never get it to work on the car due to the mounting not really being right. This design used a single track with the sensors mounted 1.25 "tick-pitches" apart, which probably would not have worked due to the poor accuracy of my pick-and-place (me).

First attempt at custom boards, using surface-mount sensors.

For the second design, I used a leaded sensor (Honeywell HLC1395-002) and a dual Schmitt trigger (TI SN74LVC2G17). I worked out the mounting more carefully prior to getting the boards made, and the leaded sensors allowed for some flexibility on their mounting height and alignment. Consequently, these boards worked great (two separate layouts, one for the front and one for the rear). The boards have 4 sensor footprints so that they can be used in left/right configurations.

Schematic for second set of boards (same for both layouts).

Second set of boards, for front (right) and rear (left) wheels.

The boards necessarily ride with the suspension and steering of the wheels. The bearing carriers fortunately have a good spot to screw down each board with a single fastener, such that it sticks out the appropriate amount into the wheel. The leaded sensors are bent back to be at the right distance from the black/white track. The initial setup is a bit touchy.

Mounting of front encoder board.
Mounting of rear encoder board with wheel.

The "connectors" are just standard 0.100" spacing 4x1 male pin headers. The cables to the CPU have the corresponding 4x1 female connector made from prototyping wires. They are tied off with lacing cord with enough service loop to allow for full travel of the suspension and steering.

Rear encoder cabling with tie-downs.

And that's about it. With the boards powered up and wheels spinning, the encoders output 2 square waves about 90° apart as expected.

Spinning wheel with scope trace of encoder channels.
I didn't actually put too many outdoor revs on these wheels, but I never had any problems with the hardware once they were mechanically dialed in. In a future post I'll detail how the 4 encoders were read with the PRU on a BeagleBone Black.

9 comments:

  1. Hi, can you please post how the encoders were read with the PRU? I plan to use an Arduino Uno and was hoping you could help. :)

    ReplyDelete
    Replies
    1. I know I'm late to the party, but there are great Arduino instructions with code examples. I used the interrupt example for reading the encoders:
      http://playground.arduino.cc/Main/RotaryEncoders

      Delete
    2. Also late to the party, I'm fond of reading quadrature encoders with a lookup table; there's an example in the code linked at the bottom of this post:
      http://www.blargh.co/2011/04/sparkfun-avc-2011.html

      I think it's among the more efficient ways to do it in software, which can be an issue with high-resolution encoders attached to motors. It's the way the PJRC library does it, nicely abstracted to use any interrupt-capable pins.
      http://www.pjrc.com/teensy/td_libs_Encoder.html

      Delete
  2. Hi,

    nice Project love it!
    Is it possible to share the layout files in Eagle or similar program? I would like to rebuilt. Or can you sell one set of boards? Thank you in advance.

    ReplyDelete
    Replies
    1. Hi Ralf, the boards are available through OSH Park. Here's a link to my profile there which has the boards: https://www.oshpark.com/profiles/jleichty

      Delete
  3. Hello,

    What is the value of the capacitor that you used?

    Thanks!

    Jad

    ReplyDelete
    Replies
    1. They were 0.1uF 0805 surface mount capacitors, specifically these: http://www.mouser.com/ProductDetail/Kemet/C0805C104K5RACTU/

      Not sure why that didn't make it into the schematic!

      Delete