Lego Mindstorm NXT are a great platform for many things such as games, education etc.
In the following I will described my adventures with the standard LEGO Mindstorm NXT package + a Gyro from hitechnic and MATLAB 2007b.
The quick guide is to download the wonderful package NXTway_GS and follow the instructions there. In what follows I am trying to explain the basic technologies used in NXTway_GS.
The long term goal of the project is to examine the possibilities of using LEGO Mindstorms as a way to teach Linear/Fuzzy Control. The short term goal is… to have fun.
So I need two or three “classical” case studies. The first thing that came in my mind is the inverted pendulum problem, or in this case the more interesting self-balancing robot problem. But first things first.
LEGO Mindstorm NXT – Specifications (wikipedia)
- 32-bit AT91SAM7S256 main microprocessor (256 KB flash memory, 64 KB RAM)
- 8-bit ATmega48 microcontroller @ 4 MHz (4 KB flash memory, 512 Bytes RAM)
- 100×64 pixel LCD matrix display
- A single USB 2.0 port
- Bluetooth (Class II) wireless connectivity, to transfer programs to the NXT wirelessly or offer ways to control robots remotely (through mobile phones and possibly by PDA‘s)
- 4 input ports, 6-wire cable digital platform (One port includes a IEC 61158 Fieldbus Type 4/EN 50 170 (P-NET) compliant expansion port for future use)
- 3 output ports, 6-wire cable digital platform
- Digital Wire Interface, allowing for third-party development of external devices
LEGO Mindstorm NXT – Programming
- ROBOLAB – educational toolkit/graphical language
- Next Byte Codes (NBC) is a simple language with an assembly language syntax that can be used to program the NXT brick.
- Not eXactly C (NXC) is a high level language, similar to C, built on top of the NBC compiler. It can also be used to program the NXT brick. NXC is basically NQC for the NXT.
- leJOS NXJ is a high level language based on Java that uses custom firmware developed by the leJOS team.
- LEJOS OSEK is an open source firmware for LEGO MINDSTORMS NXT that allows ANSI C/C++ programming. LEJOS OSEK consists of I/O driver part of leJOS NXJ platform C/Assembly source code, TOPPERS OSEK Real-Time Operating System source code that includes ARM7 (ATMEL AT91SAM7S256) specific porting part, and glue code to make them work together.
I used LEJOS OSEK so a few more expanations/definitions (and a picture) are in order.
- OSEK=Offene Systeme und deren Schnittstellen für die Elektronik in Kraftfahrzeugen; English: “Open Systems and their Interfaces for the Electronics in Motor Vehicles”
It is a standards body that has produced specifications for an embedded operating system, a communications stack, and a network management protocol for automotive embedded systems.
OSEKtime specifies a standard for time-triggered real-time operating systems.
- TOPPERS（Toyohashi OPen Platform for Embedded Real-time Systems）Project is based on the technical development result applied ITRON, aimed to develop base software for use in embedded systems. By releasing quality Open Source Software, it is intended to promote embedded system technology and industry. Also by utilizing developed technology and distributing educational software, it is proposed to cultivate and train embedded system programmers.
Embedded Systems Programming – MATLAB
- Simulink® is software for modeling, simulating, and analyzing dynamical systems. It provides a graphical user interface (GUI) for building models as block diagrams
- Real-Time Workshop
Real-Time Workshop® is an extension of capabilities of Simulink® and MATLAB® that automatically generates, packages and compiles source code from Simulink models to create real-time software
applications on a variety of systems.
- Real-Time Workshop Embedded Coder® is a separate, add-on product for use with Real-Time Workshop. It is intended for use in embedded systems development. Real-Time Workshop Embedded Coder generates code that is easy to read, trace, and customize for your production environment. Real-Time Workshop Embedded Coder generates optimized ANSI-C or ISO-C code for fixed-point and floating-point microprocessors. It extends the capabilities provided by Real-Time Workshop to support specification, integration, deployment, and testing of production applications on embedded targets. Real-Time Workshop Embedded Coder addresses targeting considerations such as RAM, ROM, and CPU constraints, code configuration, and code verification.
Self Balancing Robot using all of the above technologies
NXTway_GS is a wonderful demo that includes:
How to Build a Self-Balancing Two-Wheeled Robot called NXTway-GS
Mathematical Dynamics Model of NXTway-GS
Controller Design for Balance and Drive Control
NXTway-GS Model Illustration
Simulation and Experimental Results
You can simulate NXTway-GS model and generate controller program that can be executed on the NXT. Also, you can see the movie of NXTway-GS control experiment at the following URL.
NXTWay_GS uses Embedded Coder Robot NXT Demo.
What happens roughly? – A model based design approach
The equations that describe the robot have been inserted in Simulink, and so a simulation (with VRML) is available.
The plant is linearized and the controller to keep the robot standing up is found using LQR (Linear Quadratic Regulator) techniques.
The controller found is included in a Simulink diagram, and using Embedded Coder NXT Demo, Lejo OSEK C source code is produced.
The C code is then compiled using the GCC of GNU ARM toolchain that produces a binary file which can be uploaded (either in SRAM or in flash) using USB to the NXT.
More in a few days…