Lego Mindstorms Nxt 2.0 Download Mac Updated

Lego Mindstorms Nxt 2.0 Download Mac

Lego NXT on the Mac

Book Number: 23 (2007)
Event Number: 04
Column Tag: Geek Toys

Lego NXT on the Mac

Lego's next generation Mindstorm kits play nice with the Mac.

Past Rich Warren

I acknowledge it. I have had a long-term love/hate affair with the Lego Mindstorm line. I beloved the idea of building robots from preformed plastic bricks, simply the actual kits always failed to alive upwards to my expectations. Certain, the Robotic Invention System seemed cool when I first opened the box, but I soon constitute the express selection of motors and sensors quite...um...limiting.

Of course, the software side was even worse. Lego's graphical programming surround only ran on Windows. Sure, you lot could find third party programming tools that offered fractional Mac back up, but these oftentimes lagged behind their Windows or Linux counterparts. Programming the Mindstorm brick from the Mac often devolved into an practice in frustration.

Then, when Lego announced the new Mindstorm NXT, I greeted the news with a fair bit of cynicism. At least, that was my intention, but part of me still wanted to believe. I grew curious, and peeked--only peeked--at the printing releases. The more I read, the more intrigued I became.

The Mindstorm NXT offers several pregnant improvements over before models. Information technology provides a more than-interesting range of motors and sensors directly out of the box. Besides, Lego'due south software now runs nether OS X; you can even purchase the NXT kit at your local Apple tree store. Finally, Lego has open sourced their firmware. By providing software, hardware and Bluetooth developer kits, they requite the customs unprecedented access to the brick'southward inner workings. Overall, the new Lego Mindstorm NXT is a promising platform for anyone interested in hobby robotics, and information technology is especially nice for Mac lovers.

The Hardware

The brick comes with 4 input ports (ane doubles equally an expansion slot for a even so-hypothetical sensor hub) and iii output ports. The overnice-but-pocket-size LCD tin can display black and white text and graphics, while the brick's loudspeaker plays a diverseness of NXT sound files. Unfortunately, the brick can but play .rso files. Notwithstanding, you tin find Mac-friendly utilities that convert .wav and MIDI files at http://bricxcc.sourceforge.net/utilities.html.

You connect your computer to the brick using either a USB cable or a Bluetooth wireless connectedness. The wireless connection is very cool. The brick can link with a computer, with other bricks or even with Bluetooth phones or PDAs. The Mindstorm community has already produced a number of PDA and cell phone remote controls. I suspect we will meet interesting Bluetooth sensors in the time to come.

The kit comes with 3 motors. This is the NXT's biggest limitation, since (different sensors), with only iii ports, this looks like a difficult-and-fast limit. However, including a 3rd motor in the basic kit feels similar big comeback over the RIS 2.0, which only came with 2. The new servomotors are bigger than the former motors, but they include a born rotation sensor. This gives you a lot of fine control over the robot's drive train.

The kit likewise comes with four sensors: a affect sensor, a light sensor, a sound sensor and an ultrasonic range finder. The touch and light sensor are bigger than, simply otherwise similar to, their RIS 2.0 equivalents.

The sound sensor can observe the book of the ambient sound in either adjusted or standard decibels. The dBA setting focuses on sounds within man hearing, while the dB setting includes sounds as well high or too depression for our ears. In either example, it can distinguish volumes up to about ninety dB, which is roughly equal to a typical lawnmower.

The Ultrasonic Sensor uses sonar to make up one's mind the range to objects. Information technology can discover items from 0 to 255 cm (a little over viii feet iv inches), with an accuracy of 3 cm. Still, this accuracy depends a lot on the object you are sensing. Ultrasonic sensors work best when approaching hard, flat objects straight on. If yous approach the wall at as well steep an angle, a lot of the sound may reflect away from you. For similar reasons, the sensor struggles with round, soft or thin objects. Effectually my apartment, the robot keeps running into my beanbag (probably considering of the roundish shape and the soft cover), and information technology cannot see the screen door leading to our balcony. Other than that, it does a reasonably good job.

Finally, no give-and-take of hardware would be complete without mentioning the third party expansions. Several companies offer new, high-quality sensors: everything from magnetic compasses to DYI prototype boards. Even Lego'due south getting in on the hardware-hacking game. Yous tin can buy legacy cables on their online store, letting yous connect erstwhile RIS ii.0 motors and sensors to the new, NXT brick.

Overall the NXT seems well designed with an eye towards futurity expansion. Sure, it still has its limits, but it is much more promising than any of the earlier Mindstorm products.

The Software

Lego's Mindstorm software lets you lot program and manage the files on your brick. Programs are written using a elevate-and-drop graphical programming language, referred to as NXT-G. Powered by National Instruments' LabVIEW, NXT-One thousand represents a huge comeback over the graphical programming tool used by the RIS two.0. Great for simple projects or quick prototypes, it still becomes frustrating when yous try to create larger or more complicated programs.

If you want even more ability, y'all can utilise the NXT toolkit for LabVIEW, but LabVIEW is non cheap. They offer a gratuitous, academic version to Mindstorm owners--just the gratis version only runs on Windows. If you lot have a spare $1,199 lying around, you tin can purchase the Mac version. I don't. So permit's talk nearly something else.

If graphical programming is non your cup of tea, y'all can find a growing number of third-political party tools scattered across the spider web. I will just mention the Mac-friendly ones in this commodity. This includes: LeJOS NXJ and iCommand from the LeJOS team (http://lejos.sourceforge.cyberspace/), Side by side Byte Codes (NBC) and Not eXactly C (NXC) from the people at Bricx Command Center (http://bricxcc.sourceforge.net/nbc/),and finally Matt Zukowski and Tony Burser's reddish-nxt library (http://rubyforge.org/projects/reddish-nxt/).

These third-party projects tin exist divided into 3 master camps: software that runs on a estimator and sends commands to the brick over Bluetooth (iCommand and ruby-nxt), languages that compile to the same bytecode used by the existing NXT firmware (NBC and NXC), and systems that completely replace the brick's firmware (LeJOS NXJ). I will briefly examine each of these options, only be warned: these projects are nevertheless green, and near of them are undergoing frantic development. Anything I say now will undoubtedly exist outdated by the time this commodity prints.

The Dark Side

Of course, in that location has to be a catch somewhere. Every bit I am writing this, the Lego software is non available equally a universal binary. It just runs under Rosetta, and this creates some issues.

First, Rosetta does not recognize the Bluetooth adapter on my MacBook Pro. And then, I tin can just communicate with my brick using the USB cable. While that definitely knocks the software downwardly a few pegs on the coolness-O-meter, information technology'due south not (by itself) a deal breaker. Unfortunately, the Lego software too seems ho-hum and buggy. Dropping in a serial of uncomplicated commands works fine, but don't even recall well-nigh using data wires. Don't go me incorrect; the software works keen on my wife'southward PowerMac. The Windows version also runs smooth-equally-silk under Parallels. Just if you have to employ the Lego software on an Intel Mac, save oftentimes and don't try anything too complicated.

Still, all promise's not lost. If you accept an Intel Mac, you tin manually configure the Bluetooth connection (come across http://juju.org/articles/2006/10/22/bluetooth-serial-port-to-nxt-in-osx for good instructions). This won't help you with Lego's software, but it does let yous use iCommand and ruby-nxt. I also recommend checking out the NXTBrowser for uploading and managing files over a Bluetooth connection. (http://web.mac.com/carstenm/iWeb/Lego/NXT/NXT.html).

The rest of this article focuses on programming the tribot robot. If you followed the instructions when you opened the NXT box, it is the first robot you congenital. It'south a differentially steered, three-wheeled robot with snapping mandibles--you lot can't miss information technology. If, like me, you've lost the original instructions, you can find a digital version in the Mindstorm software'south Robo Center.

We will simply use the ultrasonic sensor in these samples, but go ahead and make the whole contraption--afterward all, snapping mandibles are only besides cool!

NXT-Thou


Launch the Mindstorm NXT application. In the Start New Programme text box, type wanderer and click Go.

This gives you a blank filigree. You lot can create your programme by dragging blocks from the toolbar. Let's starting time by dragging a loop block and dropping it onto the sequence beam as shown.


This is our plan's chief loop. Nosotros desire it to run forever, which should exist the default. To double-cheque, select the loop block, then look at the control settings below the workspace. Select Forever from the driblet-down options.

Now drop a switch block within the loop block. This fourth dimension nosotros will want to change the settings. Control should say Sensor. Change the Sensor setting to Ultrasonic Sensor and set the Distance to < 25 inches. You might want to play around with the distance setting, just 25 inches seemed adept for running around my apartment.


This is the skeleton of the globe's simplest behavior-based robot. Behavior-based robotics (also called reactive robotics) builds a robot from the lesser upwardly. Professor Robert Brooks pioneered this technique at MIT in the 1980'due south.

Instead of worrying near complicated data processing and planning, behavior based robotics focuses on immediate reactions to the robot's surroundings. These robots tend to be elementary but very robust. They effortlessly handle unexpected changes in their surroundings. And, often, surprisingly complex behavior can sally from the interaction of otherwise uncomplicated rules.

Given the relatively limited sensors and on-lath processing ability, beliefs based approaches seem the perfect fit for Mindstorm projects.

Here, we are building a uncomplicated rules-based compages. Each rule has a prerequisite, if that prerequisite is met, the rule fires. In our case, we have two behaviors: avert obstacles and explore. Since we only have two options, we can express them in a unmarried if...else... rule. If we are closer than 25 inches, avoid the obstacle, else explore.

To actually plan this, drop a move block into the top and bottom of the switch. If our robot senses an object closer than 25 inches, it will execute the pinnacle axle (indicated by the flower icon). If it is farther than 25 inches, it will execute the bottom (note the mountain icon--become information technology? Blossom for close. Mount for far abroad.).

Select the top move block. Set the Power to 25, the Elapsing to Unlimited and slide the Steering command all the fashion to the correct, as shown.


Select the bottom move block. Prepare the Duration to Unlimited. Exit all the other settings alone.


Normally, a movement didactics volition cause the program to block until the movement finishes. When you gear up the block's elapsing to unlimited, it starts the motors, and and so continues onto the next control on the sequence beam. In our case, information technology will just proceed looping around. On each iteration it checks the ultrasonic sensor, then executes the advisable block. If something's in our way, nosotros plough to the right. Otherwise, we bulldoze directly ahead.


So far this is a very simple instance. NXT-G programs can get a lot more complicated. About blocks have a pullout drawer on the bottom-left corner. Opening this drawer exposes a serial of input-output ports. Yous can connect blocks using information wires, allowing you lot to modify the block's settings at runtime. While the exact details are beyond the scope of this article, I volition include a slightly more complicated example with the online source code.

NXT-G'south biggest limitation is that it quickly becomes unwieldy. I notice scrolling around the desktop quite awkward, especially when the projection no longer fits on a single screen. You can compress common sequences into custom blocks. This gives you lot some control over the size of your plan, only it does non permit real functional decomposition. As far as I can tell, there'southward no style to pass non-global values into these custom blocks.

So, if y'all're like me, y'all'll quickly accomplish the limits of what NXT-Thousand has to offer. Or, at to the lowest degree, what y'all're willing to put up with. So, permit'due south look at the third party options.

NBC/NXC

Next Byte Codes (NBC) is an assembly-similar language for the default brick firmware. Information technology gives you lot fine-grain, low-level control over the brick. You can write and compile programs, and then download them to the brick, much like you would from NXT-M.

Not eXactly C (NXC) is a c-similar language congenital on top of NBC. In many means NXC is modeled after NQC, which was a c-like programming language for the onetime RIS 2.0 Mindstorm kits.

Both languages provide powerful, on-Brick programming capabilities that go well beyond NXT-Thou. Personally, I adopt the high-level, NXC approach, only to each their ain.

Hither is our sample plan in NXC:

NXC sample code

The post-obit code shows our sample program written in NXC. The robot turns to the right whenever the ultrasonic sensor detects an obstacle closer than 25 inches. Otherwise, it drives direct.

#include "NXCDefs.h" // Very simple implementation, everything is placed in the master task. task chief(){    short ultra;        SetSensorLowspeed(S4);        while(true){       ClearScreen();       ultra = SensorUS(S4);              // range converted manually.       // 63 cm is approximately 25 inches.       if (ultra > 63){          TextOut(0, LCD_LINE7, "Forrad");          NumOut(0, LCD_LINE8, ultra);          OnFwdSync(OUT_BC, 75, 0);       } else {           TextOut(0, LCD_LINE7, "Turn!");          NumOut(0, LCD_LINE8, ultra);                OnFwdSync(OUT_BC, 25, -100);       }              // If nosotros endeavour to cheque the ultrasonic sensor also frequently,        // it will requite us incorrect values.       Look(20);    } }

You lot compile this using the nbc awarding from the command line.

nbc -O=wander.rxe wander.nxc

Now, upload wander.rxe to the NXT brick. You can either employ the Lego Mindstorm'south software, or try NXTBrowser. Once it's uploaded, you lot run the program on the brick similar any other NXT-One thousand plan.

Our plan is and then elementary, it should exist easy to interpret it into NBC, correct? Right?

I'll leave that project for the overly aggressive. However, if you lot only want to run across the bytecode, you can use the NBC compiler to decompile an existing *.rxe file.

nbc -x wander.rxe

You tin can save this file, edit it and recompile to your center's content. Y'all can likewise decompile NXT-G programs. Unfortunately, the Mindstorm software does not salvage compiled binaries. This leaves you with two choices. You can download the binary from the NXT brick to your computer, or you can use a third-party extension that saves NXT-Grand binaries to disk (http://forums.nxtasy.org/index.php?s=053735c91df88266e477eda9b28b06ca&showtopic=531&st=0&p=4477& - entry4477).

Note: while the NXT-G and NXC programs are functionally identical, the NXT-G binary is 5 to half dozen times larger than the NCX version. Yet another reason to use third-party tools.

Version    Lines    Bytes NXT-M      1448     27185 NXC         222      4793

ruby-nxt

Now we move to the realm of the strange. The ruby-nxt library lets you program your robot using Ruby-red. Withal, these programs run on your computer, not on the brick. Scarlet-nxt sends commands to the brick using the Bluetooth connection. The brick but executes these commands.

If y'all've read my earlier articles, you know I'k a big Ruby fanboy. So, I was quite excited when I establish this project.

This telerobotic approach has several advantages. The robot's program has full-access to your computer. This gives you a lot more memory and processing power. Yous can even build a GUI for the program using RubyCocoa (http://rubycocoa.sourceforge.internet/doc/).

At that place are, yet, a few downsides. When your robot wanders also far away, you completely lose control. Likewise, killing the program on your computer often leaves the robot executing it'due south last control, which tends to send it spinning over the horizon. Finally, you might observe a slight delay betwixt the moment your figurer issues a command and the moment your robot begins executing it. This tin become a serious upshot when trying to perform precise maneuvers.

Also, similar many of the tertiary political party tools, this projection still has several rough edges--mostly in the documentation, or relative lack thereof. The installation comes with a few sample programs, and a reasonably documented API. But, sometimes it'due south hard to see how all the pieces fit together, especially since crimson-nxt provides multiple options for doing the same thing. For our simple sample, I will use the commands API, a high-level abstraction which largely mimics NXT-G blocks

Here's a ruby-nxt version of our wandering robot:

reddish-nxt sample lawmaking

This is our sample program written in Ruby using the crimson-nxt library. Merely like the other samples, it turns to the right whenever the ultrasonic sensor detects an obstacle closer than 25 inches. Otherwise information technology drives straight.

require 'rubygems' require 'nxt_comm' def do_sonar   sensor = Commands::UltrasonicSensor.new(@nxt)   sensor.mode = :inches      return sensor.distance end def forwards   b = Commands::Motor.new(@nxt)   b.port = :b   b.ability = 75   b.direction = :forward   b.duration = :unlimited      c = Commands::Motor.new(@nxt)   c.port = :c   c.ability = 75   c.direction = :frontwards   c.duration = :unlimited      b.start   c.get-go terminate def plow   b = Commands::Motor.new(@nxt)   b.port = :b   b.power = 25   b.direction = :forward   b.elapsing = :unlimited      c = Commands::Motor.new(@nxt)   c.port = :c   c.power = 25   c.direction = :backward   c.duration = :unlimited      b.get-go   c.start end def shutdown   b = Commands::Motor.new(@nxt)   b.port = :b        c = Commands::Motor.new(@nxt)   c.port = :c      b.cease   c.finish terminate @nxt = NXTComm.new('/dev/tty.RikiBot-DevB-1') @running = true runloop = Thread.new {   while @running do     distance = do_sonar     if (altitude < 25)        turn       else       forward     end   terminate      shutdown } puts "Press the return key to stop." gets @running = false runloop.bring together @nxt.close

This code assumes that you loaded ruby-nxt using rubygems. If you loaded information technology manually, you lot may demand to edit the require lines.

You tin can run this from the control line as shown below

ruby wander.rb

There are a couple of important points here. I could not utilize the synchronized move commands. Whenever the robot encountered an obstacle, it would plow abroad as expected. But, when it started to drive forward once more, the synchronization always kicked in, and the robot snapped back around to face the occludent.

Instead, I gave each motor a split command. Even at the all-time of times, the synchronized motors don't bulldoze in a truly directly line. So, with the motors running separately, expect to meet distinct list to 1 side.

Additionally, the Bluetooth delay sometimes causes trouble. Even so, I recommend ruby-nxt (and it's soul-sister, iCommand) for any telerobotic project (that's just a fancy way of proverb computer-based remote controls). I'll include a ruby-based remote in the sample code.

About of this code was developed using old-fashioned trial and error while staring at the API. I tested several other approaches, but this was the just one that worked satisfactorily. Once again, every bit the project matures, things might even out a bit.

iCommand

Like in spirit to cherry-red-nxt, iCommand allows you to build and run Java programs on your computer. These programs also send depression-level commands to the NXT brick over a Bluetooth connexion.

As I am writing, iCommand only communicates with the original NXT firmware. However, future versions should likewise communicate with NXJ (meet below).

Currently, iCommand excels at computer-to-brick communication. Telerobotic programming seems overly hard at this point. A lot of the API does not work as advertised. I spent a lot of time massaging this simple sample into an acceptable shape. And, as you lot can see, the resulting source lawmaking is a flake on the verbose side.

Yet, iCommand offers an intriguing set of very-loftier-level robotic commands. These could profoundly simplify telerobotic programs, once the library matures.

Hither's our sample plan in Java:

iCommand sample code

This shows our sample program written in Java using iCommand 0.5. But like the other samples, it turns to the right whenever the ultrasonic sensor detects an obstacle closer than 25 inches. Otherwise it drives straight.

import icommand.platform.nxt.*; import icommand.nxtcomm.*; import java.io.*; public form Wander {        private boolean running;        public Wander(){              System.out.println("Wandering...");              running = truthful;       NXTCommand.setVerify(true);              Thread runloop = new Thread(){          public void run(){                          Ultrasonic sensor = new Ultrasonic(Sensor.S4);             int altitude;                          while(isRunning()){                distance = sensor.getDistance();                // Manual conversion of distances                // 63 cm is approximately 25 cm.                if (altitude < 63) {                   Motor.B.setSpeed(25);                   Motor.C.setSpeed(25);                   Motor.B.forward();                   Motor.C.backward();                }                else {                   Motor.B.setSpeed(75);                   Motor.C.setSpeed(75);                   Motor.B.frontwards();                   Motor.C.forward();                }             }          }       }; // end thread              runloop.commencement();       Organization.out.println("\nPress the return cardinal to quit.");              effort{                    BufferedReader br =              new BufferedReader(                new InputStreamReader(System.in));                    br.readLine();                 } catch(Exception eastward){           e.printStackTrace();       }              running = imitation;              try{          runloop.join();          } catch(Exception e){          eastward.printStackTrace();       }              stopRun();    }        public boolean isRunning(){       return running;    }        public void stopRun(){       Organisation.out.println("Shutting Downward!");       Motor.B.end();       Motor.C.stop();       NXTCommand.shut();    }        public static void primary(String[] args){              new Wander();    } }

You compile iCommand programs just similar a normal Java:

javac Wander.coffee

Then run information technology:

java Wander

Both iCommand and ruby-nxt make first-class image languages. Trust me, it's a lot easier to see data printed out on your calculator screen, than attempt to spot messages on the NXT while it zips abroad at pinnacle speed.

Ruby-nxt and iCommand besides provide the full power of a full general-utilise programming language, with a large number of useful libraries at your fingertips. Imagine edifice your Robot on Track, or crafting interesting Swing GUI for a telerobotic project. These tools permit your imagination run wild. And the Bluetooth connectedness really opens doors--at to the lowest degree until your robot wanders out of range...

LeJOS NXJ

Every bit far equally I can tell, this is the kickoff firmware replacement written for the NXT brick. NXJ allows you to run Java programs on the brick itself. As I am writing this, the LeJOS crew only released their initial 0.one offering, and information technology's not quite fix for prime time. Currently, there'south no sound, Bluetooth or ultrasonic sensor back up, but like all the projects mentioned in this article, it's undergoing rapid evolution.

The LeJOS crew congenital an fantabulous firmware replacement for the former RIS 2.0 system, including a built-in robotics API for beliefs-based development. Looking at the new API, they clearly program to follow a like arroyo hither.

NXJ promises to be a powerful replacement for the default Lego firmware. I expect forward to playing with it once information technology matures, simply I'one thousand going to wait a little while earlier I make that plunge.

Real Ability

We are always faced with tough engineering decisions--even in hobby robotics. Sometimes I need the authentic motor control and fast reactions that I get past running my lawmaking on the brick itself. Other times I need access to more memory, to greater computational abilities or a nice GUI interface. The corking affair is, with a Bluetooth wireless connection, yous tin can accept your cake and consume it too.

Part of the programme can run on the brick. It tin can gather data, and then ship that data back to your calculator via the Bluetooth connection. Your estimator and so churns through this data, doing all the heavy computations. Once done, the computer sends new commands back to the brick, perhaps setting new goals or otherwise changing the robot'southward behavior.

This is where the real power lies. And I suspect, as the third-party tools mature, splitting a program betwixt the calculator and the brick will become easier and easier.

Summary

Well, that's the end of our lightning tour of the Mindstorm NXT. I was pleasantly surprised with the breadth of third-party tools currently available. Of course, our PC counterparts have a few additional choices, but non every bit many every bit you might estimate.

All of these projects are still young and a scrap crude around the edges. NXC seems to provide the solidest implementation, merely the documentation remains rather light. Still, I highly recommend NXC as an NXT-Yard replacement.

Compared with the old Mindstorm kits, the NXT offers a much wider range of features and capabilities. There'south more than enough to keep me decorated for quite some fourth dimension. And, equally third-party tools and hardware mature, the possibilities will go on to grow.

I can hardly wait.


Rich Warren lives in Honolulu, Hawaii with his wife Mika and daughter Haruko. He is a freelance writer, full-time software engineer and part-time Graduate student at the University of Hawaii in Manoa. When not playing on the embankment with his daughter, he can be constitute writing, studying, or doing enquiry--all on his MacBook Pro. You tin reach Rich at rikiwarren@mac.com.

Lego Mindstorms Nxt 2.0 Download Mac

Posted by: drummondcanetur.blogspot.com

Post a Comment

0 Comments