The best programming language for Lego Mindstorms, hands down

Play around with Lego Mindstorms NXT enough and at some point you'll inevitably get frustrated with NXT-G, its graphical programming language of "blocks" that you drag around and connect with "wires". It's great for teaching kids the basics, but once they embark on anything remotely ambitious they're bound to run into trouble. Whether it's the crazy sprawl of blocks over the work area (even a simple loop can require screens of slow horizontal scrolling), the lack of floating point math or, perhaps worst of all, the total absence of debugging tools, sooner or later you're going to start longing for a proper programming language that uses, you know, text and stuff.

"if...then...else", "while", even "for...next" -- you won't know how much you actually like those constructs until you don't have them. For anyone who's ever programmed, there's nothing better for understanding programming logic than properly tabbed and commented code, all in a column of text as God intended. And for your kids, there's no time like the present to introduce real programming, using coding conventions that will be as relevant in the decades to come as they were in decades past.

The good news is that there are lots of replacement text-based languages for Mindstorms NXT, from Java to Lua (or, if you want to stick with visual programming, you can also use LabView, the professional-grade language that NXT-G is based on). Even better news: I'm here to tell you that one stands out from all the rest.

It's RobotC and it's simply fantastic. If you're not a C programmer, don't worry--aside from a few grammatical conventions, it could be BASIC. But where it really stands out is in the programming environment. RobotC's integrated development environment (IDE) includes real-time syntax checking, compiling and contextual help and auto-complete of functions and variables. It has an awesome debugger, allowing you to step through your program, set break points and watch variables, or just watch the code executing on the NXT brick. And its collection of instructional and sample programs is unmatched in the Mindstorms world.

To give you of sense of this, here's my Lego UAV code in NXT-G (here and here) and in RobotC (here).

RobotC got its start at Carnegie-Mellon, the nation's top robotics school, and the pedigree shows. But special credit should go to Dick Swan, who authored much of the current program. (Dick, get a home page so I can link to you!)

For the stuff that we're now doing, including integrating GPS via Bluetooth, there's nothing for Mindstorms NXT that can match RobotC for flexibility and ease of use. Plus if you want to teach your kids real programming, why not introduce them to a real programming language? C leads to C+, C++ and C#, which is a lot more than you can say for Java ;-)

(Aside: as I was re-teaching myself how to program in C, I was reminded about the funny logic of computers. -100 is > than -90. Is this true in all languages?)

Views: 398

Comment by Jack Crossfire on November 14, 2007 at 5:15pm
But Java leads to $$$.
Comment by greg meno on November 17, 2007 at 9:47am
-100 > -90 == true
hah in most real languages this is false.
I had a similar experience when I was doing the F.I.R.S.T. robotic challenge in high school.
I was forced to use the ever primitive stamp basic from the good folks at parallax. It would seem that most languages that generate code for toy microprocessors don't allow the representation of negative numbers(ie unsigned arithmetic). Which is what I assume you are seeing here.

We there are various ways to cheat the system and
represent negatives, but who wants to fly their plane under ground :)

Moderator
Comment by Sgt Ric on November 17, 2007 at 1:38pm
It's not only programming that sends them earthward...there's also gravity!

(As someone who has "re-kitted" dozens of planes, I consider myself to be somewhat of an expert on the effects of gravity)
Comment by Craig on April 13, 2008 at 4:11pm
Chris,

I am interested in your input on learning a programming language for this sort of task. I saw the entry on RobotC. While I have very limited time to learn a programming language (the only experience I have is with SAS), I was wondering what your opinion would be for a) a good cross-platform language with mutliple applications (e.g. more bang for the buck, so to speak); b) what would be the best mechanism to delve into it - can it be self-taught? If it is RobotC, great. Does a language like Python have any application to the UAV work?

3D Robotics
Comment by Chris Anderson on April 13, 2008 at 6:59pm
RobotC is great for Mindstorms, but doesn't apply to embedded processors such as Arduino, PIC or Basic Stamp. But the basic principles are the same: C is the language you're going to want to learn, since it's the one common factor for all embedded processors. RobotC on Mindstorms is a great way to start robtics, and can be totally self-taught, but Basic Stamp is perhaps a better gateway to embedded processors, which will serve you well down the line.

I don't think Python, which at heart an interpreted scripting language if memory serves, is what you want. For UAV work you need a real-time language with easy hardware (from pin to register) access.
Comment by Neal Clark on April 13, 2008 at 8:20pm
I am a big fan of c and the atmel at90usb board. The board costs around $30, has a great ide, usb support, an uses the c programming language. If you want full featured high performance programming there is nothing better. Although the learning curve can be a little steep.

I have used the board alot in the past and can provide a RTOS, and drivers for magnetic compass, accelerometers, motors, servos, and a digital radio.

Thanks,

Neal.

Comment

You need to be a member of DIY Drones to add comments!

Join DIY Drones

© 2019   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service