<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: LEGO Mindstorms NXT in Teaching</title>
	<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/</link>
	<description>Loren Shure  works on design of the MATLAB language at &#60;a href="http://www.mathworks.com/"&#62;The MathWorks&#60;/a&#62;. She writes here about once a week on MATLAB programming and related topics. &#60;br&#62;&#60;br&#62;&#60;a href="/images/loren-full.jpg"&#62;&#60;img src="/images/loren.jpg"&#62;&#60;/a&#62;</description>
	<pubDate>Sun, 22 Nov 2009 23:12:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: Linus Atorf</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30557</link>
		<dc:creator>Linus Atorf</dc:creator>
		<pubDate>Thu, 27 Aug 2009 22:29:14 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30557</guid>
		<description>Dear Michele!

Thank you for your comments. It seems you've got a little version mix-up.

The toolbox 2.03 (and 2.04) uses MotorControl.rxe. The version displayed on your NXT screen should be MotorControl 1.1 (or 1.2). With this toolbox, you need to have the LEGO MINDSTORMS NXT Firmware version 1.05 installed.
So far so good. The motor class in this version is called NXTmotor (note the lowercase m). Motor precision and performance is alright, but not great.



The warning you describe (no reply time out in .WaitFor) has only been introduced in toolbox version 4.00. This version offers far better motor control. For this version, MotorControl20.rxe is required. It's called this way intentionally by COM_OpenNXTEx to distinguish from previous versions (so renaming files doesn't help). In order to compile MotorControl20.nxc, you need nbc.exe from the very latest version from BricxCC, included in the file test_release.zip, found here: http://bricxcc.sourceforge.net/
You can also find the MotorControl20.rxe binary here: http://www.mindstorms.rwth-aachen.de/trac/browser/trunk/tools/MotorControl/MotorControl20.rxe

Please note that MotorControl 2.* needs the newest LEGO MINDSTORMS NXT Firmware. Either 1.26 (comes with NXT-G Education 2.0), 1.27 or 1.28 by John Hansen (included in the mentioned test_release.zip from BricxCC) or 1.28 (comes with the new NXT 2.0 retail building kit).


So please don't mix up different versions of the toolbox with different versions of MotorControl. Always take the MotorControl version which comes with the according toolbox zipfile. You can find out the toolbox you're using (set in the MATLAB path) by typing:&lt;pre&gt;info = ver('RWTHMindstormsNXT')
&lt;/pre&gt;


With toolbox 4.00, the motor class is called NXTMotor (uppercase M) by the way.


So I hope I've clarfied eveything. The high pitched beeping noise you describe is intended. It's the NXT's synchronization. It should be mentioned somewhere inside the chapter "Troubleshooting" of the toolbox documentation I believe. I've also added a description of this "feature" in the new documentation for future version 4.01. It keeps the motors in sync, useful for straight driving. It can be disabled using .Stop or .StopMotor.


The next toolbox release 4.01 is scheduled for next week. With this release we'll also officially support Mac OS. The motor control in 4.00 (beta) works ok, we fixed some minor issues for 4.01, but overall 4.00 is pretty stable and should be well usable.

Don't hesitate to ask further questions. Keep watching http://www.mindstorms.rwth-aachen.de for future versions, and feel free to open a ticket with feature requests or bug reports if needed.

Regards, Linus</description>
		<content:encoded><![CDATA[<p>Dear Michele!</p>
<p>Thank you for your comments. It seems you&#8217;ve got a little version mix-up.</p>
<p>The toolbox 2.03 (and 2.04) uses MotorControl.rxe. The version displayed on your NXT screen should be MotorControl 1.1 (or 1.2). With this toolbox, you need to have the LEGO MINDSTORMS NXT Firmware version 1.05 installed.<br />
So far so good. The motor class in this version is called NXTmotor (note the lowercase m). Motor precision and performance is alright, but not great.</p>
<p>The warning you describe (no reply time out in .WaitFor) has only been introduced in toolbox version 4.00. This version offers far better motor control. For this version, MotorControl20.rxe is required. It&#8217;s called this way intentionally by COM_OpenNXTEx to distinguish from previous versions (so renaming files doesn&#8217;t help). In order to compile MotorControl20.nxc, you need nbc.exe from the very latest version from BricxCC, included in the file test_release.zip, found here: <a href="http://bricxcc.sourceforge.net/" rel="nofollow">http://bricxcc.sourceforge.net/</a><br />
You can also find the MotorControl20.rxe binary here: <a href="http://www.mindstorms.rwth-aachen.de/trac/browser/trunk/tools/MotorControl/MotorControl20.rxe" rel="nofollow">http://www.mindstorms.rwth-aachen.de/trac/browser/trunk/tools/MotorControl/MotorControl20.rxe</a></p>
<p>Please note that MotorControl 2.* needs the newest LEGO MINDSTORMS NXT Firmware. Either 1.26 (comes with NXT-G Education 2.0), 1.27 or 1.28 by John Hansen (included in the mentioned test_release.zip from BricxCC) or 1.28 (comes with the new NXT 2.0 retail building kit).</p>
<p>So please don&#8217;t mix up different versions of the toolbox with different versions of MotorControl. Always take the MotorControl version which comes with the according toolbox zipfile. You can find out the toolbox you&#8217;re using (set in the MATLAB path) by typing:
<pre>info = ver('RWTHMindstormsNXT')
</pre>
</p><p>With toolbox 4.00, the motor class is called NXTMotor (uppercase M) by the way.</p>
<p>So I hope I&#8217;ve clarfied eveything. The high pitched beeping noise you describe is intended. It&#8217;s the NXT&#8217;s synchronization. It should be mentioned somewhere inside the chapter &#8220;Troubleshooting&#8221; of the toolbox documentation I believe. I&#8217;ve also added a description of this &#8220;feature&#8221; in the new documentation for future version 4.01. It keeps the motors in sync, useful for straight driving. It can be disabled using .Stop or .StopMotor.</p>
<p>The next toolbox release 4.01 is scheduled for next week. With this release we&#8217;ll also officially support Mac OS. The motor control in 4.00 (beta) works ok, we fixed some minor issues for 4.01, but overall 4.00 is pretty stable and should be well usable.</p>
<p>Don&#8217;t hesitate to ask further questions. Keep watching <a href="http://www.mindstorms.rwth-aachen.de" rel="nofollow">http://www.mindstorms.rwth-aachen.de</a> for future versions, and feel free to open a ticket with feature requests or bug reports if needed.</p>
<p>Regards, Linus</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michele</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30547</link>
		<dc:creator>Michele</dc:creator>
		<pubDate>Wed, 26 Aug 2009 01:11:08 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30547</guid>
		<description>Hi Gautam,

I am using version 2.03 of the RWTH - Mindstorms NXT Toolbox on a MacBook and Matlab 7.6.  I am able to communicate via bluetooth. I can play a note and read from the sensors.  I am having trouble with the motors.   I have uploaded the MotorControl.rxe file to the NXT.    

If I run
&lt;pre&gt;
handle = COM_OpenNXT('bluetooth.ini');
&lt;/pre&gt;
the MotorControl.rxe program on the NXT is executed.   

If I then run
&lt;pre&gt;
COM_SetDefaultNXT(handle);
m = NXTMotor('A', 'Power', 50, 'TachoLimit', 1000);
m.SendToNXT(handle);
timedOut = WaitFor(m, 5);
&lt;/pre&gt;


I get the following warning:
&lt;pre&gt;
Warning: There has been no reply (time out) for at least 5 seconds from the
embedded NXC program MotorControl, which should be running on the NXT
brick. Please make sure the program is running and does not get terminated
accidentally. Exiting WaitFor() and continuing...
&#62; In NXTMotor.WaitFor at 168
&lt;/pre&gt;


Coincidentally, the file COM_NXTOpenNXTEx.m was using MotorControl20.rxe instead of MotorControl.rxe.  I changed this in the m-file back to MotorControl.rxe. No luck.   Next, I left the MotorControl20.rxe in the m-file and changed the name of the file on the NXT.  That didn't work either.  I tried this because I wasn't sure which m-files actually use the filename on the NXT.

I have used the DirectMotorCommand to get the motors to turn.  The motors don't rotate to the programmed value.  Also, the NXT makes high-pitched noises afterwards until I turn the NXT off. 
 
I'd like to use the NXTMotor functions rather than the DirectMotorCommand function.  

Any advice for me?

Thanks,
Michele</description>
		<content:encoded><![CDATA[<p>Hi Gautam,</p>
<p>I am using version 2.03 of the RWTH - Mindstorms NXT Toolbox on a MacBook and Matlab 7.6.  I am able to communicate via bluetooth. I can play a note and read from the sensors.  I am having trouble with the motors.   I have uploaded the MotorControl.rxe file to the NXT.    </p>
<p>If I run</p>
<pre>
handle = COM_OpenNXT('bluetooth.ini');
</pre>
<p>the MotorControl.rxe program on the NXT is executed.   </p>
<p>If I then run</p>
<pre>
COM_SetDefaultNXT(handle);
m = NXTMotor('A', 'Power', 50, 'TachoLimit', 1000);
m.SendToNXT(handle);
timedOut = WaitFor(m, 5);
</pre>
<p>I get the following warning:</p>
<pre>
Warning: There has been no reply (time out) for at least 5 seconds from the
embedded NXC program MotorControl, which should be running on the NXT
brick. Please make sure the program is running and does not get terminated
accidentally. Exiting WaitFor() and continuing...
&gt; In NXTMotor.WaitFor at 168
</pre>
<p>Coincidentally, the file COM_NXTOpenNXTEx.m was using MotorControl20.rxe instead of MotorControl.rxe.  I changed this in the m-file back to MotorControl.rxe. No luck.   Next, I left the MotorControl20.rxe in the m-file and changed the name of the file on the NXT.  That didn&#8217;t work either.  I tried this because I wasn&#8217;t sure which m-files actually use the filename on the NXT.</p>
<p>I have used the DirectMotorCommand to get the motors to turn.  The motors don&#8217;t rotate to the programmed value.  Also, the NXT makes high-pitched noises afterwards until I turn the NXT off. </p>
<p>I&#8217;d like to use the NXTMotor functions rather than the DirectMotorCommand function.  </p>
<p>Any advice for me?</p>
<p>Thanks,<br />
Michele</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Linus Atorf</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30499</link>
		<dc:creator>Linus Atorf</dc:creator>
		<pubDate>Thu, 30 Jul 2009 19:06:30 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30499</guid>
		<description>Hello,

I'd like to respond to some issues brought up in the comments here:

&lt;b&gt;Bluetooth&lt;/b&gt;
Not all Bluetooth adapters you can buy work equally well with the NXT or with MATLAB. We tested some, and here's the (incomplete) list as a guide:
http://www.mindstorms.rwth-aachen.de/trac/wiki/BluetoothAdapter

&lt;b&gt;Motor precision&lt;/b&gt;
Since version 2.03 of the RWTH - Mindstorms NXT Toolbox, a way for better precision is provided. While the official NXT firmware (and previous toolbox versions) don't provide a way to rotate a motor to a precise angle with a single command (like e.g. 90 degrees and then stop), we added this feature by a program running on the NXT simultaneously. So give version 2.03 a try and use the &lt;i&gt;NXTmotor&lt;/i&gt; class.

Even better motor control is added with the latest version 4.00 (beta), only 10 days old :-). While it might be unstable, first results show a really great way to control motors accurately (the class is now called &lt;i&gt;NXTMotor&lt;/i&gt;). Try out the latest version and see if it works for you:
http://www.mindstorms.rwth-aachen.de/trac/wiki/Download

&lt;b&gt;Gyro Sensor&lt;/b&gt;
Make sure to use either version 2.04 (of the RWTH - Mindstorms NXT toolbox) or the beta 4.00, as version 2.03 has limited support for the Gyro sensor (no good calibration, only 1 sensor allowed) which is fixed in later versions.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I&#8217;d like to respond to some issues brought up in the comments here:</p>
<p><b>Bluetooth</b><br />
Not all Bluetooth adapters you can buy work equally well with the NXT or with MATLAB. We tested some, and here&#8217;s the (incomplete) list as a guide:<br />
<a href="http://www.mindstorms.rwth-aachen.de/trac/wiki/BluetoothAdapter" rel="nofollow">http://www.mindstorms.rwth-aachen.de/trac/wiki/BluetoothAdapter</a></p>
<p><b>Motor precision</b><br />
Since version 2.03 of the RWTH - Mindstorms NXT Toolbox, a way for better precision is provided. While the official NXT firmware (and previous toolbox versions) don&#8217;t provide a way to rotate a motor to a precise angle with a single command (like e.g. 90 degrees and then stop), we added this feature by a program running on the NXT simultaneously. So give version 2.03 a try and use the <i>NXTmotor</i> class.</p>
<p>Even better motor control is added with the latest version 4.00 (beta), only 10 days old :-). While it might be unstable, first results show a really great way to control motors accurately (the class is now called <i>NXTMotor</i>). Try out the latest version and see if it works for you:<br />
<a href="http://www.mindstorms.rwth-aachen.de/trac/wiki/Download" rel="nofollow">http://www.mindstorms.rwth-aachen.de/trac/wiki/Download</a></p>
<p><b>Gyro Sensor</b><br />
Make sure to use either version 2.04 (of the RWTH - Mindstorms NXT toolbox) or the beta 4.00, as version 2.03 has limited support for the Gyro sensor (no good calibration, only 1 sensor allowed) which is fixed in later versions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30497</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Thu, 30 Jul 2009 15:41:50 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30497</guid>
		<description>Hi Hidir,

I assume you are referring to Bluetooth interface.

You can get both the gyroscope and accelerometer data using the &lt;a href="http://www.mindstorms.rwth-aachen.de/trac/wiki/Download" rel="nofollow"&gt;RWTH Aachen Mindstorms NXT Toolbox&lt;/a&gt; (see the GetAccelerator and GetGyro functions).  

Getting the time information is tricky. With the Bluetooth interface, it is difficult to get the time at which the gyro or acceleration value was sensed. The simplest solution is probably something like the following:

&lt;pre&gt;
  % This example uses the RWTH Aachen Mindstorms NXT Toolbox
  tic; % start of measurement
  OpenGyro(SENSOR_1);
  for i=1:100
    sensorValue(i) = GetGyro(SENSOR_1);
    timeStamp(i) = toc;
    pause(0.1);
  end
  CloseSensor(SENSOR_1);
&lt;/pre&gt;


Gautam</description>
		<content:encoded><![CDATA[<p>Hi Hidir,</p>
<p>I assume you are referring to Bluetooth interface.</p>
<p>You can get both the gyroscope and accelerometer data using the <a href="http://www.mindstorms.rwth-aachen.de/trac/wiki/Download" rel="nofollow">RWTH Aachen Mindstorms NXT Toolbox</a> (see the GetAccelerator and GetGyro functions).  </p>
<p>Getting the time information is tricky. With the Bluetooth interface, it is difficult to get the time at which the gyro or acceleration value was sensed. The simplest solution is probably something like the following:</p>
<pre>
  % This example uses the RWTH Aachen Mindstorms NXT Toolbox
  tic; % start of measurement
  OpenGyro(SENSOR_1);
  for i=1:100
    sensorValue(i) = GetGyro(SENSOR_1);
    timeStamp(i) = toc;
    pause(0.1);
  end
  CloseSensor(SENSOR_1);
</pre>
<p>Gautam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HIDIR</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30494</link>
		<dc:creator>HIDIR</dc:creator>
		<pubDate>Thu, 30 Jul 2009 07:07:23 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30494</guid>
		<description>how can I get the time information together with the gyro or accelerometer data?
Thanks</description>
		<content:encoded><![CDATA[<p>how can I get the time information together with the gyro or accelerometer data?<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30457</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Mon, 06 Jul 2009 15:24:58 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30457</guid>
		<description>Hi Dhruba,

If you want to control the LEGO NXT from MATLAB using Bluetooth, there is NO need to change the standard firmware.

If you want to generate an executable that will run autonomously on the LEGO NXT (using the &lt;a href="http://www.mathworks.com/matlabcentral/fileexchange/13399" rel="nofollow"&gt;Simulink-based library&lt;/a&gt;) then you will need to change the firmware (the library comes with instructions for how to do this). Updating the firmware -- and switching back to the standard firmware -- is usually pretty safe, and is common in many LEGO NXT programming environments.

Gautam</description>
		<content:encoded><![CDATA[<p>Hi Dhruba,</p>
<p>If you want to control the LEGO NXT from MATLAB using Bluetooth, there is NO need to change the standard firmware.</p>
<p>If you want to generate an executable that will run autonomously on the LEGO NXT (using the <a href="http://www.mathworks.com/matlabcentral/fileexchange/13399" rel="nofollow">Simulink-based library</a>) then you will need to change the firmware (the library comes with instructions for how to do this). Updating the firmware &#8212; and switching back to the standard firmware &#8212; is usually pretty safe, and is common in many LEGO NXT programming environments.</p>
<p>Gautam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhruba</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30453</link>
		<dc:creator>Dhruba</dc:creator>
		<pubDate>Mon, 06 Jul 2009 02:56:14 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30453</guid>
		<description>I am using Mindstorm NXT can I run from MATLAB. If so, do I have to earse the firmware and how do I switch back to Mindstorm NXT. While changing the firmware is there a possibilty of damaging the brick.

Regards,
Dhruba</description>
		<content:encoded><![CDATA[<p>I am using Mindstorm NXT can I run from MATLAB. If so, do I have to earse the firmware and how do I switch back to Mindstorm NXT. While changing the firmware is there a possibilty of damaging the brick.</p>
<p>Regards,<br />
Dhruba</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30380</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Thu, 11 Jun 2009 17:42:20 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30380</guid>
		<description>Correction -- In Step 3 of my Simulink example, the expression in the MATLAB Fcn block should be "setMotorPower(leftMotor,u)"

Gautam</description>
		<content:encoded><![CDATA[<p>Correction &#8212; In Step 3 of my Simulink example, the expression in the MATLAB Fcn block should be &#8220;setMotorPower(leftMotor,u)&#8221;</p>
<p>Gautam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gautam Vallabha</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30379</link>
		<dc:creator>Gautam Vallabha</dc:creator>
		<pubDate>Thu, 11 Jun 2009 16:42:38 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30379</guid>
		<description>Eduard,

You can use the RWTH functionality from Simulink. I will go through the example with the MATLAB toolbox from my post, but you can use the same approach for the RWTH toolbox functions. 

&lt;b&gt;Step 1&lt;/b&gt;: in MATLAB set up the connection to the LEGO NXT and configure the sensors:
&lt;pre&gt;
 lego = legoNXT('COM40');
 mySensor = lego.Port1;
 set(mySensor, 'Type','Touch');
 leftMotor = lego.PortA;
&lt;/pre&gt;


&lt;b&gt;Step 2&lt;/b&gt;: To read the sensor in Simulink, add a "MATLAB Fcn" block to your model. For the MATLAB expression, enter "getdata(mySensor)". Wire the input port of the MATLAB Fcn block to Ground. You can group the Fcn and Ground blocks as a subsystem that pumps out sensor values. 

&lt;b&gt;Step 3&lt;/b&gt;: To control the motor in Simulink, add another "MATLAB Fcn" block. For the MATLAB expression, enter " setMotorPower(legoMotor,u)", where setMotorPower is the following MATLAB function: 
&lt;pre&gt;
function out = setMotorPower(motorObj, powerValue)
  set(motorObj, 'power', powerValue);
  out = 0;
&lt;/pre&gt;
(You need a separate function because the MATLAB Fcn block requires an output, but the SET command doesn't return one). Finally, wire the output port of the MATLAB Fcn block to a terminator. You can group the Fcn and terminator blocks as a subsystem that accepts a motor power setting.  You can create another such subsystem for starting/stopping the motor.

&lt;b&gt;Step 4&lt;/b&gt;: Configure your model (using the "Configuration Parameters ..." dialog box) to use a Fixed-step discrete solver. Now, you need to run your model in real time rather than simulated time (for example, you want to poll the sensor every 200 msec or so). To achieve this, you need a block which forces the simulation to match elapsed time. If you have the Aerospace Blockset, you can use the "Simulation Pace" block. Otherwise, try the following submissions in the MATLAB Central FileExchange:
&lt;a href="http://www.mathworks.com/matlabcentral/fileexchange/4868" rel="nofollow"&gt;Pseudo Real Time in Simulink&lt;/a&gt;
&lt;a href="http://www.mathworks.com/matlabcentral/fileexchange/3175" rel="nofollow"&gt;Real-Time Blockset 7.1 for Simulink&lt;/a&gt;

You can improve this lots of ways, of course. For example, you can mask your "read sensor" and "set motor power" subsystems and allow the user to specify different sensor/motor ports. Or, you can include the the initialization code as part of another MATLAB Fcn block. But the above steps should be sufficient to get you started.

Gautam</description>
		<content:encoded><![CDATA[<p>Eduard,</p>
<p>You can use the RWTH functionality from Simulink. I will go through the example with the MATLAB toolbox from my post, but you can use the same approach for the RWTH toolbox functions. </p>
<p><b>Step 1</b>: in MATLAB set up the connection to the LEGO NXT and configure the sensors:</p>
<pre>
 lego = legoNXT('COM40');
 mySensor = lego.Port1;
 set(mySensor, 'Type','Touch');
 leftMotor = lego.PortA;
</pre>
<p><b>Step 2</b>: To read the sensor in Simulink, add a &#8220;MATLAB Fcn&#8221; block to your model. For the MATLAB expression, enter &#8220;getdata(mySensor)&#8221;. Wire the input port of the MATLAB Fcn block to Ground. You can group the Fcn and Ground blocks as a subsystem that pumps out sensor values. </p>
<p><b>Step 3</b>: To control the motor in Simulink, add another &#8220;MATLAB Fcn&#8221; block. For the MATLAB expression, enter &#8221; setMotorPower(legoMotor,u)&#8221;, where setMotorPower is the following MATLAB function: </p>
<pre>
function out = setMotorPower(motorObj, powerValue)
  set(motorObj, 'power', powerValue);
  out = 0;
</pre>
<p>(You need a separate function because the MATLAB Fcn block requires an output, but the SET command doesn&#8217;t return one). Finally, wire the output port of the MATLAB Fcn block to a terminator. You can group the Fcn and terminator blocks as a subsystem that accepts a motor power setting.  You can create another such subsystem for starting/stopping the motor.</p>
<p><b>Step 4</b>: Configure your model (using the &#8220;Configuration Parameters &#8230;&#8221; dialog box) to use a Fixed-step discrete solver. Now, you need to run your model in real time rather than simulated time (for example, you want to poll the sensor every 200 msec or so). To achieve this, you need a block which forces the simulation to match elapsed time. If you have the Aerospace Blockset, you can use the &#8220;Simulation Pace&#8221; block. Otherwise, try the following submissions in the MATLAB Central FileExchange:<br />
<a href="http://www.mathworks.com/matlabcentral/fileexchange/4868" rel="nofollow">Pseudo Real Time in Simulink</a><br />
<a href="http://www.mathworks.com/matlabcentral/fileexchange/3175" rel="nofollow">Real-Time Blockset 7.1 for Simulink</a></p>
<p>You can improve this lots of ways, of course. For example, you can mask your &#8220;read sensor&#8221; and &#8220;set motor power&#8221; subsystems and allow the user to specify different sensor/motor ports. Or, you can include the the initialization code as part of another MATLAB Fcn block. But the above steps should be sufficient to get you started.</p>
<p>Gautam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eduard</title>
		<link>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30377</link>
		<dc:creator>Eduard</dc:creator>
		<pubDate>Wed, 10 Jun 2009 09:19:17 +0000</pubDate>
		<guid>http://blogs.mathworks.com/loren/2008/06/30/lego-mindstorms-nxt-in-teaching/#comment-30377</guid>
		<description>Hi Gautam,
is there any way to control my nxt by simulink simultanously without downloading the file to my nxt. By using the rwth Mindstorms code in matlab it works fine. And I also use the ecrobot nxt Toolbox, but here I have to download the file to my nxt first before running the programm.
Is there any way to use the rwth codes in Simulink?
Thank You</description>
		<content:encoded><![CDATA[<p>Hi Gautam,<br />
is there any way to control my nxt by simulink simultanously without downloading the file to my nxt. By using the rwth Mindstorms code in matlab it works fine. And I also use the ecrobot nxt Toolbox, but here I have to download the file to my nxt first before running the programm.<br />
Is there any way to use the rwth codes in Simulink?<br />
Thank You</p>
]]></content:encoded>
	</item>
</channel>
</rss>
