July 13, 2014

An Assembly Language Delay Routine for ARM Microcontrollers

I'm in the midst of writing some code to initialize an LCD screen. The initialization requires me to send a command, then wait for at least 50 milliseconds, then send more commands.

If you're using an Arduino, this is easy: you call the delay() function. If you're graduating from the Arduino to a more 'bare metal' development environment, you may find yourself looking for this function that doesn't exist on your platform.

Furthermore, if you do a Google search for delay routines on an ARM microcontroller, the near universal reply is, "you should use a hardware timer for that!" (more…)

June 6, 2014

AVC Boards have arrived!

I had given up all hope of receiving my AVC circuit boards and had convinced myself that they had become forever lost in the mail. And wouldn't you know, today they show up. Ten circuit boards when I only need one. (more…)

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 22, 2014

Udacity Course Review: Artificial Intelligence for Robotics

A couple of months ago, while doing research for the Sparkfun AVC, I posed to the DIYRovers Google Group a question about the Kalman filter. I had discovered through reading that the Kalman filter is a popular algorithm in robotics and the more I read the more it seemed that the Kalman filter is the answer to just about any robotics problem out there. Unfortunately, I was unable to find any good learning resources for this algorithm that didn't require an undergraduate degree in mathematics.

One of the members of the group suggested that a good resource for learning the Kalman filter is the Udacity course "Artificial Intelligence for Robotics."

Udacity, for those who don't know, is a MOOC: A Massively Open Online Courseware site. Udacity hosts online classes that anyone can take free of charge. Udacity is a for-profit educational organization founded by Sebastian Thrun, David Stavens, and Mike Sokolsky. It is the outgrowth of free computer science classes offered in 2011 through Stanford University, where Sebastian is a professor. I'll talk about the for-profit part in a few paragraphs.

So, at the encouragement of another AVC'er, I started taking the course.

The course wasn't at all what I expected. The primary focus of the course is how to deal with uncertainty in robotics applications. For instance, a sensor might be noisy, or a command to move the robot might be affected by wheel slip. The entire course is an introduction to various methods and algorithms (including the Kalman filter) that can be used to deal with this type of uncertainty.

The course starts off with simple one-dimensional examples and considers noise and probability. That is, in the presence of noisy sensors and noisy movement commands, the robot cannot have absolute knowledge of its position. Instead, the course teaches how to track the probability of the robot being in any particular location, and the reliability of any probabilistic guess as to the robot's position.

The course advances into more complex algorithms and into two-dimensional examples. Bayes' Theorem is introduced and conditional probabilities are used. The course proceeds on to the Kalman filter, particle filters, the A* and other search algorithms, PID control, and SLAM algorithms.

The course is taught by Sebastian Thrun. Sebastian is a professor at Stanford, and was a member of the DARPA Grand Challenge  winning team and a member of Google's self-driving car research team. Clearly, the guy has experience in robotics to be teaching this course. In fact, Sebastian uses his experiences with these projects to bring real-world examples to his lectures. This brings home the point that these algorithms are practical and applicable to real-world problems.

The course material proceeds logically and builds in sequential steps. Lessons are broken into short videos, typically 2-6 minutes, followed by a quiz, which is typically a Python programming exercise or a multiple choice question. In most cases, a skeleton Python program is given and the student must write a function to implement the concept just explained in the lecture. I found that the exercises complement the lectures quite well. Sebastian is an outstanding instructor, and the material was paced perfectly for me. The Python programming is done in an in-browser editor and is graded by an autograder in the course engine. Feedback on the exercises is immediate.

I found very few downsides with this class. I was a little disappointed that the Kalman filter wasn't discussed in as much depth as I would have liked. Also, the subtitles on many of the videos are very poor; whoever created the subtitles clearly was not familiar with the material. That combined with Sebastian's German accent make for some truly interesting subtitles.

Be warned that this is not an introductory course! This is the exact same course that Georgia Tech uses in its Online Master of Science in Computer Science program, and I assure you that this course really is graduate level coursework. You'll need to have a semester or two of college level statistics, exposure to linear algebra, and decent programming skills to complete this course. Having said that, it's been over 20 years since I've taken linear algebra and I did just fine.

You can take the course for free, or you can pay $150 a month to get a "certificate" for passing the course. The material is the same in both cases. The difference is that with the paid course you have access to "coaches" and are required to do a final project. As luck would have it, my employer amended our tuition reimbursement program as I was halfway through doing this course for free, which allowed me to get reimbursed for taking the paid version of the course. That was a no-brainer and I immediately signed up for the paid version of the course.

Before my first payment was due, my assigned coach scheduled a Google Hangouts videoconference to ensure that I had the necessary academic background to be successful in the course.

The entire coaching staff is available to answer questions via instant messaging or email. They respond to instant messages immediately in my experience.

The coaching staff was, in a word, fantastic. I was (and still am) simply blown away by these guys. The coaches not only understand the course material, they understand it well, and they understand the broader context of the course material as it applies to real world problems. I kind of think of the coaches as the Teaching Assistants that I had in some of my undergraduate courses at university. I can say that if the TA's in my undergrad career had been as amazing as the Udacity coaches, college would have been a much different experience for me. I cannot say enough good things about the Udacity coaching staff. I don't know where they find these people, or how much they're paid, but they are far and away the best asset for this course.

For example, when I contacted the coaches about a question I had on one of the exercises for the Final Project, the coach looked at my code and quickly observed that my code ran in n^2 time, when, with a little modification it could be made to run in linear n time. I did know this about my code before asking for help, but I was impressed that the coach pointed this out to me so quickly. And that observation had nothing to do with the question for which I was contacting the coaches for help!

It is not necessary to complete all of the lectures or exercises to 'pass' the course and get a certificate. Only completing the final project is required. The final project includes writing some code and writing a short narrative explaining certain features of your code and why you made certain design decisions. The first time I submitted my project it was kicked back to me because I had made some arbitrary decisions without explaining my reasoning in the code comments. The graders are thorough!

In summary, this course was an outstanding experience for me. I probably wouldn't have paid for this course if my employer didn't offer reimbursement, but knowing now what I know about the experience, it would totally have been worth it to pay this out of my own pocket.

Highly recommended.

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…)

April 7, 2014

Unholy Combinations

I just feel so.... dirty running Python on Windows. Like I'm going against God's Natural Law or something.

OK, I feel better now that I have that off my chest. Back to work.

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 23, 2014

Using the FAT filesystem on SD cards with the STM32F4 Processor: Part II

In part I of this tutorial, we created a project for our STM32F4DISCOVERY board that read and wrote sectors to an SD card. In today's installment, we'll add a filesystem on top of that. (more…)