Electronic Design

The Mind Of Mindstorms

The Lego Mindstorms NXT hardware is the starting point but it is the software that takes building beyond castles and spaceships. The Lego Mindstorms NXT can be programmed using a growing number of tools. I take a look at three: the standard Mindstorms NXT programming environment, the NBC compiler and LabView with virtual instruments designed for the Mindstorm NXT platform. My visit to the FIRST Robotics competition showed me just how much fun the NXT can be. Most of the competitors were using the standard development platform but more experienced developers often make use of other options as well. Lego Mindstorms NXT The Lego Mindstorms NXT development platform is designed for its target audience, budding roboticists. The development environment uses a graphical programming language based on National Instrument’s LabView. This graphical programming environment supports multiple profiles that are handy for different users as well as different projects. Users can start out by using step-by-step instructions for developing applications for sample robot development platform designs. This includes downloads from Lego’s website. The building instructions and these examples are designed to work together. For each major enhancement to a project, there’s a matching addition to the sample application. Programming can be done using USB or the wireless Bluetooth support. This is especially handy when using a Bluetooth wireless keyboard or mouse. The NXT brick implements four distinct connections that can include PC. It can be used to synchronize the work of multiple NXT-based robots. Like the local flash file system, the IO is limited to a number, Boolean value or text string. The latter tends to be useful for sending or receiving multiple parameters in one step. The sample robots are designed to introduce solid hardware construction as well as programming basics. This starts with device control such as running motors and sensors. This eventually moves on to more complex programming constructs such as conditionals and loops. LabView has a sophisticated programming environment that we will take a look at later. Lego’s version is simpler but very functional. The Lego development environment uses a menu-based, drag-and-drop methodology. Programming objects called “blocks” are linked together using Lego-like structures. These structures represent the control sequences. Multiple paths represent tasks. Variable value links are simple lines. One advantage of the Lego-like structuring comes when inserting items in between other items. The programming environment simply moves the surrounding items farther apart so the new item fits. In general, the Lego approach has different on emphasis on control flow that tends to be more natural when trying to build step-by-step operations. LabView supports this same methodology but normally LabView applications are more data flow oriented. With the Lego approach, parallelism is more explicit. Multiple tasks are represented by multiple Lego-linked control structures. There is a concept of subroutines called blocks that are actually sub-programs. They can be reused, and examining the contents is simply a matter of double-clicking the icon. Blocks tend to be less sophisticated than LabView virtual instruments but they work well for the target audience and applications. The biggest limitation tends to be the debugging support or really the lack thereof. Print tends to be replaced with audio or video output from the NXT brick or wireless communication with the PC. NBC Compiler The Next Byte Codes (NBC) compiler targets developers wanting a text-oriented programming environment. The input is an assembler-like text-based language and the compiler generates byte code programs that can be downloaded to the NXT brick. This approach is more familiar to programmers experienced with programming environments like C, C++ or Java. It can also be faster to develop more complex robotic applications than using the Lego Mindstorms’ development environment. The development environment is a Windows application called the Bricx Command Center. It includes a text editor, compiler and downloader. A typical application looks like: #include “NXTDefs.h” dseg segment byte var1 dseg end thread main set var1,1 loop1: add var1,var1,1 brcmp NEQ,loop1,var1,10 exit end Programs can include multiple threads and there is a predefined set of functions that can control or query the Lego hardware. The NBC debugger is in beta at this point but it does work. Code matches the source since it is an assembly level debugger but that should be sufficient for many applications. NBC is definitely not for novices that would be more at home with the Lego Mindstorms graphical environment but it is ideal for those who want to learn about the hardware at a low level. It lets programmers learn about assembly level programming as well as debugging techniques from breakpoints to watch variables. NBC is still in its infancy and it has a lot of room to grow. It will likely remain a learning tool as other alternatives are likely to be more productive for larger applications. LabView And Mindstorms National Instruments LabView is a sophisticated graphical programming environment that can target a wide range of platforms from the Lego’s Mindstorm to embedded platforms like National Instruments’ CompactRIO or Analog Devices’ Blackfin digital signal controller. LabView’s basic graphical component is the virtual instrument (VI). A virtual instrument can accept a number of inputs and generate a number of outputs. The number of inputs, outputs and the function that the virtual instrument performs are variable. They can range from a two input adder with a numeric output to a graphical oscilloscope display to a Fast Fourier transform. Essentially, virtual instruments are comparable to text-based subroutines. LabVIEW Toolkit for Lego Mindstorms NXT adds VIs for all the Lego controls, motors and sensors. It works with LabView 7.1 or later. It is possible to add more VIs for custom hardware. LabView already has all the graphical programming constructs that the NXT hardware can support. This means that the entire LabView programming power can be brought to bear. LabView will be the programming platform of choice for more advanced Lego NXT maniacs. A set of files and an application note describes how to convert a Lego VI to a Mindstorms block. This allows a one-way movement of developed components from LabView to Mindstorms. Migration from Mindstorms to LabView is not necessarily straightforward because of the differences in the graphical programming environments. Developers moving code from LabView to Mindstorms must keep this in mind. For example, the Lego block’s drawer of variables is comparable to a VI’s input and output connectors but they look much different. The other consideration is price. The Mindstorms development environment is free and comes with the Lego hardware. LabView costs a significant chunk of change although educational discounts and donations can be significant. Organizations like FIRST Robotics teams are provided with free tools from a number of companies including National Instruments. The advantage for National Instruments is that Mindstorms is just the starting point. Related Links FIRST Robotics Lego Next Byte Codes National Instruments

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.