Our resident expert on all things
robotic is merely an email away.
roboto@servomagazine.com
Tap into the sum of allhumanknowledge and get your questions answered here!
From software algorithms to material selection, Mr. Roboto strives to meet you
where you are — and what more would you expect from a complex service droid?
by
Dennis Clark
14 SERVO 11.2010
Christmas is coming and I have a list of robotic toys
to choose from again this year which included parts and
boards from SparkFun, motors from Pololu, motherboards,
and all kinds of other cool stuff. Many of you readers
know that I have been a fan of the ATmega line of
processors for small robots for a while now. I like the
Eclipse IDE, and the free and open source gcc compilers
and AVR libraries. Then, I discovered the Arduino
environment and that was very cool too. What many of
you don’t know is that I have been a PIC fan for many
years. Microchip has a huge number of parts and many
very good third-party compiler companies for C, Basic, and
whatever. I’ve gone over to the AVR line because those
parts are supported on my favorite Platform Mac OS X.
I have kept an old laptop hidden in the mad scientist’s lab
running Windows 2000 and my MPLAB setup to program
my PICs. Lately, I’ve been running MPLAB 8. 5 in Parallels
However, the world is about to change.
At their Masters Conference this August, Microchip
demonstrated their MPLAB X IDE. This IDE is based on the
Java NetBeans platform and is OS agnostic. Microchip is
busy porting their PIC compilers to this new platform and
they too will be OS agnostic. I’ve used the Beta release and
it is indeed sweet. It has many new upgrades and cool
things that they could not do with their older IDE.
However, the BEST thing about it is that their hardware
suite has had their drivers ported too. Holy PIC, Batman!
We’re about to be able to run a supported Microchip IDE
and program our PIC24FJ64GA006 with our ICD3 on Mac
OS X 10. 5, Linux, and Windows! For those of you that are
like me, this is the best news we’ve heard all year (which I
admit, doesn’t have much competition), but still, Microchip
has heard and responded. Rumor has it that the MPLAB X
will release in January 2011 and it will be free. My fingers
are crossed — I’m testing the Beta version now and I can’t
wait for the release!
Life is good.
Q. I’ve gotten tired of my old fashioned way of programming my robots using a big loop and oing things one at a time. I keep missing things
and messing up. I don’t want to have to buy a fancy
motherboard running Linux, or something even more
expensive to get multitasking. Someone said I don’t have
to do that. Can you tell me how to get multitasking on
a simple AVR ATMEGA128? That would be so cool,
Mr. Roboto!
— Robo Bob
A. Robo Bob, your sources are correct! You can indeed get a form of multitasking working on your favorite small processor. The magic is called “state machines”
which you may have seen written as FSM, or Finite State
Machine. This type of programming is the mainstay of the
embedded programming world. Every embedded
programmer needs this tool in their toolbox if they are
going to succeed. Indeed, every robot programmer needs
it too!
When you use what is called a real time operating
system (RTOS) such as Linux, uCOS, VX Works, or the like,
you get what is called a preemptive multitasking operating
system where you define threads that all run concurrently.
There are a couple of terms here you may not be familiar
with; the first is preemptive multitasking. In a nutshell, this
means that the operating system has a periodic interrupt —
usually in the 1 ms to 10 ms time range — that stops
whatever is happening and switches to another task thread.
Your code has no choice about this; it just happens. The
other term is “concurrent.” This is a very important concept.
Frequently, you hear folks say that many threads run at the
same time, or simultaneously. This is incorrect (unless you
have a multi-processor system). Only one thread is running
at a time, for whatever the timeslice period has been
defined. The program gives the illusion of simultaneous
execution because the tasks switch around so fast. This is
called concurrent processing,