Você está na página 1de 5

by Colin Flournoy, IAR Systems

A Meeting of the Mindstorms


Ever wonder what may lie under the hood of some of todays toys aimed at our youth? You may be somewhat surprised to find that no longer are the days of entertainment centered solely around a 555 timer circuit. What if I told you that toys geared toward ten year olds and older may be an ideal platform for your own personal enrichment? Sounds interesting? Well, that is exactly what in fact is delivered in a LEGO MINDSTORMS NXT robot kit. In this article I would like to introduce you to a platform that provides a convenient and fun way to applying IAR visualSTATE and give you an overview of what is needed to obtain this. Initially when you purchase the LEGO MINDSTORMS kit, programming of the brain of your robot is done with a high level graphical language seen below, which parallels IAR visualSTATE in some respects. From a flowchart, a state machine is generated and downloaded via USB to the NXT brick where it is then run on a virtual machine.

The native NXT programming language

Page 2

Up until now, debugging LEGO MINDSTORMS was trial and error running standalone from any debugger, without any insight as to the state of the intelligent brick. For the professional/hobbyist, IAR Embedded Workbench and IAR visualSTATE provide an alternate, more familiar way to program and debug your robot. With a debugger attached you can inspect the state of variables and create your own custom firmware. The firmware for the NXT brick is open source and is available on the LEGO web site, along with other documentation such as hardware developers kit. With the firmware originally being developed under the IAR Systems tool suite, the opportunity and ease for creating your own custom firmware is readily available. Without going into too much detail with regards to the hardware on board the NXT brick, two main controllers coexist: Atmel AT91SAM7S256 (ARM7) and Atmel ATmega48 (AVR). Both controllers are connected via a Two-Wire Interface (TWI), where the ARM7 MCU is the master on the bus which in turn initiates and receives data from the AVR MCU.

Block diagram of NXT brick

For all intents and purposes, to create your own custom firmware, it is only necessary to be able to communicate to the ARM7 device within the NXT brick. LEGO has provided all of the necessary JTAG through hole pins to connect your IAR J-Link to their PCB, although the header pins are not populated on board. A slight modification two the intelligent brick will need to be made for you to connect IAR JLink to NXT. Provided at the end of this article is a link to the pdf file outlining how to solder the appropriate header pins onto your NXT brick. Note: The warranty to LEGO MINDSTORMS becomes void as soon as you open the brick. After this is done you will be able to connect your IAR J-Link to LEGO MINDSTORMS.

Page 3

LEGO MINDSTORMS with IAR J-Link connected

IAR Embedded Workbench and IAR visualSTATE enable the end user to develop the customized firmware at the source level and then graphically debug the application, given further insight into the state of your robot. With tight integration between IAR visualSTATE and C-SPY debugger the state machine comprising your robot can be debugged graphically as seen below in the statechart diagram. The state machine will be updated periodically within the debugger via the DCC channel on the IAR JLink. This new feature expands on the already powerful debug capabilities of C-SPY now allowing you debug a the statechart level. For instance you can now set breakpoints on a transition into and out of a state as opposed to the individual source line, view executed action functions, and also triggers.

Page 4

Simple motor state machine for LEGO MINDSTORMS

The benefits of this new debugger integration with IAR visualSTATE become obvious when debugging the application. You obtain instant graphical feedback pertaining to the system state at any point in time. Previous forms of state machine debugging would be distorted by the C-level implantation debugging. The example provided shows a breakpoint being set at the statechart level for LEGO MINDSTORMS NXT. This simple example contains three states related to the motor output, initialization, on, and off.

Page 5

Set breakpoints at the state chart design level

A link is provided at the conclusion of this article to an example showing how to program and debug your NXT robot right within IAR Embedded Workbench using the newly integrated IAR visualSTATE plugin for the IAR C-SPY Debugger. In the example project for IAR visualSTATE, the original source provided by LEGO has been modified to bypass the Virtual Machine, allowing the end user to test individual modules within the platform (i.e. motors, LCD display, Bluetooth, and input sensors. The example included, demonstrates how drive two output motors with toggling the main orange button and grey button on the NXT. This example can be expanded to a much larger application utilizing more of the modules on the platform. The original source code can be downloaded directly from www.legomindstorms.com. The web site also contains a wealth of example projects as well as building instructions for template robots. Any information related to using LEGO MINDSTORMS as an educational tool can also be obtained at www.legoeducation.com.

Você também pode gostar