Index: /trunk/publishing/MATLABCentral/Example_5_DriveUntilWall.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_5_DriveUntilWall.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_5_DriveUntilWall.m	(revision 701)
@@ -0,0 +1,93 @@
+%% Example 4: Drive Until Wall
+% In this little demo our robot drives forward until it detects a wall.
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+%% Clean up
+% Close previous handles (if existing)
+COM_CloseNXT all
+clear all
+close all
+
+
+%% Constants
+MaxDriveTime = 30; % in seconds, stop after this time...
+USPort       = SENSOR_4;
+
+
+%% Initialize NXT connection (Bluetooth)
+handle = COM_OpenNXT('bluetooth.ini');
+COM_SetDefaultNXT(handle);
+
+
+%% Reset Motor / remember start position
+ResetMotorAngle(MOTOR_B);
+ResetMotorAngle(MOTOR_C);
+StartPos = GetMotorSettings(MOTOR_B);
+
+
+%% Prepare sensor
+OpenUltrasonic(USPort)
+
+
+%% And GO!
+
+SetMotor(MOTOR_B);
+    SyncToMotor(MOTOR_C);
+    SetPower(60);
+    SetAngleLimit(0);
+    SetTurnRatio(0);
+    SetRampMode ('off');
+SendMotorSettings();
+
+
+%% Detect wall (sensor loop)
+time(1) = tic; 
+while(toc(time(1)) < MaxDriveTime)
+   if GetUltrasonic(USPort) < 30
+       break
+   end%if
+end%while
+
+
+%% Immediately stop all motors!
+StopMotor('all', 'off');
+% but where are we now?
+CurPos = GetMotorSettings(MOTOR_B);
+
+
+%% Signal
+NXT_PlayTone(440, 1000);
+
+
+%% Drive back home!
+% To try to understand what exactly the different rotation count values
+% mean, we compare them just for fun
+TotalAbsDist = StartPos.TachoCount - CurPos.TachoCount;
+Dist         = CurPos.Angle;
+
+SetMotor(MOTOR_B);
+    SyncToMotor(MOTOR_C);
+    SetPower(-60);
+    SetAngleLimit(abs(Dist));
+SendMotorSettings();
+
+
+%% Wait until there
+WaitForMotor(1, MaxDriveTime);
+
+% brake
+StopMotor('all', 'brake');
+
+pause(1);
+
+%% clean up
+CloseSensor(SENSOR_4)
+StopMotor ('all', 'off');
+
+
+%% Close NXT connection
+COM_CloseNXT(handle);
Index: /trunk/publishing/MATLABCentral/Example_7_ShinyRadar.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_7_ShinyRadar.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_7_ShinyRadar.m	(revision 701)
@@ -0,0 +1,176 @@
+%% Example 6: ShinyRadar
+% This function provides a live moving ultrasonic radar.
+%
+% Note: This demo uses an robot with a rotating ultrasonic sensor.
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+function Example_7_ShinyRadar
+
+%% Clean up previous handles
+COM_CloseNXT all
+
+%% Set up Matlab
+clear all % if you use clear all, call COM_CloseNXT all before, as we did!
+close all
+format compact
+
+
+%% Set up ports & vars
+portMotor   = MOTOR_A;
+portUS      = SENSOR_4;
+GearFactor  = 4;
+MotorRange  = 170 * GearFactor;
+MotorSpeed  = 25;
+
+
+%% Initialize GFX
+figure('Name', 'Shiny Radar'); %, 'Position', [50 60 1200 500]);
+axis equal
+axis([-170 170 0 170]); 
+set(gca, 'Color', 'black');
+hold on
+
+
+hScanLine = ResetFigure(false);
+
+
+
+%% Open connection
+h = COM_OpenNXT('bluetooth.ini');
+COM_SetDefaultNXT(h);
+
+
+%% Reset Motor, open sensor
+StopMotor all off
+NXT_ResetMotorPosition(portMotor, false);
+NXT_ResetMotorPosition(portMotor, true);
+
+OpenUltrasonic(portUS);
+
+%% Turn right so start position
+SetMotor(portMotor)
+    SetPower(20)
+    SetAngleLimit(MotorRange/2 - 20)
+SendMotorSettings
+WaitForMotor(portMotor)
+pause(0.5)
+StopMotor(portMotor, 'off');
+
+
+%% First motor go
+tmp = GetMotorSettings(portMotor);
+StartPos = tmp.TachoCount;
+
+SetMotor(portMotor);
+    SetPower(-MotorSpeed);
+    SpeedRegulation on
+    SetAngleLimit(MotorRange);
+SendMotorSettings
+
+
+
+%% Main loop
+while(true)
+    
+    % get current pos
+    tmp = GetMotorSettings(portMotor);
+    CurPos = tmp.TachoCount;
+    phi = pi - ((CurPos - (StartPos - MotorRange)) / MotorRange) * pi;
+    %alpha = phi * 180 / pi
+    %x = cos(phi)
+    %y = sin(phi)
+    
+    % get ultrasonic
+    distUS = GetUltrasonic(portUS);
+
+    
+    % plot where we are
+    set(hScanLine, 'XData', [0; cos(phi) * 150])
+    set(hScanLine, 'YData', [0; sin(phi) * 150]);
+    
+    % plot radar dot
+    if (distUS > 1) && (distUS < 200)
+        plot(cos(phi) * distUS, sin(phi) * distUS, 'g.')
+    end%if
+    
+    
+    drawnow
+    
+    % reverse direction if necessary
+    if CurPos < (StartPos - MotorRange)
+        StopMotor(portMotor, 'off')
+        NXT_ResetMotorPosition(portMotor, false);
+        NXT_ResetMotorPosition(portMotor, true);
+
+        SetMotor(portMotor)
+            SetPower(MotorSpeed)
+            SetAngleLimit(MotorRange)
+        SendMotorSettings
+        
+        hScanLine = ResetFigure(true);
+    end%if
+    
+    % reverse direction if necessary
+    if CurPos > StartPos
+        StopMotor(portMotor, 'off')
+        NXT_ResetMotorPosition(portMotor, false);
+        NXT_ResetMotorPosition(portMotor, true);
+        SetMotor(portMotor)
+            SetPower(-MotorSpeed)
+            SetAngleLimit(MotorRange)
+        SendMotorSettings
+        
+        hScanLine = ResetFigure(false);
+    end%if    
+    
+    
+
+end%while
+
+
+
+%% Clean up
+StopMotor all off
+CloseSensor(portUS);
+
+COM_CloseNXT(h)
+
+
+end%function
+
+
+function hScanNew = ResetFigure(leftTrue)
+
+    cla
+
+%% Plot Radar outlines
+
+    % circles
+    col = [0.3 0.3 0.3];
+    for j = 1 : 3
+        phi = linspace(0, pi, 60) ;% - pi;
+        x = cos(phi) * 50 * j;
+        y = sin(phi) * 50 * j;
+        plot(x, y, '-', 'Color', col)
+    end%for
+
+    % lines
+    len = 160;
+    plot([0; cos(pi/4)*len], [0; sin(pi/4)*len], '-', 'Color', col)
+    plot([0; 0], [0; len], '-', 'Color', col)
+    plot([0; -cos(pi/4)*len], [0; sin(pi/4)*len], '-', 'Color', col)
+
+    % draw scanline again:
+    if leftTrue
+        hScanNew = plot([0; -150], [0; 0], '-r');
+    else
+        hScanNew = plot([0; 150], [0; 0], '-r');
+    end%if
+
+
+    drawnow
+end%function
Index: /trunk/publishing/MATLABCentral/Example_1_PlayTone.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_1_PlayTone.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_1_PlayTone.m	(revision 701)
@@ -0,0 +1,28 @@
+%% Example 1: Play Tone and Get Battery Level
+% Example to play a specific tone with the NXT Brick and retrieve the current battery level: 
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+% Close previous handles (if existing)
+COM_CloseNXT all
+% Prepare workspace by cleaning all old settings to be on the safe side. 
+clear all
+close all
+
+% Open new NXT connection 
+%  - Tries to open a connection via USB. The first NXT device that is found will be used.
+%  - Device drivers (Fantom on Windows, libusb on Linux) have to be already installed for USB to work.
+%  - For using Bluetooth a previous configuration file has to be generated COM_MakeBTConfigFile)
+handle = COM_OpenNXT();
+
+% Play tone with frequency 800Hz and duration of 500ms. 
+NXT_PlayTone(800,500, handle);
+
+% Get current battery level. 
+voltage = NXT_GetBatteryLevel(handle)
+
+% Close NXT connection. 
+COM_CloseNXT(handle);
Index: /trunk/publishing/MATLABCentral/Example_3_DriveAroundTable.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_3_DriveAroundTable.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_3_DriveAroundTable.m	(revision 701)
@@ -0,0 +1,112 @@
+%% Example 3: Drive Around Table (Basic Motor Commands)
+% In this little demo, our bot drives a square on the floor around a well known table.
+%
+% Note: This example uses the basic motor commands, which are based on the LEGO NXT direct commands
+% specified by the LEGO Communication Protocol. For advanced motor control (more precise motor
+% control) and a more intuitive usability we recommend the advanced motor control commands (see
+% example 4).
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+%% Clear and close
+COM_CloseNXT all
+clear all
+close all
+
+
+%% Constants
+TableLength      = 2850; % in degrees of motor rotations :-)
+QuarterTurnTicks = 245;  % in motor degrees, how much is a 90° turn of the bot?
+
+
+%% Open NXT connection (Bluetooth)
+handle = COM_OpenNXT('bluetooth.ini');
+COM_SetDefaultNXT(handle);  % set NXT handle as the default handle
+
+
+%% Initialize Motors...
+% we send this in case they should still be spinning or something...
+StopMotor('all', 'off');
+% and we also "clean up" before we start:
+ResetMotorAngle(MOTOR_B);
+ResetMotorAngle(MOTOR_C);
+
+
+%% Start the engines, main loop begins (repeated 4 times)
+% 4 times because we got 4 equal sides of the table :-)
+for j = 1 : 4
+
+%% Drive
+    SetMotor(MOTOR_B);
+        SyncToMotor(MOTOR_C); % this means we have to set parameters only once
+        SetPower(75);
+        SetAngleLimit(TableLength);
+        SetTurnRatio(0); % straight ahead
+    SendMotorSettings(); % and GO!
+    
+    % let the robot start:
+    pause(1);
+
+%% Check for the end end of table
+    WaitForMotor(GetMotor);
+    
+    % give it a little time to correct its mistakes (hey synchronisation
+    % mode :-)
+    pause(2);
+    
+    % apparently we've stopped!
+    % then release the motors
+    StopMotor('all', 'off');
+    % if we don't do that, syncing again doesn't work
+    
+    % and again, if we don't rest relative counters, synced turning etc doesnt work...
+    ResetMotorAngle(MOTOR_B);
+    ResetMotorAngle(MOTOR_C);
+    
+    
+%% Now please turn 
+
+    SetMotor(MOTOR_B);
+        SyncToMotor(MOTOR_C); % this means we have to set parameters only once
+        SetPower(30) % slower is more acurate
+        SetAngleLimit(QuarterTurnTicks);
+        SetTurnRatio(100) % turn right
+    SendMotorSettings();  % and GO!
+
+    % leave the bot time to start turning
+    pause(1);
+    
+%% Check for the end of rotation
+
+    WaitForMotor(GetMotor);
+    
+    % give it a little time to correct its mistakes (hey synchronisation mode :-)
+    pause(2);
+    
+    % apparently we've stopped!
+    % then release the motors
+    StopMotor('all', 'off');
+    % if we don't do that, syncing again doesn't work
+    
+    % and again, if we don't rest relative counters, synced turning etc doesnt work...
+    ResetMotorAngle(MOTOR_B);
+    ResetMotorAngle(MOTOR_C);
+    
+%% Thats it. Repeat 4 times....
+end%for
+
+
+% Hey! End of a hard day's work
+% Just to show good style, we close down our motors again:
+StopMotor('all', 'off');
+% although this was completely unnecessary....
+
+% nice
+
+
+%% Close Bluetooth
+
+COM_CloseNXT(handle);
Index: /trunk/publishing/MATLABCentral/FileExchangeDescription.txt
===================================================================
--- /trunk/publishing/MATLABCentral/FileExchangeDescription.txt	(revision 614)
+++ /trunk/publishing/MATLABCentral/FileExchangeDescription.txt	(revision 701)
@@ -14,6 +14,5 @@
 http://www.lfb.rwth-aachen.de/mindstorms
 
-The sources of the RWTH - Mindstorms NXT Toolbox are also provided by a SVN repository which is located on the open source project page
-http://www.mindstorms.rwth-aachen.de
+Because of license issues the sources of the RWTH - Mindstorms NXT Toolbox (GPL) are hosted at project page http://www.mindstorms.rwth-aachen.de
 
 
@@ -24,8 +23,8 @@
 
 5. MATLAB release:
-MATLAB 7.3 (R2006b)
+MATLAB 7.7 (R2008b)
 
 
 6. Other requirements:
-Windows or Linux; LEGO® MINDSTORMS® NXT building kit; LEGO® MINDSTORMS® NXT firmware v1.05 (recommended); Bluetooth 2.0 adapter recommended model by LEGO® (e.g. AVM BlueFRITZ! USB) supporting the serial port profile (SPP) or USB cable.
+Windows or Linux; LEGO® MINDSTORMS® NXT building kit; LEGO® MINDSTORMS® NXT firmware v1.26 (recommended); Bluetooth 2.0 adapter recommended model by LEGO® (e.g. AVM BlueFRITZ! USB) supporting the serial port profile (SPP) or USB cable.
 
Index: /trunk/publishing/MATLABCentral/Example_2_ReadSoundSensor.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_2_ReadSoundSensor.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_2_ReadSoundSensor.m	(revision 701)
@@ -0,0 +1,31 @@
+%% Example 2: Read Sound Sensor
+% Example to read the sound sensor value in db:
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+% Close previous handles (if existing)
+COM_CloseNXT all
+% Prepare workspace by cleaning all old settings to be on the safe side. 
+clear all
+close all
+
+% Open new NXT Bluetooth connection according to the previous generated configuration file.
+handle = COM_OpenNXT('bluetooth.ini');
+
+% Set current NXT handle as default for subsequent toolbox function calls
+COM_SetDefaultNXT(handle);
+
+% Initialize the sound sensor by setting the sound sensor mode and input port. 
+OpenSound(SENSOR_2, 'DB');
+
+% Get the current sound sensor value in dB. 
+value = GetSound(SENSOR_2)
+
+% Close the sound sensor. 
+CloseSensor(SENSOR_2);
+
+% Close Bluetooth connection. 
+COM_CloseNXT(handle);
Index: /trunk/publishing/MATLABCentral/Example_6_NextGenerationUltrasound.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_6_NextGenerationUltrasound.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_6_NextGenerationUltrasound.m	(revision 701)
@@ -0,0 +1,80 @@
+%% Example 5: Next Generation Ultrasound
+% This script demonstrates the results of the ultrasound "snapshot mode"!
+% Interpretation of the results however is difficult.
+%
+% Just connect an NXT to the USB port, adjust the US port (or connect it to
+% SENSOR_2), and see what's happening. The script will exit after 200
+% measurements...
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+%% Clean up
+% Close previous handles (if existing)
+COM_CloseNXT all
+
+%% Set up Matlab
+clear all
+close all
+format compact
+
+
+%% Set up ports
+portUS      = SENSOR_2;
+
+
+%% Get USB handle
+COM_CloseNXT all
+h = COM_OpenNXT();
+COM_SetDefaultNXT(h);
+
+
+%% Lets go then!
+figure('name', 'Next Generation Ultrasound')
+set(gca, 'Color', 'black');
+hold on
+
+
+OpenUltrasonic(portUS, 'snapshot')
+
+n          = 8;         % bytes the US sensor received
+count      = 200;       % how many readings until end?
+plotcols   = 8;         % how many out of n echos to plot?
+outOfRange = 160;       % setting for out of range readings
+
+colors = flipud(hot(8));
+
+data = zeros(1, n); 
+allX = (1:count+1)';
+
+
+for i = 1 : count
+    USMakeSnapshot(portUS)
+    pause(0.05);            % wait for the sound to travel
+    echos = USGetSnapshotResults(portUS);
+
+    echos(echos == 255) = outOfRange;
+
+    echos = [echos(1); diff(echos)];
+
+    data = vertcat(data, echos');
+    x = allX(1:i+1);
+    
+    clf
+    hold on
+    set(gca, 'Color', 'black');
+    
+    axis([0 count 0 outOfRange])
+
+    for j = plotcols : -1 : 1
+        area(x, data(:, j) , 'FaceColor', colors(j, :))
+    end
+    
+end%for
+
+
+%% Clean up
+CloseSensor(portUS)
+COM_CloseNXT(h);
Index: /trunk/publishing/MATLABCentral/Example_4_DriveAroundTable_MotorClass.m
===================================================================
--- /trunk/publishing/MATLABCentral/Example_4_DriveAroundTable_MotorClass.m	(revision 701)
+++ /trunk/publishing/MATLABCentral/Example_4_DriveAroundTable_MotorClass.m	(revision 701)
@@ -0,0 +1,94 @@
+%% Example 7: Drive Around Table (Motor Class)
+% This example equals demo 3, but uses the motor class and an advanced motor control.
+%
+% Note: For using the advanced motor control the MotorControl program has to be downloaded onto your
+% NXT. The MotorControl program is located at /tools/MotorControl.
+%
+% Signature
+%   Author: Linus Atorf, Alexander Behrens
+%   Date: 2009/07/17
+%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
+
+%% Clear and close
+COM_CloseNXT all
+clear all
+close all
+
+
+%% Constants and so on
+TableLength      = 1000;     % in degrees of motor rotations :-)
+QuarterTurnTicks = 217;      % in motor degrees, how much is a 90° turn of the bot?
+Ports = [MOTOR_B; MOTOR_C];  % motorports for left and right wheel
+DrivingSpeed     = 50;
+TurningSpeed     = 30;
+
+
+%% Open Bluetooth connetion
+h = COM_OpenNXT('bluetooth.ini');
+COM_SetDefaultNXT(h);
+
+
+%% Initialize motor-objects:
+
+mStraight                   = NXTMotor(Ports);
+% next command since we are driving in SYNC-mode. This should not be
+% necessary with correct default values, but at the moment, I have to set
+% it manually,
+mStraight.SpeedRegulation   = false;  % not for sync mode
+mStraight.Power             = DrivingSpeed;
+mStraight.TachoLimit        = TableLength;
+mStraight.BrakeAtTachoLimit = true;
+
+
+mTurn1                      = NXTMotor(Ports(2)); % ports swapped because it's nicer
+mTurn1.SpeedRegulation      = true;  
+mTurn1.Power                = TurningSpeed;
+mTurn1.TachoLimit           = QuarterTurnTicks;
+mTurn1.BrakeAtTachoLimit    = true;
+
+
+mTurn2          = mTurn1;
+mTurn2.Port     = Ports(1);   % ports swapped again...
+mTurn2.Power    = - mTurn1.Power;
+
+
+
+%% Initialize Motors...
+% we send this in case they should still be spinning or something...
+mStraight.Stop('off');
+
+
+%% Start the engines, main loop begins (repeated 4 times)
+
+% 4 times because we got 4 equal sides of the table :-)
+for j = 1 : 4
+
+%% Drive
+
+    mStraight.SendToNXT();
+    
+    
+%% Check for the end end of table
+   	mStraight.WaitFor();
+    
+%% Now please turn 
+
+    mTurn1.SendToNXT();
+    mTurn1.WaitFor();
+    
+    mTurn2.SendToNXT();
+    mTurn2.WaitFor();
+    
+    
+%% Thats it. Repeat 4 times....
+end%for
+
+
+
+% Hey! End of a hard day's work
+% Just to show good style, we close down our motors again:
+mStraight.Stop('off');
+
+
+%% Close Bluetooth connection
+COM_CloseNXT(h);
