Controlling Lego NXT Robots with Matlab

For research in Knuthlab, I am interested in controlling the Lego NXT Bricks with Mathworks MATLAB.  MATLAB is a high-level mathematical language structured much like C.  The main benefit is that many sophisticated mathematical algorithms are available for immediate use in MATLAB, and that these algorithms are fast and easily developed.  Furthermore, much signal processing research is performed in MATLAB; including most of my own algorithms.

NXT Brick

The most promising solution is to have MATLAB send commands to the NXT Brick and to receive sensor readings from the NXT Brick.  In both cases Bluetooth is the obvious means of communication.

At this stage, we have found three possible solutions:

  1. Incorporate Java Classes into MATLAB and then employ either iCommand or LeJOS NXT which both use the Java Programming Language to control the NXT Brick.
  2. Adopt the solution engineered by Gregory Gutt for the George Mason Neural Dynamics Laboratory, which employs RealTerm as a server to pass commands to the NXT via Bluetooth in the form of a Byte Stream.  This is a very attractive solution, but would require the writing of more detailed NXT commands in MATLAB…an endeavor possibly worth the effort.  Crucial to this effort are the steps of using RealTerm from MATLAB and understanding the Byte Streams used by NXT.
  3. The last possibility would be interfacing MATLAB to one of the various C or C-like interfaces to NXT.  This would require the writing of MEX files, which I am not very excited about doing.

We will have to make some decisions in the near future, but the prospect of interfacing MATLAB directly to the Brick via Byte Streams sent by RealTerm seems to me to be the most robust and flexible solution.  I will keep you posted.

Kevin Knuth
Albany NY

Published by


Kevin Knuth was born in Fond du Lac, Wisconsin, USA. He received his Ph.D. in physics with a minor in mathematics at the University of Minnesota in 1995, and held postdoctoral positions studying neuroscience in New Orleans and New York City. From 2001 through 2005 he was a research scientist at NASA Ames Research Center in the Intelligent Systems Division developing machine learning techniques and their applications in the Autonomous Systems and Robotics Area. Currently he is an Assistant Professor in Physics at the University at Albany, State University of New York. His scientific interests include: probability theory, astrophysics, complex systems, earth science, and brain dynamics. For recreation, he enjoys hiking, birdwatching and poking around tidal pools.

2 thoughts on “Controlling Lego NXT Robots with Matlab”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>