Fun with LEGO Mindstorms Programming
I've developed pbForth, a port of a rather archaic programming language, for the LEGO Mindstorms brick. The cool thing about it is that with a dumb terminal emulator that does ASCII uploads and can handle XMODEM (checksum) transfers, you can compile applications right on the brick! Yes, on the brick! When you are done, you blast S records back to your PC using XMODEM and then you can reload the app anytime using one of the standard firmware uploaders.
Check out pbForth for LEGO Mindstorms
pbForth got a whole chapter in the O'Reilly book, and it is getting more and more momentum as replacement firmware that busts the 32 variable barrier, and allows total cross-platform development without screwing around with building ecgs.
OK, I'm biased - I wrote it - but I think it's cool. Maybe some of you LEGO gearheads out there would like to try programming in something other than the native tongue. Learning Forth can make you a better C programmer. No, I'm not a Forth evangelist - I write embedded systems in C all day long.
I for one would love to see Perl for LEG0. Do any such extensions for Perl exist, or are they in the works? Could other languages be adapted for LEGO? Forth is admittedly rather archaic, and few people program in it any more. Might open the appeal of the Mindstorm to a greater community.
Oh. Who am I kidding. Every geek wants LEGO. :^)
-DrPsycho - Coping with reality since 1975
I, for one, do not want to see perl on legos. While the string handling is really great, it's a write-only language. I mean, with the standard legos you can take them apart and reassemble them in chunks... but with perl, once you assembled it the nanobots would come out of the controller box and glue everything together. Write-only legos... oi.
The reason tools like this are so important are of course variables. I mean what programming language is complete without something as basic as variables? Unfortunately, the default mindstorms "language" doesn't really have variables, and we had to pull off some rather absurd tricks in my high school robotics class to emulate them. It was unfortunate that the teacher wouldn't let us use something different like pbForth. I don't know what his problem was :(, then again he also loved NT.
I think I'm going to try and convince him to use pbForth for future classes, anyone know of other schools (highschools in particular) doing such a thing now? Our problem is that the classes primarily contain normal students with no programming knowledge, so this might sharply increase the learning curve. Any ideas on how to make programming simpler to the non-geek/techie?
Q:Doctor, how many autopsies have you performed on dead people?
A:All my autopsies have been performed on dead peop
(Forth, you mean)
You can also set your output to base 3, or 9, or 37!
(You can even set it to base 1, but don't expect to get an answer real soon...)
The cake is a pie
Perl is much like Lego... you can put almost anything almost anywhere. Just instead of innies and outties Perl has lots of punctation and even more context.
Perl is NOT suited to embedded programming. Perl is huge. A Forth interpreter is tiny, and Forth bytecode is tiny. Forth was written for embedded systems.
Perl is best suited to larger systems, as a good method of tying together the extensive resources available on such a machine. It's just not suited to a tiny system.
If you use windows try Mark Overmar's RCX control center. It's a keen IDE with a bunch of other kewl features like remote control, var watches, and more!
License: By reading this you are agreeing that you agree with me.
Yes, but that's a feature, remember. They designed it so that all programs could be forwards compatible if the value of 4 ever changes (which is good, since the ISO is now working on the Number89 standard, which is characteristically several years late (C9X, anyone?))
~~~~~~~~~
auntfloyd
Firstly, legOS is a really cool project. They've totally re-written the firmware for the RCX and built a fully pre-emptive multitasking environment running programs you can write in C or C++ and compile with a gcc cross-compiler. Very cool stuff, though the networking support (IR) doesn't seem very usable just yet.
NQC uses the standard firmware I believe, and is a bit more solidified. You write programs in a pseudo-C language and compile/upload it using the NQC utility. It also has some good IR message passing abilities.
Information about both of these can be found at LUGNET in the robotics section.
I experimented with LegOS a while back but ended up using NQC and a bunch of server-side Perl to build myself a telerobotic camera mount for my webcam.
There are definitely tools available out there for some extremely flexible Mindstorms programming.
As with any great toy, there are limitations, but here is the low down for thoes who dont know about this little toy yet...
Out of the box its a PLC type system with three in's and three out's... It comes with two motors, two on/off "touch" sensors and one ir sensor... It also has (but not talked about) its own built in IR sensor which it can use but requires using some slightly more advanced programming languages than the one included.
There are all types of Visual Basic programs available, but thats all I have seen so far. The lego site talks briefly about it I belive.
There are also add ons available for it... a heat sensor, a rotational sensor and of course more motors.
The toy is pretty nice, but really requires some patience engineering the remaining bricks to do what you want, and as always, if you dont have some legos already, you will want to go and get a few kits, because you will be limited despite the large quantity of bricks included.
Hope this helps clear some stuff up.
AF-Design, web development.
But when you have all the computer toys you want, and the ones you dont cost far more than a few hundred dollars, is it not worth it?
AF-Design, web development.
I was in the Penninsula Robotics Competition here in south eastern Virginia. We(my school's team) had to build a robot that would drive around a rectangular course and collect small white wiffle balls.
Programming for the Mindstorms robots isn't very hard. However there are many other problems with them.
For one you are only allowed to have three engines on a given mindstorms robot. I guess i should more accuratly say that you are only given 3 power terminals to plug your engines into, you may plug in more than three engines, but then two of them must go in the same direction.
Another problem with the mindstorms robots is that they don't allow much room for a "smart" robot, as you are only given 3 sensors (like the engines above you can plug in more than three sensors but then two of them must respond to the same stimulus).
Also the strength of legos in general is much worse when you try to put legos and a moving vehicle into one. Your building style will have to be entirely reformed if you plan on keeping your mindstorm alive for more than 10 minutes. The technic legos help with this a little, because they are longer and contain those neat axle shafts which we used liberally. But overall if you decide to change anything on the robot it will have to be entirely rebuilt for strengh/durability reasons.
The last major problem with mindstorms robots is that they cost way too much. For a kit including three engines, a bunch of legos, and one cpu unit(basically the bare minimum you can get by on if you want a robot that moves), it was > 500$.
I got my mindstorms kit a while back but i havent played with it a lot recently. I know 300 bucks (canadian ;) is a lot to spend but i think it was completely worth it since i have quite an investment in a lot of other technics lego kits. Now i am able to use all those pieces to make tonnes of stuff!
I tried using the RCX software which came with it (under emulation on my mac) but it was deplorable.. not just slow, i found it icky to use. I tried using RoboLab (the software used in the educational market from Dacta) but that was graphical too! I finally chose NQC and so far have found it the most useful. Theres just something about whipping out a bunch of code and compiling it ;) rather than dragging a bunch of icons together and hitting 'SEND' (imho).
the last thing i remember making is a garbage dump truck which used sensors to pickup and empty a garbage container, then drive away.. (wasnt my idea, i saw it on the web) but it was my implementation. The next thing i want to make is a wicked sports car with a rack & pinion steering and a gear box. Check out Ben's Lego Creations for ideas. He has some really neat designs.
i also recommend the new david baum book (he made NQC) for general programming and lego design issues. I love this book. Check out his site.
cheers,
nitin
My congratulations to Ralph on pbFORTH. It appears
to be a great alternative to the Lego firmware
in providing more granular control of the RCX and
in its functionality. I especially enjoyed the
ability to try out commands on the fly via a terminal (without having to compile or write a
whole program first).
At this time, however, I find I'm spending more of
my time in NQC. It's a fantastic tool -- very C
like and feature-rich. I find I haven't really
run into a situation yet where pbFORTH's extra
functionality has been required (and consequently
the installation of a firmware different from that
which came with the RIS).
Ultimately, I'm not sure I need to spend the time learning FORTH, just to play with legos.
Last, I have no opinion of legOS, since I haven't
tried it yet. It looks very cool, though.
It's probably worth mentioning that most of these
alternatives are due to the reverse engineering
of the RCX done by Kekoa Proudfoot:
http://graphics.stanford.edu/~kekoa/rcx/
In my Netscape, it's under 'Communicator | Tools | Java Console'. Under my IE4, it's under 'Internet Options | Advanced'. Setting that setting there will enable it in the 'Tools' menu.
granted, that for over 100 it was kinda high priced...i just bought mine saturday. It was actually over 200 for the full mother load set, and then for 6 AA batteries and a 9 volt. As with some other ppl, i havent touched legos for several years and have been working basically out of the book for the models for now, however they are fun to play with, i have yet to make anything productive with them, though i do feel that over time its possible (just make sure you have some old parts to through in if u want to get creative... They're expensive, but there fun lil toys
At first I thought, oh, that's OK. That still involves problem solving and working with constraints, yes?
But what constraints! Forget any notion of building Rodney Brooks-like robots: You get three sensor inputs. Even if you were willing to spring for lots of extra-cost sensors, and used some clever multiplexing schemes, you'd be hard pressed to build an insect that could even know whether its legs were up or down, forward or back.
And seemingly simple robots have a way of using up the parts that come in the standard set. Once you've built a track following robot, what do you do with it? You've used up both motors. Similarly, once you've built an arm that can raise/lower open/close its claw, you've used both motors, both touch sensors, and most of the gears and structural pieces.
I'm afraid that I lost interest pretty quickly.
I personally use NQC becuase personally its much easier for me to deal with than the drag-and-drop interface provided with the application on the kit's CD-ROM, and IMHO I find it more flexible.
Mark Miller has made modifications to allow each sensor input on the RCX to handle four different sensors per input (for a total of twelve sensors per RCX unit). He has also provided example code in NQC to show how to handle the situation. Here's the link: http://www.eagle-software.com/MindFest.h tm. This is a great solution for those of you who would like to use more than 3 input devices on a single brick.
What am I doing with mine? Currently I'm trying (honest!) to create an ATV that can map out its immediate surroundings (using proximity detection [http://www.mop.no/~simen/legoproxi.htm], and input from touch sensors) so that if it gets stuck it can quickly figure out how to leave the area. I just purchased my second set and a myriad of sensors too. Joy! =)
--
Well, I wouldn't mention it, I've already been slashdotted into the ground once and that was just a quickie fu, but you asked...
The Public 8-Ball is a robotic magic 8-ball driven by Lego bricks, RCX, and a radioshack motor (it's burnt up all my lego motors and they are just too expensive.) Hit it with Netscape and see your destiny in real time.
And please, if anyone has a Java applet to display a stream of JPEG frames let me know, then IE users can see the 8 ball too.
I may be slashdot resistant now. After a dozen or so people are queued for 8 ball shaking I start deflecting.
You're not paying $100 (or $200 or whatever) for the Legos. You're paying for a really cool, really small computer that happens to come with a bunch of Lego bricks and other accessories (sensors, motors, and the like).
I don't know just how cool it is yet, though. I got a set for my son for Christmas and he hasn't yet let me near it.
--
Someone you trust is one of us.
I got a lego mindstorms set for christmas, and haven't had as much time to experiment with it as i would have liked, but I think legOS is the coolest and most powerful environment for legos so far. It supports C or assembler, or anything else that will generate code that is compatible with the lego CPU. Best of all, it gives you 32 kilobytes, not 32 variables! I have heard that it is very cumbersome to download programs to it, but the dynamic loader in version 0.2 appears to have solved that nicely.
:)
I still think NQC is great for quick hacks, though
-- 2 + 2 = 5, for very large values of 2
Here's a related topic to this whole Mindstorm business. I have a system that LEGO designed way way before the Mindstorms and even MIT's LEGO brick (which became the basis of the Mindstorms) called LEGO Technic TC. It consisted of a very simple 8-bit ISA card that connected to a black box with a ribbon cable. Basically it was a relay control card. The thing had 6 "output ports" that could either drive a motor forward and backward or operate a light. It also had two input ports for 1-bit touch sensors or optical sensors (or any other 1-bit sensor you could build for that matter).
The whole system was programmed in a LOGO (Remember that one, geeks?) environment called LEGO TC LOGO. It ran under DOS. I have been unable to find any control programs for this thing except for the stupid worthless DOS based LOGO.
Is anyone else still using this system? Is there anything for it under Linux?
~GoRK
--
That said, you're right that the lack of IO is constraining. You can use multiple RCXs linked via an infrared network, but that of course doubles your cost. It'd be nice if Lego would release an "RCX Pro", with something like eight inputs and eight outputs.
(While I'm wishing, I'd also like to see a MiniRCX, about 1"x1"x2". It'd be supercool if that had a large number of IO ports, but I'd be happy as long as they were made to talk to each other easily -- you could fit quite a few in the space taken by a regular RCX, after all.)
--
A few days after getting my LEGO Mindstorms set, I hit upon the idea of using a joystick as an input sensor. I had an Atari 2600 in the closet with a few good controllers left, so I hacked together a method to use it with the RCX.
.sig: Not a text file ********
Briefly, with any switch-based joystick, you can use different resistors between each direction wire and ground so that unique sensor values result which can be read by the RCX.
When it's done, you have a 10-position switch that's very useful -- discrete values for joystick in the center, all 8 positions, and fire button pressed. (trigger RCX-mounted weaponry? Mmmm...)
Complete info is available at http://xidus.xidus.net/joystick.html
Have fun, and let me know if you do anything interesting with this sensor, or even if you manage to build one correctly.
-
$ more ~/.sig
********
$ more ~/.sig
********
--
I run a small website for Lego Robot (and general robotics) fans. Check out www.marsrobot.com for many interesting examples of mindstorms fun. How many toys are there that can be hacked to the level that the mindstorms kit has been?
Play Well
In simple math, yes it's well worth it. I usually spend between 45 and 50 for most PC games and can finish most of them in under two days. Some longer more involved games may take me 4 or 5 days but you get the idea. When I got my Mindstorms I played with them for 18 hours straight but now I'm down to 4-5 hours/day. If I were to add up all of the time I've spent with the Lego's it would cost me about $700 to get the same amount of "rec time" from games. Since I've gotten them I've worked through all of the "book models" and all of the challenges and then started making my own stuff. The two coolest was one that launched the a vehicles driver from the drivers seat when it ran into an object (moustrap not included) and a rotating mount for my web cam (got that for christmas) that rotates about 10 deg every 20 seconds. It covers about a 120 deg arc and reverses direction at each end.
Congratulations. The 8448 that I got for Xmas has a 5 speed *with reverse* now if only it had a working clutch...
They did? OH great. They just launched the Sputnik of Lego transmissions. Now I gotta catch up with a 6 speed transmission. You see, that's my dream job, to actually design new Technic sets for a living. If there was a part I needed to have made, I could of just had a custom one(like filling in the gap of technic gears they have) made and introduced into the lego part family.
We've taken some pictures, wrote up some text and released the software we're using:
http://fastolfe.net/features/telecam/