CO.CC:Free Domain
Free Web Hosting with Website Builder

The NXT Project is a place to learn more about Lego Mindstorms Education NXT, with building guide and programming guide.

Friday, September 19, 2008

Which approach is best for you? by Dick Swan

Three different programming environments are available from LEGO for the NXT– NXT-G, ROBOLAB and ROBOTC, and they all make it quite easy to program Mindstorms robots. In addition, the open source community has developed other alternative programming solutions for the NXT. This article provides an introduction to the rich selection of programming approaches available today. This online expanded version of the Winter 2007 article features an extended comparison table and a lot more technical details behind this article.


NXT-G
NXT-G is a graphical programming environment developed by National Instruments for LEGO. Writing an NXT-G program is very much like creating a flowchart. You “write” a program by dragging icons (“code blocks”) that describe different behaviors, e.g., turn motor A on at 75 percent of full power, and connect them with lines to describe the program behavior. Using a variety of code blocks, you can control motors, introduce delays, play sounds and direct the flow of your code according to the state of sensors and timers, etc.
The diagram shows an NXT-G implementation for a “classical” line-following robot. The program looks at the value of a light sensor positioned above the line, and depending on which side of the line edge it is on, i.e., light or dark, turns one rear wheel on and the other rear wheel off. This is implemented as a loop that is repeated forever. Inside the loop, the light-sensor value is checked and the program branches to “true” or “false” code based on the value. NXT-G is targeted at children and adults with no programming experience, and for this reason, it is very easy to use.

NXT-G graphical programming screen for a line-following robot.

ROBOLAB
ROBOLAB was originally developed by Tufts University for LEGO for the first generation LEGO Mindstorms RCX microprocessor “brick.” It was extensively enhanced and revised to support both the RCX and the second-generation NXT.
ROBOLAB is another graphical environment, although it is not as intuitive as the NXT-G language. If you already know
ROBOLAB or you need to program on both the RCX and NXT, ROBOLAB is a good choice for you. If you’re just starting and want a graphical programming language for the NXT, the NXT-G is the better choice.

ROBOLAB program screen for line following.
ROBOLAB was written using the LabVIEW system from National Instruments. LabVIEW is also the underlying core technology used to write NXT-G. Other useful ROBOLAB features include support of both integer and floating point calculations, and ROBOLAB has a comprehensive data-logging solution. Graphical interfaces such as NXT-G and ROBOLAB are very intuitive but can become tedious as you become more experienced with programming.

ROBOTC
The ROBOTC solution allows the NXT to be programmed using the industry-standard C language. It was developed by the Robotics Academy at Carnegie Mellon University and can be obtained from the LEGO Education Group or directly from the Robotics Academy at www.robotc.net. Both of the graphical programming solutions had drag-and-drop capabilities for the “code blocks.” ROBOTC has a similar capability, but with it, you drag and drop text. The left window in the picture contains the “dictionary” of ROBOTC’s built-in robotics control capabilities. ROBOTC is targeted at novices and advanced users. ROBOTC has “basic” and “expert” modes; in the “basic” mode, a lot of the advanced functionality and menus are hidden.

ROBOTC screen showing classic line-following program.

ROBOTC has a powerful interactive real-time debugger that significantly reduces the time it takes to debug programs. So far, over 2,000 students have been taught ROBOTC in the classroom; at the end of the first class, they were programming and running their first ROBOTC programs for the NXT. Carnegie Mellon University’s Robotics Academy has developed step-by-step instructional videos that enable new users to become competent programmers quickly. ROBOTC supports both the NXT and RCX as well as products from Innovation FIRST (VEX and the FIRST Robotics Competition).

NXC ... NOT EXACTLY C
NXC (Not eXactly C) is a C-like language for the NXT. NXC programs are developed using the Bricx development environment. Bricx was originally developed for LEGO’s earlier RCX robotics product and has been enhanced to support the NXT.
NXC uses the same firmware as NXT-G. This is very convenient for users who want to program in both a graphical and a text environment because they don’t have to reload and change the firmware every time they switch the environment type. You can store both NXT-G and NXC programs simultaneously in the same brick. NXC has the same limitations as the NXT-G solution. It has integer but not floating-point variables. It doesn’t have more powerful LCD text formatting.

NXC line-drawing program screen.
The NXC programming language syntax and semantics are similar to C’s, but they are also different. For example, NXC character strings start with a double quote and end with a single quote; C uses double quotes for both the start and the end. NXC and ROBOTC are the only solutions that have run-time debuggers.

PBLUA
Lua is a relatively new text-based language that has gained a lot of attention and interest in the academic arena. pbLua is a full-featured version of Lua for the NXT. The pbLua implementation of the line- following program is very similar to the ROBOTC and NXC implementation.

pBLua implementation of line following.

NXJ
NXJ is a JAVA implementation for the NXT. It is standard JAVA but with a much smaller Class library. The standard Class library is far too large for the total 256K bytes of memory on the NXT. NXJ programs are written and compiled on the PC. The compiled programs are then transferred to the NXT where they can be executed.

NXJ line-following programming.

CONCLUSION
NXT-G is likely a good choice for a graphical programming solution. ROBOTC is a good, text-based programming solution. If you don’t need the full power of ROBOTC or want an open source solution and already have programming experience, NXC is another choice for you. pbLua and NXJ show promise but are not currently mature enough or sufficiently full-featured for most users.
Author Dick Swan is an avid LEGO robotics fan. He is also one of the principal developers of the ROBOTC system and co-developer of the ROBOLAB extensions for the NXT.
Links

LEGO Mindstorms retail, mindstorms.lego.com
LEGO Education, www.lego.com/eng/education/mindstorms/default.asp 
National Instruments NXT-G Programming, www.ni.com/academic/mindstorms
NXJ JAVA for the NXT, lejos.sourceforge.net
NXC Programming Language, bricxcc.sourceforge.net/nbc
pbLUA for the NXT, www.hempeldesigngroup.com/lego/pbLua

ROBOLAB graphical programming,
130.64.87.22/robolabatceeo or www.lego.com/eng/education/mindstorms/home.asp? pagename=robolab
Robotics Academy ROBOTC, www.robotc.net

No comments:

Sign up for PayPal and start accepting credit card payments instantly.