Guy on Simulink

Simulink & Model-Based Design

Running Simulink models on LEGO MINDSTORMS NXT 12

Posted by Guy Rouleau,

As you probably already know, MATLAB R2012a is now available for download!

One of my favorite feature in this release is the built-in support for running models on low-cost target hardware, including LEGO® MINDSTORMS® NXT and BeagleBoard. To give you an idea of this feature, here is a discussion I had with my friend Ashish Uthama.


Ashish and I started as Application Support Engineers at MathWorks on the same day. While I was focusing on Simulink, he quickly transferred into the Image Processing Toolbox team. Consequently, he never really had opportunities to use Simulink.

As part of my job, I am currently developing what we call Model-Based Design Labs. In these internal training labs, we use LEGO® MINDSTORMS® NXT to give participants a Model-Based Design experience. Ashish just signed up for the next set of labs I will teach next month.

Part 1 - Setup

Ashish: Hey Guy, I am really excited about the Model-Based Design Lab!. I just bought a LEGO® MINDSTORMS® NXT kit. Here is a YouTube video of what I did last weekend.

Guy: WHAT!!! You did not use Simulink to program the NXT???

Ashish: I was planning to, eventually. Isn’t there a whole lot of setup steps? Like downloading drivers, compilers, blocks and the associated configuration? I’ll get to it when I have more time to spare.

Guy: It used to be that way. But we have made the process a whole lot simpler with R2012a. Now it's literally a couple of clicks to install it. Once you have MATLAB and Simulink installed, go to the Tools menu and you should see an option to Install/Update Support Package.

Installing the NXT support package

In R2012a, we offer support packages for two targets: Beagle Board and LEGO® MINDSTORMS® NXT. Select the one you need and Simulink will install everything needed.

Selecting a target

Ashish: That's it? And I only need MATLAB and Simulink installed? No Simulink Coder?

Guy: Absolutely, and in fact, it also works with the Student Version of MATLAB and Simulink.

A few hours later...

Part 2 - Results

Ashish: With just a basic introduction to Simulink I received 4 years back when I started with tech support at MathWorks, it only took me a couple of minutes to install the required software and an hour or so to get my first bot programmed! Here is a video of what it does:

Guy: Nice... and what does your model look like?

Ashish: As you can see below, I used the Color Sensor and configured it as a light sensor. I analyzed the data realized I could program it to follow the edge of the line. The algorithm is simple, white means turn left and black means turn right.

Line Tarcking Model

Guy: Not bad for a first try. I’ll show you how to improve that in the Model-Based Design Lab.

Ashish: Considering it's actually running a compiled program on the hardware, this is really impressive. I am excited about the power of Simulink!

Guy: I really think this built-in support for running models on low-cost target hardware is a great tool to learn many engineering concepts.

Now it's your turn!

Do you think it could be useful for you to learn or teach engineering concepts and Model-Based Design?

For more information, consult the documentation for more details on how to run models on target hardware.

Leave a comment here.

12 CommentsOldest to Newest

Paul replied on : 2 of 12

You guys get paid to play with Lego? Where do I sign up?
I don’t think I’ll get one because I can see my life being consumed by that thing, trying to make it moonwalk on command and fetch me beer from the fridge…
I’m not in education, but this is massive news for just about every controls course there is, well done. I can see people getting carried away and maxing out the processor on that thing, what’s it running?
Is there a new framework for target / board support packages in R012a? Wha are the implications for the older methods?

Dan Lluch replied on : 3 of 12

@Manu – We are aware of Raspberry Pi and will keep it in mind

@Paul, Glad you like the capability, and we have over 300+ openings available! So feel free to take a look and apply :)

In terms of what is running on board, it is running NXT OSEK. You are right that there may be resource limitations, but so far people have liked and been able to do a surprising amount on there. We urge people to try it out and share what they do on MATLAB Central. Having the resource limitation also leads to ‘learning moments’ between faculty/students too.

There is not a new framework for 12a target support packages, per se. We are including some built-in support using the technology we have, but there are still significant investments in our production code generation. That will continue.

@J2n10r89 replied on : 4 of 12

Hi guys. I have a problem installing Mindstorm package. The problem appears when the GNUARM is installing. It says that the file is corrupt and that is neccesary to get a new copy. I do not know what to do. Please help me.

@J2n10r89: I have seen that once in the past and redownloading the installation fixed the problem. Please contact technical support if this does not resolve the issue.

Eduardo replied on : 8 of 12

Hey there!! I found very interesting your code. Very smart.
I am programming a C-ACC system to 3 Lego NXT cars rides in platoon and following a line with this toolbox from Matlab2012 in Simulink.

Im having some problem because I need to plot the graphs of acceleration and speed of the cars, and also adjust the speed and PID parameters in real time remotely by bluetooth communication.
I think the parameters is ok to set making the communication pc to brick. But i also need the communication on the other hand, from brick to pc to take information about speed and acceleration and plot the graphs on PC while the program is running.
Do you know if is that possible? Thanks !!!

jer replied on : 10 of 12

Hey! Thank you for posting this, I was having such a hard time going from NXT to Simulink. This program is great, however not being familiar with the Simulink models I do not know how to change variables (i.e. different colors controlling how the robot turns). Where can I find a layout that tells which constants control these commands?

Mehdi replied on : 11 of 12

Hey Guy, I have a question. I need to used RFID sensor in my hardware which is not supported by simulink pakage for NXT. Do you have any idea about adding a block for that in simulink? Thanks,

Add A Comment

What is 2 + 9?

Preview: hide