Quadrature Encoders for the ActivityBot
Duane Degn
Posts: 10,588
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.
Above it the front of the PCB and below is the back of the PCB (mirrored image).
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.
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.
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.
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.
Above it the front of the PCB and below is the back of the PCB (mirrored image).
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.
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.
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
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.
-Phil
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.
@Duane, nice looking PCB!
Thanks erco. I added two mounting holes to my latest version.
I had wondered about that. Thanks for the info.
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.
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.)
Yes, this is the plan.
Here's the latest version.
With lines showing the wheel size.
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.
Here's the bottom of the board.
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).
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.
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.
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.
I moved the A output trace on the bottom of the board.
I'm curious about adding an encoder to the inside of a servo. I added a single sensor earlier.
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.
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.
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.
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
I was more careful with these and they appear to work but I haven't tested them with the ActivityBot wheels or gears yet.
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.
I also populated an "in servo" sensor. These are pretty dang small.
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.
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.
The vertical placement of the sensors is easier to see in this next photo.
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.
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.
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.
I utter that phrase at work more often than I should....
Great work as usual, Bossman Duane!
I use the phrase or something similar too often here.
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.
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.
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.