Shop OBEX P1 Docs P2 Docs Learn Events
Quadrature Encoders for the ActivityBot — Parallax Forums

Quadrature Encoders for the ActivityBot

Duane DegnDuane Degn Posts: 10,588
edited 2013-12-07 22:06 in Robotics
I'm converting at least one of my BOE-Bots into an ActivityBot. I purchased the new high speed servos before the ActivityBot had been announced.

I now have a couple sets of the ActivityBot wheels. I just couldn't bring myself to pay $38 for a set of encoders to go with the new wheels. Especially since erco had just sent me some of his P5587 optical encoders.

I also wanted to my encoders to be quadrature encoders so there wouldn't be any uncertainty about encoder tics at low speeds (or stopped).

So here's my first (public) attempt at making a PCB for these encoders.

attachment.php?attachmentid=104912&d=1384242713

Above it the front of the PCB and below is the back of the PCB (mirrored image).

attachment.php?attachmentid=104910&d=1384242710

The two sensors are mounted so there is one and one fourth of a encoder cycle between them.
I drew some circles in DipTrace to add in the layout.

attachment.php?attachmentid=104911&d=1384242712

The largest circle is the size of the wheel with the tire. The blue dots indicate the openings in the wheel. There are 32 encoder cycles per rotation of the wheel. 360 degrees/32 encoder cycles = 11.25 degrees per encoder cycle. Since I wanted the two sensors to be 1.25 encoder cycles apart this meant I wanted the two sensors separated by 14.0625 degrees. (11.25 * 1.25 = 14.0625 degrees) To give the board a symmetrical look, I rotated each sensor half of the 14.0625 degree (7.03125 or 7.0 is close enough).

The square in the above diagram represents the position of the servo. So this PCB should be able to be mounted above the servo. The PCB will need some sort of mounting board similar to Parallax's encoders.

These PCBs are pretty small so they shouldn't cost much from OSH Park but I think I'll probably try a couple of other variations. I'm not sure if I really need the mounting holes since these could be attached to a mounting board with double sided foam tape.

I'm hoping for feedback on this current design. Any errors you can see?

Here's a schematic from the sensor thread.

attachment.php?attachmentid=103447&d=1376971510

Any suggestions for improving the design?

I'd particularly like to hear from any of you using an ActivityBot. Do you see anything that would make these sensors easier to use? I'm wondering if the header for the four pin connector should positioned on the side instead of the top. If I move the header to the side I may need to make a left and a right version. I think it would be possible to make a reversible board but I'm not sure if it would be worth the hassle to design one (I'd use the pads of the passives as solder jumpers).

I'll probably post a couple other designs before submitting any to OSH Park.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-12 01:16
    Here's another board.

    attachment.php?attachmentid=104913&d=1384247509

    If I use this one I think I either need to make a mirror image to use on the other side of the bot or I should add a second set of headers to the left side of the board.

    I do wonder if I should include some sort of mounting holes.
  • ercoerco Posts: 20,256
    edited 2013-11-12 07:11
    Beautimous as always, Pal! I would def add at least one mounting hole to the second one. Four is overkill. Nice board designs!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-11-12 08:57
    Duane Degn wrote:
    I'm hoping for feedback on this current design. Any errors you can see?
    The sensors currently used with the ActivityBot and BOE-Bot are modulated, which prevents interference from external sources, such a fluorescent lighting. During the encoder's early development some eight years ago, this was found to be very important, since the sensors face outwards and can "see" ambient lighting through the holes in the wheels. Most non-modulated sensors are designed to be housed inside of equipment, such as printers, for detecting paper edges and the like. They may not adapt well to external applications.

    -Phil
  • ercoerco Posts: 20,256
    edited 2013-11-12 09:21
    @PhiPi: Agreed. That's one peril of using a reflective (one-sided) optical sensor on a disk with holes in it: you never know what the lighting may be on the other side of the holes. I prefer a nice solid encoder disk with printed b/w stripes, which works quite well with the tiny P5587 sensor Duane is using here. Mounting printed disks to the wheels is always a viable option, and much finer resolution could be obtained.

    Will it pain insane Duane Degn's brain to obtain or refrain?

    @Duane: You could use 90-degree headers on those boards to make mounting easier.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-11-12 12:00
    I don't use open faced wheels like the Activity bot's with a simple encoder, so I find shielding the encoder really helps eliminate ambient noise. My favorite shield is a drinking straw covered with black heat shrink tubing.

    @Duane, nice looking PCB!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-12 12:19
    erco wrote: »
    . . . I would def add at least one mounting hole to the second one. . . .

    Thanks erco. I added two mounting holes to my latest version.
    The sensors currently used with the ActivityBot and BOE-Bot are modulated, which prevents interference from external sources, . .

    I had wondered about that. Thanks for the info.
    erco wrote: »
    Mounting printed disks to the wheels is always a viable option, and much finer resolution could be obtained.

    I'm not sure if a finer pitched encoder would work well this this design. The second encoder wouldn't necessarily be 90 degree out of phase with the first. I suppose as long as the encoders weren't exactly in phase or 180 degrees out of phase, the Propeller should be able to catch individual transitions.
    erco wrote: »
    Will it pain insane Duane Degn's brain to obtain or refrain?

    You forgot to mention my "broken candy cane" which always seemed to end up in the rhymes my little sisters and their friends would come up with. For those who may not know, "Degn" has been Americanized to "Dane" when pronounced. Who would name their child with rhyming first and last names which also started with the same letter? (No, this doesn't really bother me. All the teasing I've ever had (about my name) has been good natured.)
    erco wrote: »
    @Duane: You could use 90-degree headers on those boards to make mounting easier.

    Yes, this is the plan.

    Here's the latest version.

    attachment.php?attachmentid=104928&d=1384285858

    With lines showing the wheel size.

    attachment.php?attachmentid=104929&d=1384285859

    I'm figure ons set of holes could be used for the right side and the other set of holes for the left side.

    It did cross my mind to move the sensors a father apart. I know now that external light can cause a problem but I'm also worried about light from one sensor interfering with the other.

    I think I'll send this one off to OSH Park and see how well it works (I'll wait for additional feedback for a few hours first).

    @erco, your PM inbox is full again.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-12 14:13
    I think this one if my favorite so far.

    attachment.php?attachmentid=104932&d=1384293960

    Here's the bottom of the board.

    attachment.php?attachmentid=104933&d=1384293961

    It's ambidextrous, has mounting holes and is small. Small boards are inexpensive through OSH Park so I think I'll give this one a try (didn't I just say that about another board?).

    One thing that concerns me about this board is I used 5V copper pour on the top layer. I was hoping to compensate for having the bypass caps a bit further away from the Vdd pin than I'd normally l like.

    Do any of you see a problem with having a 5V copper pour on the top of the board and a ground pour on the bottom?

    Again, I'll wait a bit for feedback before submitting this version (or so I claim).
  • W9GFOW9GFO Posts: 4,010
    edited 2013-11-12 17:06
    The resistor at the upper left is not aligned with the header, needs to move down and to the left.

    I would also flip the caps around so that the vias were inboard, then the placement of the caps and resistors could be symmetrical both vertically and horizontally.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-12 19:19
    W9GFO wrote: »
    The resistor at the upper left is not aligned with the header, needs to move down and to the left.

    When I placed the resistors on the board shown in post #1 I made sure the x and y coordinates matched up on either side of the board. I started getting lazier with my subsequent boards. Thanks for pointing out the lack of symmetry, I'll fix it.
    W9GFO wrote: »
    I would also flip the caps around so that the vias were inboard, then the placement of the caps and resistors could be symmetrical both vertically and horizontally.

    I was attempting to keep the anode of the capacitor as close to Vdd as practical. Vdd is the top left pin of the sensor. I think the 5V copper pour on the top and the ground pour on the bottom will add some capacitance to the board so the placement of the bypass caps isn't as critical. I like you ideas on how to improve the look of the board. I'll make these changes too.

    Something about the trace on the bottom of the board to the A channel output bothers me. I'm thinking of adding a bend in the trace to move it away from the 5V hole.

    Thanks for the suggestions. Please let me know if you see any other ways to improve the board.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-12 22:21
    Here's the board with the changes Rich suggested. I think it looks better this way.

    attachment.php?attachmentid=104968&d=1384321633

    I moved the A output trace on the bottom of the board.

    attachment.php?attachmentid=104969&d=1384321634

    I'm curious about adding an encoder to the inside of a servo. I added a single sensor earlier.

    attachment.php?attachmentid=103791&d=1378587798

    I was tempted to try to add a second encoder so I could have quadrature readout but I didn't think I'd be able to align the encoders well enough by just using Polymorph to hold them in place.

    Since OSH Park's PCBs are so inexpensive when the PCBs are small, I decided to try making a small two sensor board to fit up inside of a servo.

    Here's what I came up with.

    attachment.php?attachmentid=104970&d=1384321699

    A four pin header is actually pretty big compared to the size of this board so I decided I'll just solder wires directly to some of the pins and have the connector at the end of a four wire pigtail.

    In order to keep the board as small as possible, I placed the caps and resistors on the bottom of the board.

    attachment.php?attachmentid=104971&d=1384321700

    While the top of the board should be symmetrical, I didn't attempt to position the capacitors and resistors to make the bottom of the board also symmetrical. The board outline should be symmetrical. I think I'm starting to feel comfortable designing boards with curved outlines.

    I tried to think of encoder angles to produce the desired 90 degrees phase difference between the two encoders. The best I could come up with was to use two black stripes (as seen in the photo) and place the second sensor 45 degrees from the first sensor. The two sensors are rotated 22.5 degrees (in opposite directions) from vertical in the above design.

    I need the sensors to be either 1/4 of a cycle from each other or a multiple of a full cycle plus a quarter cycle in order to achieve the desired quadrature output. I'm not sure what other combinations of stripes and encoder placement which would work in the limited space available inside the servo. If anyone knows of some other combination let me know and I might make another board.

    Thanks for the input so far. Let me know if any of you have suggestions for further improvements.
  • ercoerco Posts: 20,256
    edited 2013-11-13 18:33
    This guy 3D printed his own wheels with spiral spokes. A pretty cool effect to watch as the bot rolls around, and it got me thinking. It's a through hole wheel, too. Some kind of encoder layout could track this wheel, too. If you had a black wheel and you painted just a few curved spokes silver or white for reflectivity, you could track them with an array of sensors mounted radially, and they could work like an absolute encoder, instead of the incremental encoders we're all using.

    I have no time for this madness, but I'm just planting a seed. Given proper time, it will completely consume Duane and become the single-focused object of his fixation. :)

    Jump to 25 seconds: http://www.youtube.com/watch?v=QNRPiBzxZ0Q#t=25
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-07 09:34
    I've received the PCBs back from OSH Park a while ago. I wasn't very careful with the first board I populated and let out the magic smoke of one of the IR LEDs.

    I was more careful with these and they appear to work but I haven't tested them with the ActivityBot wheels or gears yet.

    attachment.php?attachmentid=105437&d=1386432534

    You can see in this next photo how the two sensors are one and one fourth cycles from each other. I didn't hold the sensor in exact alignment by you can see how the two sensors are the desired 90 degrees out of phase.

    attachment.php?attachmentid=105440&d=1386432540

    I also populated an "in servo" sensor. These are pretty dang small.

    attachment.php?attachmentid=105435&d=1386432531

    The P5587's leads are thicker near the sensor so the sensor is held above the PCB. You can see this gap in this next photo.

    attachment.php?attachmentid=105436&d=1386432532

    Initially I didn't like the gap and would have prefered the sensor sit securely against the PCB. I latter decided the gap is probably a good thing after all since it allows the sensor to closer to the encoder disk while allowing the PCB to be spaced at a more comfortable distance from the disk.

    This works out to be an advantage with the one to be mounted inside a servo.

    attachment.php?attachmentid=105438&d=1386432536

    The vertical placement of the sensors is easier to see in this next photo.

    attachment.php?attachmentid=105439&d=1386432538

    The in servo PCB holds the sensors at a 45 degree angle. As shown in an earlier post (#11), one encoder cycle of the servo gear is a 180 degree rotation of the gear. Since there are two cycles per rotation of the gear, the sensors needed to be offset by 45 degrees in order to have them 90 out of phase of the encoder cycle.

    That's it for now. Hopefully I'll have time to do some real tests with these sensors today.

    @erco, Yes those spiral wheels are cool. I hope to make some out of Polymorph sometime. I believe your seeds of madness have sprouted in my brain and will soon join the rest of the garden (weed patch?) you've planted there.
    623 x 565 - 99K
    505 x 556 - 98K
    728 x 496 - 120K
    550 x 477 - 144K
    655 x 532 - 140K
    509 x 413 - 105K
  • kwinnkwinn Posts: 8,697
    edited 2013-12-07 11:53
    Nice boards Duane. If you wanted to make them even smaller you might be able to do so by moving the sensors further apart and putting a single mounting hole between them.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-07 12:22
    kwinn wrote: »
    Nice boards Duane. If you wanted to make them even smaller you might be able to do so by moving the sensors further apart and putting a single mounting hole between them.

    Thanks kwinn. I like how the boards look too. It sure is fun to layout a board in DipTrace and have these nice looking boards show up two weeks later.

    I like you single mountng hole idea. I haven't mounted these encoders to an ActivityBot yet, but I'm pretty sure I'm going to want to change the design. The header area of the PCB comes too close to the wheel. The board will require some sort of backing board to hold in its proper position. I'd rather the encoder be able to be mounted with just a standoff and a screw if possible.

    I think if you use your single hole idea, I could use one of the slots on the side of the ActivityBot to mount the encoder.

    I used some PolyMorph to secure the small encoder board up inside a servo with poor first results. I mounted the sensor too close to the brass gear. There wasn't enough room for the IR light to bounce back to the sensor. If I move the gear about half a millimeter away sensor the sensor could pickup the encoder pattern.

    My current plan it to reheat the PolyMorph and move the sensor back down inside the servo a bit.

    I'm anxious to get to the software part of this project. I have some encoder software I'm using with other project which should work well here with some minor tweaks.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-07 16:24
    I've got the encoder inside the servo working. I'm getting 378 transition per rotation. I was kind of expecting more. I should really count the teeth on the gears and compute the gear ratio so I can know the exact figure.

    The ActivityBot quadrature encoders should provide 128 transitions per rotation so the internal encoders have about three times the resolution of using encoders on the ActivityBot wheel.

    Hopefully I'll have something interesting to show soon.
  • ercoerco Posts: 20,256
    edited 2013-12-07 20:58
    Duane Degn wrote: »
    Hopefully I'll have something interesting to show soon.

    I utter that phrase at work more often than I should....



    Great work as usual, Bossman Duane!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-12-07 22:06
    erco wrote: »
    I utter that phrase at work more often than I should....

    I use the phrase or something similar too often here.
    erco wrote: »
    Great work as usual, Bossman Duane!

    Thanks.

    So I've got the encoder counting pulses from the gear just fine but a servo rotating at a known speed looks a lot like a servo rotating at some random speed.

    I need to make a second servo so I can upgrade my cheap bot.

    I counted the gear teeth (not as much fun as it sounds) and the gear with the two dark stripes (8 transitions on a quadrature encoder) has 8 teeth near the center. I didn't count the outside teeth to the gear since the number wouldn't be included in the calculation. The next gear in line had 37 (usually) teeth on the outside edge and 9 teeth in the center. The next gear has 36 (usually) and 16 teeth. The final gear has 41 teeth (all three times counted). After doing the math I come up with 379.25 transitions per revolution.

    I also rotated the servo by hand ten times and the encoder count came out to be 3,794. The initial and final servo positions didn't exactly line up but if they had I bet there would have been 3,792 (or 3,793) transitions counted. I'm pretty confident value of 379.25 transitions per rotation.

    Now to use this number so I can stop the servo in any position I desire. I feel like I've got a pretty good algorithm to control the speed of the servo with PID (really just P & I). I think getting the servo to stop where desired may be a bit trickier. I'm not sure how big a factor backlash will be.

    Hopefully I'll be able to control the position of the servo to about one degree precision.

    I also want to get the ActivityBot encoders mounted. I'm hoping to add my 16 pixel rings to to the wheels. The LEDs aren't directly related to the encoders. I just want to add them at the same time as the encoders.

    attachment.php?attachmentid=105343&d=1385974999

    If these look familiar, it's because they pretty much a copy of AdaFruit's ring. My ring it just little smaller.

    I'm not really sure how well my power and data transmission rings will work.

    attachment.php?attachmentid=111671&d=1414471148

    I didn't think to take a picture of the transfer rings. An US quarter placed in the center of the rings covers up the inside ring and half of the middle ring.

    I've got a couple ideas for brushes to use with the rings but I'm not sure if any of my ideas will work. I'm not shy about showing video of my failures so hopefully my attempts at power and data transfer to a moving wheel will at least provide some laughs.

    Well, this isn't exactly what I'd call "interesting" but tomorrow is still soon right?

    Those darn maddening seeds you keep flinging around won't leave my compost rich brain alone.
Sign In or Register to comment.