Tutorials

How to use NXT with Matlab, "Hello Spin"



How to use NXT with Matlab, “Hello Spin”:

This tutorial will show you how to make a wheel spin using Matlab/Simulink and an NXT robot kit.

This tutorial assumes that you are familiar with or have gone through the following:

-          Completed the Embedded Coder Robot NXT Instruction Manual Supplied By Takashi Chikamasa tutorial

-          Familiar with Matlab and Simulink

 

1.       Open a new Simulink document

 

2.       Go to Simulation->Configuration Parameters->Solver and fill in the screen so it matches the screen below

 

3.       Go to Simulation->Configuration Parameters->Real-Time Workshop and fill in the screen so it matches the screen below

 

4.       To obtain the proper System target file click Browse and choose Real-Time Workshop Embedded Coder (no auto configuration)

 

5.       Go to Simulation->Configuration Parameters->Real-Time Workshop->Report and fill in the screen so it matches the screen below

 

6.       Go to Simulation->Configuration Parameters->Real-Time Workshop->Comments and fill in the screen so it matches the screen below

 

7.       Go to Simulation->Configuration Parameters->Real-Time Workshop->Symbols and fill in the screen so it matches the screen below

 

8.       Go to Simulation->Configuration Parameters->Real-Time Workshop->Custom Code and fill in the screen so it matches the screen below

 

9.       Go to Simulation->Configuration Parameters->Real-Time Workshop->Debug and fill in the screen so it matches the screen below

 

10.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Interface and fill in the screen so it matches the screen below

 

11.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Code Style and fill in the screen so it matches the screen below

 

12.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Templates and fill in the screen so it matches the screen below

 

13.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Data Placement and fill in the screen so it matches the screen below

 

14.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Data Type Replacement and fill in the screen so it matches the screen below

 

15.   Go to Simulation->Configuration Parameters->Real-Time Workshop->Memory Sections and fill in the screen so it matches the screen below

 

16.   Go to Simulation->Diagnostics->Connectivity and fill in the screen so it matches the screen below

 

17.   Go to Simulation->Diagnostics->Saving and fill in the screen so it matches the screen below

 

18.   Save the document as motortest2.mdl

19.   Add the blocks seen below.  Those blocks that need to be changed from default will be noted.  Make sure that the subsystem Test_Dan is titled the same as the function call in nxtbuild(‘Test_Dan’,’build’) and nxtbuild(‘Test_Dan’,’ul2ram’).  Please note that the Servo Motor Interface is set as Port B.

 

20.   Inside of the function call nxtbuild(‘Test_Dan’,’build’).  When pressed this button will build the C code and compile it into the proper binary format

 

21.   Inside of the function call nxtbuild(‘Test_Dan’,’ul2ram’).  When pressed this button will upload the compiled code from the previous step to the ram of the NXT.  Please note that the NXT has to be in the firmware update mode.

 

22.   The ExpFcnCalls Scheduler will trigger different functions to be called at a given intervals.  In the case below a single function will be called every 10ms.  If you wanted one function to be called every 10ms and one function to be called every 500ms then the first two parameters would look like this: ‘ddd_10ms’,’ddd_500ms’ and [10 500] and the Task stack size would be [64 64] respectively.

 

23.   Below is inside of the Test_Dan subsystem

 

24.   Below is inside of the Function-Call Subsystem.  Please note that the constant MUST OUTPUT INIT8.  In addition the limits of the inputs are -100 to 100.  Also please note that in the example that the motor is hooked up to Port B.

 

25.   The scope on the root page of the motortest2.mdl is set to NOT limit the data points to the last XXX samples.

 

26.   Press the nxtbuild(‘Test_Dan’,’build’) button ONCE to convert the model into C code and have it compile it into a binary.

27.   Press the nxtbuild(‘Test_Dan’,’ul2ram’) button once to upload the previously compiled code to the ram of the NXT which is in firmware update mode

28.   The servo motor on Port B should now be spilling at 50% maximum speed.