Changeset 303
- Timestamp:
- 09/25/08 16:51:10 (5 years ago)
- Location:
- branches/atorf/RWTHMindstormsNXT
- Files:
-
- 14 modified
-
COM_ReadI2C.m (modified) (2 diffs)
-
CalibrateCompass.m (modified) (3 diffs)
-
GetCompass.m (modified) (1 diff)
-
GetUltrasonic.m (modified) (1 diff)
-
MotorRotateAbs.m (modified) (5 diffs)
-
NXT_LSRead.m (modified) (2 diffs)
-
NXT_MessageWrite.m (modified) (2 diffs)
-
OpenAccelerator.m (modified) (6 diffs)
-
OpenCompass.m (modified) (6 diffs)
-
OpenInfrared.m (modified) (4 diffs)
-
OpenLight.m (modified) (4 diffs)
-
OpenSound.m (modified) (4 diffs)
-
OpenSwitch.m (modified) (4 diffs)
-
OpenUltrasonic.m (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/atorf/RWTHMindstormsNXT/COM_ReadI2C.m
r293 r303 30 30 % many other sensors, the "data section" starts at 0x42 (66 in decimal). 31 31 % 32 % As last argument you can pass a valid NXT-handle to be used fromthis32 % As last argument you can pass a valid NXT-handle to be used by this 33 33 % function. If no handle is passed, the default set by 34 % |COM_SetDefaultNXT will be used.35 % 36 % *Returns:* |ReturnBytes|, byte-array (column vector) of uint8 34 % |COM_SetDefaultNXT| will be used. 35 % 36 % *Returns:* |ReturnBytes|, byte-array (column vector) of uint8. 37 37 % This array contains the raw sensor-data you requested. How to 38 38 % interpret them depends on the sensor. If communication failed (even … … 169 169 % note that we suppress statusbyte-error-warnings by requesting the 170 170 % 3rd optional output argument of NXT_LSRead() 171 [data BytesRead status] = NXT_LSRead(Port );171 [data BytesRead status] = NXT_LSRead(Port, handle); 172 172 173 173 -
branches/atorf/RWTHMindstormsNXT/CalibrateCompass.m
r299 r303 1 1 function [ok] = CalibrateCompass(port, f_start, varargin) 2 % Enables orcalibration mode of the HiTechnic compass sensor2 % Enables calibration mode of the HiTechnic compass sensor 3 3 % 4 4 % Syntax … … 26 26 % 27 27 % Example 28 % 28 % 29 % 30 %+ % compass must be open for calibration 31 %+ OpenCompass(SENSOR_2); 32 %+ 29 33 %+ % enable calibration mode 30 34 %+ CalibrateCompass(SENSOR_2, true); … … 41 45 %+ CalibrateCompass(SENSOR_2, false); 42 46 % 43 % See also: OpenCompass, CloseSensor, NXT_LSRead, NXT_LSWrite47 % See also: OpenCompass, GetCompass, CloseSensor, NXT_LSRead, NXT_LSWrite 44 48 % 45 49 % Signature -
branches/atorf/RWTHMindstormsNXT/GetCompass.m
r299 r303 26 26 %+ CloseSensor(SENSOR_4); 27 27 % 28 % See also: OpenCompass, CalibrateCompass CloseSensor, COM_ReadI2C28 % See also: OpenCompass, CalibrateCompass, CloseSensor, COM_ReadI2C 29 29 % 30 30 % Signature -
branches/atorf/RWTHMindstormsNXT/GetUltrasonic.m
r299 r303 10 10 % |distance = GetUltraSonic(port)| returns the current measurement value |distance| of the NXT 11 11 % ultrasonic sensor. |distance| represents the measured distance in cm. 12 % If no echo can be detected (which could indicate that either there is 13 % no obstacle in the way, or the ultrasound does not get reflected, e.g. 14 % by fur-like surfaces), the reading will be 255. If no measurement can 15 % be made (defect sensor, cable disconnected, etc.), a value of -1 will 16 % be returned. 17 % 12 18 % The given |port| number specifies the connection port. The value |port| can be 13 19 % addressed by the symbolic constants |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to -
branches/atorf/RWTHMindstormsNXT/MotorRotateAbs.m
r123 r303 1 function MotorRotateAbs(whatmotor,abs_angle,power )1 function MotorRotateAbs(whatmotor,abs_angle,power, varargin) 2 2 % Rotates a motor to an absolute angle 3 3 % 4 4 % Syntax 5 5 % |MotorRotateAbs(port,abs_angle,power)| 6 % 7 % |MotorRotateAbs(port,abs_angle,power, handle)| 6 8 % 7 9 % Description … … 10 12 % |MOTOR_C| analog to the labeling on the NXT Brick. The |angle| determines the absolute angle to 11 13 % rotate. |power| represents the motor power (|1...100|). 14 % 15 % The last optional argument can be a valid NXT handle. If none is 16 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 17 % set one). 12 18 % 13 19 % Note: … … 20 26 % 21 27 % Signature 22 % Author: Rob terSchwann, Bernd Neumann (see AUTHORS)28 % Author: Robert Schwann, Bernd Neumann (see AUTHORS) 23 29 % Date: 2007/10/15 24 30 % Copyright: 2007-2008, RWTH Aachen University … … 41 47 % *********************************************************************************************** 42 48 49 % check if handle is given; if not use default one 50 if nargin > 4 51 handle = varargin{1}; 52 else 53 handle = COM_GetDefaultNXT; 54 end%if 55 43 56 if power<=0 44 57 error('MATLAB:RWTHMindstormsNXT:Motor:invalidPower', ... … … 47 60 end 48 61 49 out = GetMotorSettings(whatmotor );62 out = GetMotorSettings(whatmotor, handle); 50 63 % physical angle the motor actually has to go 51 64 angle_to_go = abs_angle - out.TachoCount; 52 65 53 66 % relative angle (for motor command) 54 rel_angle = abs_angle - GetMemoryCount(whatmotor );55 SetMemoryCount(whatmotor, abs_angle );67 rel_angle = abs_angle - GetMemoryCount(whatmotor, handle); 68 SetMemoryCount(whatmotor, abs_angle, handle); 56 69 57 70 if sign(rel_angle)*sign(angle_to_go)>0 || angle_to_go==0 58 71 if rel_angle~=0 59 72 NXT_SetOutputState(whatmotor,power*sign(rel_angle),1,1,... 60 'SPEED',0,'RUNNING',abs(rel_angle),'dontreply' );73 'SPEED',0,'RUNNING',abs(rel_angle),'dontreply', handle); 61 74 end 62 75 else 63 76 NXT_SetOutputState(whatmotor,-power*sign(angle_to_go),1,1,... 64 'SPEED',0,'RUNNING',abs(rel_angle)+1,'dontreply' );77 'SPEED',0,'RUNNING',abs(rel_angle)+1,'dontreply', handle); 65 78 NXT_SetOutputState(whatmotor,power*sign(angle_to_go),1,1,... 66 'SPEED',0,'RUNNING',1,'dontreply' );79 'SPEED',0,'RUNNING',1,'dontreply', handle); 67 80 end -
branches/atorf/RWTHMindstormsNXT/NXT_LSRead.m
r289 r303 7 7 % |[data BytesRead] = NXT_LSRead(port, handle)| 8 8 % 9 % |[data BytesRead optionalStatusByte] = NXT_LSRead(port, [handle])| 9 % |[data BytesRead optionalStatusByte] = NXT_LSRead(port)| 10 % 11 % |[data BytesRead optionalStatusByte] = NXT_LSRead(port, handle)| 10 12 % 11 13 % Description … … 26 28 % argument is still optional, like above. 27 29 % 28 % If no Bluetoothhandle is specified the default one (|COM_GetDefaultNXT|) is used.30 % If no NXT handle is specified the default one (|COM_GetDefaultNXT|) is used. 29 31 % 30 32 % -
branches/atorf/RWTHMindstormsNXT/NXT_MessageWrite.m
r291 r303 15 15 % |mailbox|. If no mailbox is specified, default one is 0 (zero) 16 16 % 17 % |NXT_MessageWrite(message, mailbox, handle)| uses the given Bluetooth 18 % connection |handle|. This should be a serial handle on a Windows 19 % platform and a file handle on a Linux one. If no Bluetooth handle is 20 % specified, default one (|COM_GetDefaultNXT()|) is used. 17 % |NXT_MessageWrite(message, mailbox, handle)| uses the given NXT 18 % connection |handle|. If no handle is specified, the default one 19 % (|COM_GetDefaultNXT()|) is used. 21 20 % 22 21 % Examples: … … 28 27 %+ NXT_MessageWrite('F010045', 0, handle); 29 28 % 30 % See also NAME2COMMANDBYTES, COM_CREATEPACKET, COM_SENDPACKET29 % See also: COM_CreatePacket, COM_SendPacket 31 30 % 32 % Copyright 2007-2008, The MathWorks SAS (France) 33 % Writen by Laurent Vaylet, 2008/09/24 31 % Signature 32 % Author: Laurent Vaylet, The MathWorks SAS (France) (see AUTHORS) 33 % Date: 2008/09/24 34 % Copyright: 2007-2008, RWTH Aachen University 35 % 34 36 ; 35 37 % -
branches/atorf/RWTHMindstormsNXT/OpenAccelerator.m
r291 r303 1 1 function OpenAccelerator(port, varargin) 2 % Initializes and sets the mode of the NXT acceleratorsensor2 % Initializes and sets the mode of the HiTechnic acceleration sensor 3 3 % 4 4 % Syntax 5 5 % |OpenAccelerator(port)| 6 6 % 7 % |OpenAccelerator(port, handle)| 7 8 % 8 9 % Description … … 11 12 % |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. 12 13 % 14 % The last optional argument can be a valid NXT handle. If none is 15 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 16 % set one). 13 17 % 14 18 % Examples … … 17 21 %+ CloseSensor(SENSOR_4); 18 22 % 19 % See also: GetAccelerator, CloseSensor, NXT_LSGetStatus, NXT_LSRead23 % See also: GetAccelerator, CloseSensor, COM_ReadI2C, NXT_LSGetStatus, NXT_LSRead 20 24 % 21 25 % Signature … … 41 45 % *********************************************************************************************** 42 46 43 %% Parameter check 47 %% Parameter check 48 49 % check if handle is given; if not use default one 50 if nargin > 1 51 handle = varargin{1}; 52 else 53 handle = COM_GetDefaultNXT; 54 end%if 55 44 56 % also accept strings as input 45 57 if ischar(port) … … 47 59 end%if 48 60 49 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply' );61 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply', handle); 50 62 51 63 % %% Build hex command and send it with NXT_LSWrite … … 66 78 % the following command sequence is not clearly documented but was 67 79 % found to work well! 68 NXT_LSGetStatus(port); % flush out data with Poll 69 NXT_LSRead(port); % flush out data with Poll? 70 80 NXT_LSGetStatus(port, handle); % flush out data with Poll 81 % we request the status-byte so that it doesn't get checked. 82 % errors that can occur here are: 83 %Packet (reply to LSREAD) contains error message 221: "Communication bus error" 84 %Packet (reply to LSREAD) contains error message 224: "Specified 85 %channel/connection not configured or busy" 86 [a b c] = NXT_LSRead(port, handle); % flush out data with Poll? 71 87 end -
branches/atorf/RWTHMindstormsNXT/OpenCompass.m
r298 r303 1 function OpenCompass(port )2 % Initializes and sets the mode of the NXTcompass sensor1 function OpenCompass(port, varargin) 2 % Initializes and sets the mode of the HiTechnic magnetic compass sensor 3 3 % 4 4 % Syntax 5 5 % |OpenCompass(port)| 6 6 % 7 % |OpenCompass(port, handle)| 7 8 % 8 9 % Description 9 % |OpenCompass(port)| initializes the input mode of NXTcompass sensor specified by the sensor10 % |OpenCompass(port)| initializes the input mode of HiTechnic compass sensor specified by the sensor 10 11 % port. The value |port| can be addressed by the symbolic constants 11 12 % |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. 12 13 % 13 % With |GetCompass(port)| you receive the handing value ranging from 0 to 359.14 % With |GetCompass(port)| you can receive the heanding value ranging from 0 to 359. 14 15 % 15 % Since the NXT compass sensor is a digital sensor (that uses the I²C protocol), 16 % The last optional argument can be a valid NXT handle. If none is 17 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 18 % set one). 19 % 20 % Since the compass sensor is a digital sensor (that uses the I²C protocol), 16 21 % the function |NXT_SetInputMode| cannot be used as for analog sensors. 17 22 % … … 22 27 %+ CloseSensor(SENSOR_2); 23 28 % 24 % See also: GetCompass, CloseSensor, NXT_LSGetStatus, NXT_LSRead29 % See also: GetCompass, CloseSensor, COM_ReadI2C, NXT_LSGetStatus, NXT_LSRead 25 30 % 26 31 % Signature … … 47 52 48 53 %% Parameter check 54 55 % check if handle is given; if not use default one 56 if nargin > 1 57 handle = varargin{1}; 58 else 59 handle = COM_GetDefaultNXT; 60 end%if 61 49 62 % also accept strings as input 50 63 if ischar(port) … … 52 65 end%if 53 66 54 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply' );67 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply', handle); 55 68 56 69 … … 58 71 % the following command sequence is not clearly documented but was 59 72 % found to work well! 60 NXT_LSGetStatus(port ); % flush out data with Poll73 NXT_LSGetStatus(port, handle); % flush out data with Poll 61 74 % we request the status-byte so that it doesn't get checked. 62 75 % errors that can occur here are: … … 64 77 %Packet (reply to LSREAD) contains error message 224: "Specified 65 78 %channel/connection not configured or busy" 66 [a b c] = NXT_LSRead(port ); % flush out data with Poll?79 [a b c] = NXT_LSRead(port, handle); % flush out data with Poll? 67 80 end%function -
branches/atorf/RWTHMindstormsNXT/OpenInfrared.m
r291 r303 1 1 function OpenInfrared(port, varargin) 2 % Initializes and sets the mode of the NXTinfrared seeker sensor2 % Initializes and sets the mode of the HiTechnic infrared seeker sensor 3 3 % 4 4 % Syntax 5 5 % |OpenInfrared(port)| 6 6 % 7 % |OpenInfrared(port, handle)| 7 8 % 8 9 % Description 9 % |OpenInfrared(port)| initializes the input mode of NXTinfrared seeker sensor specified by the sensor10 % |OpenInfrared(port)| initializes the input mode of HiTechnic infrared seeker sensor specified by the sensor 10 11 % |port|. The value |port| can be addressed by the symbolic constants 11 12 % |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. 12 13 % 14 % The last optional argument can be a valid NXT handle. If none is 15 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 16 % set one). 13 17 % 14 18 % Examples … … 42 46 43 47 %% Parameter check 48 49 % check if handle is given; if not use default one 50 if nargin > 1 51 handle = varargin{1}; 52 else 53 handle = COM_GetDefaultNXT; 54 end%if 55 44 56 % also accept strings as input 45 57 if ischar(port) … … 47 59 end%if 48 60 49 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply' );61 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply', handle); 50 62 51 63 % %% Build hex command and send it with NXT_LSWrite … … 66 78 % the following command sequence is not clearly documented but was 67 79 % found to work well! 68 NXT_LSGetStatus(port); % flush out data with Poll 69 NXT_LSRead(port); % flush out data with Poll? 70 80 NXT_LSGetStatus(port, handle); % flush out data with Poll 81 % we request the status-byte so that it doesn't get checked. 82 % errors that can occur here are: 83 %Packet (reply to LSREAD) contains error message 221: "Communication bus error" 84 %Packet (reply to LSREAD) contains error message 224: "Specified 85 %channel/connection not configured or busy" 86 [a b c] = NXT_LSRead(port, handle); % flush out data with Poll? 71 87 end -
branches/atorf/RWTHMindstormsNXT/OpenLight.m
r123 r303 1 function OpenLight(f_sensorport, f_mode )1 function OpenLight(f_sensorport, f_mode, varargin) 2 2 % Sets the parameter mode of the NXT light sensor 3 3 % 4 4 % Syntax 5 5 % |OpenLight(port, mode)| 6 % 7 % |OpenLight(port, mode, handle)| 6 8 % 7 9 % Description … … 12 14 % (passive illumination red light off). To deactive the active illumination the function 13 15 % |CloseSensor| is used. 16 % 17 % The last optional argument can be a valid NXT handle. If none is 18 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 19 % set one). 14 20 % 15 21 % For more complex settings the function |NXT_SetInputMode| can be used. … … 45 51 46 52 %% Check Parameter 53 % check if handle is given; if not use default one 54 if nargin > 2 55 handle = varargin{1}; 56 else 57 handle = COM_GetDefaultNXT; 58 end%if 59 47 60 if ~strcmpi(f_mode, 'ACTIVE') && ~strcmpi(f_mode, 'INACTIVE') 48 61 error('MATLAB:RWTHMindstormsNXT:Sensor:invalidMode', 'Light sensor mode has to be ''ACTIVE'' or ''INACTIVE'''); … … 62 75 63 76 %% Call NXT_SetInputMode function 64 NXT_SetInputMode(f_sensorport, sensortype, sensormode, 'dontreply' );77 NXT_SetInputMode(f_sensorport, sensortype, sensormode, 'dontreply', handle); 65 78 66 79 end%function -
branches/atorf/RWTHMindstormsNXT/OpenSound.m
r123 r303 1 function OpenSound(f_sensorport, f_mode )1 function OpenSound(f_sensorport, f_mode, varargin) 2 2 % Sets the parameter mode of the NXT sound sensor 3 3 % 4 4 % Syntax 5 5 % |OpenSound(port, mode)| 6 % 7 % |OpenSound(port, mode, handle)| 6 8 % 7 9 % Description … … 10 12 % |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. The 11 13 % |mode| represents one of two modes |'DB'| (dB measurement) and |'DBA'| (dBA measurement) 14 % 15 % The last optional argument can be a valid NXT handle. If none is 16 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 17 % set one). 12 18 % 13 19 % For more complex settings the function |NXT_SetInputMode| can be used. … … 43 49 44 50 %% Check Parameter 51 % check if handle is given; if not use default one 52 if nargin > 2 53 handle = varargin{1}; 54 else 55 handle = COM_GetDefaultNXT; 56 end%if 57 45 58 if ~strcmpi(f_mode, 'DB') && ~strcmpi(f_mode, 'DBA') 46 59 error('MATLAB:RWTHMindstormsNXT:Sensor:invalidMode', 'Sound sensor mode has to be ''DB'' or ''DBA'''); … … 60 73 61 74 %% Call NXT_SetInputMode function 62 NXT_SetInputMode(f_sensorport, sensortype, sensormode, 'dontreply' );75 NXT_SetInputMode(f_sensorport, sensortype, sensormode, 'dontreply', handle); 63 76 64 77 end%function -
branches/atorf/RWTHMindstormsNXT/OpenSwitch.m
r123 r303 1 function OpenSwitch( f_sensorport)1 function OpenSwitch(port, varargin) 2 2 % Sets the parameter mode of the NXT switch / touch sensor 3 3 % … … 5 5 % |OpenSwitch(port)| 6 6 % 7 % |OpenSwitch(port, handle)| 8 % 7 9 % Description 8 10 % |OpenSound(port)| initializes the input mode of NXT switch / touch sensor specified by the sensor 9 11 % |port|. The value |port| can be addressed by the symbolic constants 10 12 % |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. 13 % 14 % The last optional argument can be a valid NXT handle. If none is 15 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 16 % set one). 11 17 % 12 18 % For more complex settings the function |NXT_SetInputMode| can be used. … … 56 62 57 63 %% check parameters 64 65 % check if handle is given; if not use default one 66 if nargin > 1 67 handle = varargin{1}; 68 else 69 handle = COM_GetDefaultNXT; 70 end%if 71 58 72 % also accept strings as input 59 if ischar( f_sensorport)60 f_sensorport = str2double(f_sensorport);73 if ischar(port) 74 port = str2double(port); 61 75 end%if 62 76 … … 69 83 70 84 %% Call NXT_SetInputMode function 71 NXT_SetInputMode( f_sensorport, sensortype, sensormode, 'dontreply');85 NXT_SetInputMode(port, sensortype, sensormode, 'dontreply', handle); 72 86 73 87 end%function -
branches/atorf/RWTHMindstormsNXT/OpenUltrasonic.m
r296 r303 6 6 % 7 7 % |OpenUltrasonic(port, mode)| 8 % 9 % |OpenUltrasonic(port, mode, handle)| 8 10 % 9 11 % Description … … 17 19 % |USMakeSnapshot| for more information. 18 20 % 21 % The last optional argument can be a valid NXT handle. If none is 22 % specified, the default handle will be used (call |COM_SetDefaultNXT| to 23 % set one). 24 % 19 25 % Since the NXT ultrasonic sensor is a digital sensor (that uses the I²C protocol), 20 26 % the function |NXT_SetInputMode| cannot be used as for analog sensors. 21 27 % 22 % Note: When the US sensor is opened in snapshot mode, the function 28 % Note 29 % When the US sensor is opened in snapshot mode, the function 23 30 % |GetUltrasonic| does not work correctly! 24 31 % … … 64 71 65 72 %% Parameter check 73 74 % check if handle is given; if not use default one 75 if nargin > 2 76 handle = varargin{2}; 77 else 78 handle = COM_GetDefaultNXT; 79 end%if 80 66 81 % also accept strings as input 67 82 if ischar(port) … … 78 93 79 94 80 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply' );95 NXT_SetInputMode(port, 'LOWSPEED_9V', 'RAWMODE', 'dontreply', handle); 81 96 82 97 … … 94 109 I2Cdata(3) = hex2dec('01'); % SINGLE_SHOT 95 110 96 NXT_LSWrite(port, RequestLen, I2Cdata, 'dontreply' );111 NXT_LSWrite(port, RequestLen, I2Cdata, 'dontreply', handle); 97 112 98 113 else … … 104 119 I2Cdata(3) = hex2dec('02'); % CONTINUOUS_MEASUREMENT 105 120 106 NXT_LSWrite(port, RequestLen, I2Cdata, 'dontreply' );121 NXT_LSWrite(port, RequestLen, I2Cdata, 'dontreply', handle); 107 122 end%if 108 123 … … 114 129 % the following command sequence is not clearly documented but was 115 130 % found to work well! 116 NXT_LSGetStatus(port ); % flush out data with Poll131 NXT_LSGetStatus(port, handle); % flush out data with Poll 117 132 % we request the status-byte so that it doesn't get checked. 118 133 % errors that can occur here are: … … 120 135 %Packet (reply to LSREAD) contains error message 224: "Specified 121 136 %channel/connection not configured or busy" 122 [a b c] = NXT_LSRead(port ); % flush out data with Poll?137 [a b c] = NXT_LSRead(port, handle); % flush out data with Poll? 123 138 124 139 end%function
