Saturday, July 21, 2012

TOBL2: Frame Design Complete!

About two minutes ago I placed my first Big Blue Saw order. This included all* of the missing pieces for TOBL2's frame which will be water jet cut from 1/8" 6061 aluminum plate. I guess one benefit to making everything so absurdly small is that I save some money on these sort of orders. Before shipping it came out to $81.40, which I hear is about the minimum you can pay. I like how Big Blue Saw gives you a preview of what your parts will look like if they were flying through a dessert.

Keeping this guy compact took a lot of changing dimensions, looking at the part in assembly, and then fine-tuning the dimensions further. The motors are mounted to a plate which can pivot, so that eats up a lot of space. The electronics stack also grew a little with the addition of the motor controller board. Altogether though, I'm very pleased with the way it turned out. The center of mass is going to be pretty atrocious, but I'm not ready to start selling TOBLs just yet, so that's alright.

I did away with the three aluminum posts mounted at each corner, and added two shelves. The top one is for the electronics stack (shown transparent) and the bottom one will hold the battery pack (ditto). PCBs should never be structural components, as I'm learning so well at work this summer. In this case, I had to be very creative, since the axles are now live and attaching posts to them won't work anymore. I prefer the old bulky aluminum posts mechanically, but I ordered an extra electronics shelf beam, so I can always put that above the servos if this doesn't cut it. As you can see, I had a little fun with the battery shelf.

Sexy battery tray

A lot of what took so long designing this frame was also anticipating what's going to go wrong. Having a drivetrain with triangular geometery, belts, springs, and moving motors, is really just asking for it - in terms of alignment issues. In an attempt to resolve all this, I put some redundant holes in to allow a little tuning upon assembly. For example, all those holes in the motor bracket are to adjust the spring tension (not easy to see in the picture below).

The drawing geometry and dimensions for these plates are disgustingly complex

 See what I mean? Gross

I also ordered some bearings on eBay, which had no picture, so that's always good. They were a dollar a piece though, so if they're the wrong size then I'm sure I'll create some crazy thing which will need them down the road. The asterisk in the second sentence is because as hard as I tried to make this the entire frame from the water jet order, I'm going to need to machine a few thicker (1/4") blocks at the interfaces of the plates and shelves. These are really straight forward, so hopefully the machinist where I work will be kind enough to let me knock those out some time.

Also, just bought a road that may have something to do with why TOBL had been moving so slowly recently...

Sunday, July 8, 2012

TOBL: Timers and PWM

Due to shear stubbornness I only brought one suitcase to Colorado. This means no soldering iron or useful tools. All I can do is SolidWorks and software. However, I've been doing a lot of CAD lately so I changed gears and took some time digging deeper into the inner workings of PWM signals. This is what I found:

Hardware, or timer-generated, PWM on AVR chips can be broken into two main categories. There is fast PWM and phase correct PWM. In fast PWM mode, the timer counts up from 0-255 (on 8-bit timers) and toggles the output once the compare register, OCRnx value, is reached. The output starts HIGH and switches LOW when this value is reached, meaning the higher the OCRnx value, the higher the duty cycle or time that the output is held HIGH. The graphs below represent the input sawtooth wave with two compare registers (most timers have two), an output PWM signal running 30% duty cycle, and one at 70% duty cycle, respectively.  
I wrote a MATLAB program to generate these waveforms; it will become more apparent why when explaining phase correct PWM.  
There is however a problem with fast PWM, for certain applications. The PWM signals above emulate the two outputs from a single timer. As can be seen above, the pulses start at the same time but at different duty cycles they do not stop synchronously. This is alright for controlling a single motor or dimming an LED, but for a pair of motors, this introduces error. Say for example there were a drivetrain with two motors, one left and one right (hmm kind of like TOBL). If TOBL were to steer left by running at 50% duty cycle on the left side and 100% on the right for x time, and repeat the other way around for the same amount of time, it would not end up at exactly it's original heading. In TOBL's case, with such a wide track and short wheelbase, this error is amplified. 

Ah hah! There is a solution to this issue called phase correct PWM. In this mode the timer counts from bottom to top and then top down to bottom again, toggling from HIGH to LOW crossing of the compare value on the way up, and from LOW to HIGH on the way down. This process looks like this:
There are a couple differences in these waveforms, starting with the triangle wave input. Because the timer has to count up and down the period of each duty cycle is doubled, or the frequency is halved, making it clear why fast PWM is named as such. You might also notice that now neither of the pulse edges align. However, more importantly, the pulses are centered around the top value. Returning to the two-motor vehicle example,  now using phase correct PWM, if the signal instruction were suddenly stopped, both motors would stop the same percentage of the way into their duty cycle. While this doesn't entirely eliminate the error, it is a lot better than fast PWM.  

On most timers fast PWM is the default and to change it you need to reset the timer/counter control register value to make the switch to phase correct. For the Arduino, which TOBL is based off, this looks like this:

TCCR2A = _BV(WGM20);

...for timer2. Of course there is a lot of other cool stuff to control at this level, so while doing this it may also be of interest to fiddle with the other registers. Setting the two outputs of the timer to non-inverting, the waveform mode to phase correct, and the prescale value to 256 would be this:

TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS22);

The prescale value is useful because it adjusts the PWM frequency (for fast 8-bit, clock speed/prescale/255 = PWM frequency). So, while I may have cut the frequency in half by selecting phase correct mode, I can do the same to the prescale value to maintain the same PWM frequency. This is less important for motor control and more important for things like servos, which usually run at about 30-50Hz.

Anyways, the point of this tangent is that PWM can be a lot more complex than analogWrite(), and can be easily modified for any application. TOBL2 software now implements phase correct PWM, though I can't do much with it until I get a rolling chassis. If you're interested in the m.file that generated the graphs above, you can get it here. It's fun to play around with and see what's going on under the hood.

Tuesday, July 3, 2012

Blog Web Address Change: You Can't Ride a Fountain

I've changed the URL of my blog from to When I started the blog a couple years ago I had a few naming ideas that didn't work out, but I wanted to start blogging so I just used "my initials - tech" as a placeholder until something more meaningful came along.

A little bit of history: Shane got me into Team 97 out of Cambridge, MA. We went to Nationals in Atlanta that year but when the competition was over we couldn't stop thinking of other things to build. At this point, the Edgerton Center Summer Engineering Workshop (I think that's the official title) was born. Our first project being this home-brewed segway.

In the process of selecting a project, Ed of the Edgerton Center had some ideas of his own. One which he was particularly adamant about was a fountain like one we saw in Atlanta. He wanted to equip it with sensors so you could run through and either not get wet at all, or get completely drenched. My response to which was "you can't ride a fountain." This went from an inside joke among the ECSEW team and developed into a personal philosophy. I see little point in creating things that don't move (sorry ardWINDo and gMeter) and you'll notice that DIY Segway, CapKart, BWD Scooter, and TinyKart are all things you can ride.

And so, about two years late, I give you: You Can't Ride a Fountain, a blog dedicated to building things that can be ridden and/or move.