June 1, 2014

AVC Proof-of-Concept (sorta) Post

The AVC Proof of Concept deadline is today. (Or maybe it was yesterday.) This is my lame attempt at desperately hoping to still qualify for the contest.

You see, the circuit boards that I ordered from Dirty Boards on the 3rd of May still haven't arrived. Without circuit boards in hand, I really don't have much to show for my AVC entry.

On the off chance that the AVC staff will take mercy on me and allow me to remain in the contestant pool, my robot consists of:

Yeah, without pics, I realize the credibility in this post is near zero. But that's all I have right now- words and ideas. I'm well aware that the chances of me being ready in time are pretty slim, but I'm hoping the decision on whether or not to drop out can be my decision and not the decision of the AVC staff.

So I'll send them a link to this post and see what they say...

May 14, 2014

AVC Boards Have Been Ordered!

Well, it's been a while since I posted anything. I've been very heads-down with various priorities and this is the first opportunity I've had to come up and take a breath. I've just shed a few obligations so I'm hoping I'll be able to post more frequently.

I haven't abandoned my AVC project! In fact, I spent several weeks tweaking the schematic and then several more tweaking the PCB design. The inescapable fact of all this is that I just plain suck at PCB design. (more…)

March 18, 2014

AVC Parts Ordered!

I submitted my order to Mouser today. While that's on its way here I'll lay out my circuit board. When the order gets here, I'll verify footprints and then send off my gerber files to have a custom PCB made.

The June contest date is approaching way too fast! I don't even have my hardware done yet, so I can't do a whole lot of software development. Argh!

March 2, 2014

The Woes of Debugging DMA on the STM32 Platform

I spent a good chunk of today getting frustrated with my AVC code. I have custom firmware on my GPS so that it sends a fixed-length binary sentence to my microcontroller. Rather than polling the USART, or handing an interrupt every time a character comes in, I figured this is a perfect application for the DMA controller... tell the DMA controller how many characters there are, and have it wake up my code when I receive a full GPS sentence.

Well, during debugging, I found that my DMA IRQ was being handled once, but I couldn't get it to trigger a second time. After wrestling with this for hours, I finally thought, what if the second DMA interrupt really is happening, but because I've got the CPU stopped at a breakpoint, I'm missing it?

So, I took out my breakpoint and instead threw a character out the USART every time the DMA IRA was called. And lo and behold, I got a DMA IRQ five times a second, which is just how often the GPS is sending me data.

Embedded programming can be so frustrating.

February 27, 2014

AVC Replacement Parts Finally Arrived!

Despite selecting 'air mail' at checkout, Hobby King apparently found the absolute slowest shipping method to get replacement parts for my R/C car to me.

Well, I finally got them and I replaced the front right "C" bracket and took the car for a test drive today. I've never owned a hobbyist-grade R/C car before so some things seemed a bit weird to me. First, the car would go much faster in reverse than it would going forward. I solved this by swapping 2 of the 3 leads to the brushless motor (thus reversing the motor's direction), and inverting the throttle signal on my transmitter. I'm not sure if that's the right solution or not, but it worked.

The other thing is that the car seems to have no problem going from reverse to forward, but it insists on pausing when going from forward to reverse. I have no idea if that's normal or not. At least the car works.

In any case, I now have a platform for my AVC robot. I'm still cleaning up code to interface with my GPS module, and I'm writing a separate subsystem to drive some LED indicators to tell me the internal state of the software. I don't know how useful that will be in the final product, but at the moment, it seems like it's going to be useful for debugging.

I'm almost finished with parts selection. I'm going to have a GPS receiver and at least one 9DOF IMU chip on my vehicle. I'm still debating whether or not to include odometry sensors, IR distance sensors, and/or ultrasonic ranging sensors.

I've started designing the schematic for my controller board in Eagle.

February 9, 2014

USART woes on the STM32F4DISCOVERY board

Now that I have the ability to use a FAT filesystem on an SD card (post to come shortly), my next task was to write some code to allow me to send debug spew to a serial port. My plan is to use an Adafruit Bluefruit EZ-Link bluetooth link to send debug data to my laptop computer while debugging my AVC code. So yesterday I sat down to bang out the code. I mean, how hard can it be, right? Configure a USART with the proper baud rate, parity, data and stop bits, and pump data into the TX register. Piece of cake, right?

In about a half hour I had some code built and running. But I was getting garbage on my laptop over the FT232 cable I was testing with. I figured maybe I'd miscalculated the baud rate, or the clock speed, or something, so I tried doubling the bitrate on the microcontroller. Same problem, so I tried halving the original bitrate. No good.

I whipped out my Saleae Logic logic analyzer and took a gander at what was happening on the wire. The data simply made no sense. The width of each bit was not only not what I calculated it should be, but successive bit times weren't even an integer multiple of each other! The bit time was all over the map.. some short, some long, and very, very few were what they were supposed to be. (more…)

February 6, 2014

FAT and SDIO on the STM32F4: Early Experiments

I've been trying to marry the FatFS filesystem driver with a modified version of ST's SDIO sample code in order to read/write a FAT filesystem on an SD card for logging on my AVC robot.

It's been a frustrating few days. I've had intermittent results and I'm not sure why. I think there's some uncertainty with the DMA completion interrupts in my current lash-up. Moving from ST's library to Lukasz Iwaszkiewicz's software helped. I don't know the differences between the two codebases. Clocking the SD card at 25MHz (I think that's the clock speed in use) at the end of 12" jumper wires surely isn't helping anything. I also think that stopping the debugger and relaunching my code without powering off the SD card may leave its internal state machine confused. All of this is just conjecture, though, based largely on my wholescale ignorance of how the SD interface and the code I'm using actually work.

Currently, I'm able to read a file from the SD card but I'm having problems writing a file. (I started my attempt at writing this morning and only had 45 minutes to work on it before I had to leave for work.)

First experiments with the STM32F4DISCOVERY and an SD card.

First experiments with the STM32F4DISCOVERY and an SD card.

I'm designing a circuit board for my robot's brain that will solve the long wire problem when it's built, but I'm still a ways out from sending that off to be fabbed.

The Saleae logic analyzer that's barely visible in the picture has been worth its purchase price many times over. Many thanks to Supermodel Wife who bought it as a Christmas present for me despite knowing absolutely nothing about what it was!

February 2, 2014

AVC Parts from Hobbyking and Adafruit Arrived

AVC Parts have Arrived!

I got a box from Adafruit and a box from Hobbyking over the past couple of days, which should be all the parts I need to start developing my autonomous vehicle.

First the Hobbyking stuff. Despite several horror stories that I've read, the box that I received was a sturdy box in undamaged condition. I opened the box to find the contents were equally well packed and contents were all in good shape.

The box that I got from Hobbyking.

The box that I got from Hobbyking.

A nicely packaged box, in fact!

A nicely packaged box, in fact!

Clockwise from the top, I have a model car, two battery chargers, a transmitter and receiver, and three batteries:

Contents of the box.

Contents of the box.

As I said, everything was well packed. Upon closer inspection however, the right front wheel appeared to have an extreme amount of camber. While examining the suspension system to try to figure out how to adjust this, I discovered that the wheel was rubbing against the suspension arm. It turns out that the front "C" bracket is broken. Man, there's nothing more frustrating than to get a new toy only to discover it's broken.

I noticed the wheel hub rubbing against the suspension.

I noticed the wheel hub rubbing against the suspension.

You can see the cracked plastic "C" bracket here. (Click for larger version.)

You can see the cracked plastic "C" bracket here. (Click for larger version.)

I sent a support email to HobbyKing and am waiting on their response. Unfortunately, Hobbyking appears to be an eastern hemisphere low-cost leader and their support reflects that. I've been waiting over four days for a response to my support ticket.

The broken part is a fifty cent replacement part, but I found that it's only stocked in Hobbyking's international warehouse, which means it could take weeks before I receive it. I went ahead and ordered a replacement, along with a bunch of other replacement parts, because I have no faith in Hobbyking's support.

However, that won't stop me from starting to develop my code. My first task is to get some kind of logging going on. I'm planning on grafting FatFs to the SDIO example in the Standard Peripheral Library, which seems to be very well documented in the comments. I have a SD card slot that I ordered from eBay. I hope to find time to wire it up and test it before the weekend is out.

I also finished code last night to get the microcontroller's TIM2 PWM outputs to generate servo signals on channels 1 and 2. I spent a LOT of time wondering why the timings that my Saleae logic analyzer was showing me weren't consistent with my calculations. I finally discovered that the HSE_VALUE in stm32f4xx_conf.h, which defines the crystal frequency, is set to 25MHz when the STM32F4DISCOVERY board is fitted with an 8MHz crystal. Changing the constant in that header file fixed the problem and ended several hours of banging my head against the wall. My code now outputs a 1ms to 2ms pulse every 20ms and does so using the features of the hardware timer, so once the value is set no code is required to maintain a constant signal.

I'm debating between using the STM32F4DISCOVERY board on my final vehicle, or laying out a custom board with the same processor on it and making something a lot smaller and tailored to the task. I'm leaning toward a custom board but I'm a little leery of soldering some small SMT parts on there. I can do SMT passives no problem, and leaded chip packages are manageable, but one of the parts I'm looking at using is a 4mm by 4mm LGA 24 package. That's some pretty tight pin spacing with no access to the pads once the part is on the board. If I go this route I plan on using the Sparkfun Reflow Skillet method.

January 26, 2014

AVC Parts Have Been Ordered, the Workshop Has a (Small) Workbench and Internet Access

While I continue to work on the workshop (progress is being made and an update will be posted soon), I went ahead and ordered parts for my 2014 Sparkfun AVC entry.

My robot is going to be built on a 1/16 Turnigy R/C car from Hobbyking.This platform has received a decent set of reviews from the R/C community and is hopefully going to be large enough to do what I need it to do.

In addition to the remote controlled car chassis, I ordered a three channel transmitter/receiver, some batteries and a battery charger. The three channels are going to be used for throttle, steering, and a selection between manual and autonomous control. In case my robot starts heading off a cliff or onto a six lane road under autonomous control, I'll be able to throw a switch on my transmitter and bring it back under manual control. For this I bought an R/C multiplexer from Michael Shimniok, a veteran AVC competitor who sells stuff on Tindie at very reasonable prices. I added a snarky comment when I placed my order that he and his robot had better watch out in the 2014 AVC because I was comin' for him, and he added a friendly note on the packing slip with my order and suggested that I join the DIYRovers Google Group where he and other AVC competitors discuss their designs. If all the other folks in the community are as friendly as he is, I like this crowd already!

I'm planning on using an ST32F4DISCOVERY board as the microcontroller for my robot brain, and I ordered a GPS and a 9DOF intertial sensor from Adafruit as my sensors. I have had success getting an Eclipse/GCC/OpenOCD development environment running for the STM32F4 under Ubuntu; keep an eye out for that blog post soon. Ultimately, I plan to create a custom circuit board with an STM32F4 controller and the sensors on one board, but that's going to be down the road a bit.

While I wait for my two orders to arrive I've been writing some code on the STM32F4. I've attempted to graft the FatFS embedded filesystem driver with ST's SDIO card sample code in the peripheral library. I haven't tested it yet on hardware, but I'm cautiously optimistic that I can develop a logging subsystem with relative ease by using these two libraries. The other code I've been working on is a library to drive the servos. I know that I have an earlier post in this blog claiming that I got servos running on the STM32F0DISCOVERY, but it seems that I may have reverted the virtual machine on which I developed that code to an earlier checkpoint, because I haven't been able to find those files anywhere. I believe I've rebuilt that code but I won't be sure, again, until I test with real hardware.

In the workshop, I bought a large U-shaped desk on Craigslist to be my new workbench. It's missing some fasteners, so I'm currently looking for some replacement parts. Until then, I did get one leg of the U assembled and I got Internet connectivity in the workshop today. That's enough amenities to begin hardware hacking out there. I need to dig out an oscilloscope and my Saleae Logic logic analyzer and I'll be able to make progress on my robot while I continue to clean up out there and get the parts needed to finish my workbench.

January 5, 2014

Sparkfun AVC Thoughts

Sparkfun has recently announced that the 2014 Autonomous Vehicle Contest (AVC) will be held on June 21, 2014.

The AVC, as its name implies, is a contest where contestants build vehicles that must navigate a course autonomously. That is, no input or guidance from a driver or pilot. I've been following the AVC for a couple of years now and have thought about entering before. This year I think I just might do it. The STM32F4DISCOVERY board appears to be a perfect platform to build upon for the contest. That board, a few sensors and a whole lot of code sounds like just the ticket.

There are two categories of competition: ground and air. I'm not yet ready to build a self-piloting drone. But a self-driving model car is probably a good stretch goal for me to build on my embedded skills. I've already starting writing a code library to write debug output to a serial port. I'm planning on picking up a BlueFruit bluetooth link from Adafruit to stream the debug spew back to my laptop. The F4 also features an embedded USB host port, so I'll write debugging info to a file on a USB thumb drive as well. With a high clock speed (180MHz), lots of Flash ROM (1MB) and RAM (192K), and plenty of I/O, it should be a generous platform on which to build.

I guess I should revisit my series on setting up a FOSS cross compiler toolchain and figure out how to configure it for the STM32F4 series.