Working with Lego Mindstorms

Since I wrote about my stint with Lego Mindstorms and blocked Java I/O calls in my last post, I thought I might as well go ahead and note some more of the gotchas I encountered while working with Mindstorms kit.

Although the Mindstorms RCX has pretty good capability, the programming interface bundled alongwith it is for kids. For any program spanning more than two cases of flow control, we need a real programming language.

The two languages I used were NQC (having almost C syntax, and named Not Quite C) and LeJOS (Le Java OS), based on Java 1.2.

NQC has inbuilt support for functions as well as multithreaded modules, but quite frankly the threading was not upto the mark. With two threads competing with each other for execution time, sometimes there would be several seconds where one of the threads waited for execution. LeJOS, on the other hand, worked beautifully with multithreading.

NQC also has a rather limited memory available for processing in comparison to LeJOS, which is quite surprising considering Java VM of LeJOS occupied around half of the memory. Yet, I was able to form large data structures in LeJOS while arrays of as small as 30 integers started giving trouble in NQC.

LeJOS has its set of troubles as well. The VM installation is actually a one time thing, but with the amount of testing you perform on the bot, batteries get changed, RCX units change and thus you find yourself running LeJOS installation a dozen times, which is quite a miserable thing to waste one’s time on. In addition to that, we have the great blocked I/O problem for Infrared Sensor which we discussed in our last post.

Limited memory and processing capacity puts stringent limits on nested methods, garbage collection and size of data structures. As I discussed earlier, a workaround to blocked I/O calls involved creating two separate threads. In my case, I had to keep both threads running infinitely. Having the child thread exit after receiving the data and having the parent thread spawn a new child when necessary worked for a while, but then the program would hang, presumably because there were too many threads getting created and the garbage collection may not have been able to cope up.

All in all, its fun working on the RCX, as long as the program is tuned to minimum resource usage, which goes for any micro platform. If you have experienced any more glitches or gotchas, please feel free to post comments!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.