Changeset 248
- Timestamp:
- 09/08/08 14:35:13 (5 years ago)
- Location:
- branches/telle/RWTHMindstormsNXT
- Files:
-
- 10 modified
-
. (modified) (1 prop)
-
@NXTmotor/read.m (modified) (1 diff)
-
@NXTmotor/set.m (modified) (1 diff)
-
@NXTmotor/stop.m (modified) (1 diff)
-
@NXTmotorsettings/read.m (modified) (1 diff)
-
@NXTmotorsettings/send.m (modified) (1 diff)
-
@NXTmotorsettings/stop.m (modified) (2 diffs)
-
GetMotorSettings.m (modified) (1 diff)
-
SendMotorSettings.m (modified) (2 diffs)
-
StopMotor.m (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/telle/RWTHMindstormsNXT
-
Property
svn:mergeinfo set
to
/branches/behrens/mfiles merged eligible
-
Property
svn:mergeinfo set
to
-
branches/telle/RWTHMindstormsNXT/@NXTmotor/read.m
r246 r248 14 14 end 15 15 16 data = NXT_GetOutputState(obj.port);17 16 17 18 settings = NXT_GetOutputState(obj.port); 19 20 data.Port = char(double('A') + settings.Port); 21 data.Power = settings.Power; 22 if settings.ModeIsMOTORON 23 data.MotorOn = 'on'; 24 else 25 data.MotorOn = 'off'; 26 end 27 if settings.ModeIsBRAKE 28 data.Brake = 'on'; 29 else 30 data.Brake = 'off'; 31 end 32 data.RegulationMode = lower(settings.RegModeName); 33 data.TurnRatio = settings.TurnRatio; 34 data.RunState = lower(settings.RunStateName); 35 data.TachoLimit = settings.TachoLimit; 36 data.TachoCount = settings.TachoCount; 37 data.BlockTachoCount = settings.BlockTachoCount; -
branches/telle/RWTHMindstormsNXT/@NXTmotor/set.m
r246 r248 194 194 195 195 case 'TachoLimit' 196 if isscalar(val) && isnumeric(val) 196 if isscalar(val) && isnumeric(val) && val >= 0 197 197 obj.tachoLimit = val; 198 198 else 199 199 error('MotorSettingError:InvalidTachoLimit',... 200 'TachoLimit must be a n umeric scalar. Zero means run forever.');200 'TachoLimit must be a non-negative numeric scalar. Zero means run forever.'); 201 201 end 202 202 otherwise -
branches/telle/RWTHMindstormsNXT/@NXTmotor/stop.m
r246 r248 21 21 end 22 22 23 if (ischar(withBrake) && strcmpi(withBrake, 'brake')) ... 24 || (withBrake ~= 0) 25 withBrake = 1; 23 if ischar(withBrake) 24 if strcmpi(withBrake, 'brake') || strcmpi(withBrake, 'on') 25 withBrake = 1; 26 elseif strcmpi(withBrake, 'nobrake') || strcmpi(withBrake, 'off') 27 withBrake = 0; 28 else 29 error('RWTHMINDSTORMS:NXTmotor:InvalidArgument',... 30 'Invalid second argument to function NXTmotor/send.'); 31 end 32 elseif isnumeric(withBrake) 33 if (withBrake ~= 0) 34 withBrake = 1; 35 else 36 withBrake = 0; 37 end 38 elseif islogical(withBrake) 39 if (withBrake == true) 40 withBrake = 1; 41 else 42 withBrake = 0; 43 end 44 else 45 error('RWTHMINDSTORMS:NXTmotor:InvalidArgument',... 46 'Invalid second argument to function NXTmotor/send.'); 26 47 end 27 48 28 NXT_SetOutputState(... 29 obj.port, ... % Port 30 0, ... % Power 31 withBrake, ... % IsMotorOn 32 1, ... % IsBrake 33 'SPEED', ... % RegModeName 34 0, ... % TurnRatio 35 'RUNNING', ... % RunStateName 36 0, ... % TachoLimit 37 'dontreply'... % ReplyMode 38 ); 39 40 49 StopMotor(obj.port, withBrake); -
branches/telle/RWTHMindstormsNXT/@NXTmotorsettings/read.m
r246 r248 16 16 end 17 17 18 for k = 1:length( data.motors)18 for k = 1:length(obj.motors) 19 19 settings(k) = read(obj.motors(k)); 20 20 end -
branches/telle/RWTHMindstormsNXT/@NXTmotorsettings/send.m
r246 r248 16 16 end 17 17 18 if nargout == 1 19 out = zeros(size(obj.motors)); 20 for k = 1:length(obj.motors) 21 out(k) = send(obj.motors(k)); 22 end 18 23 19 out = zeros(size(obj.motors)); 20 for k = 1:length(obj.motors) 21 out(k) = send(obj.motors(k)); 24 out = any(out); 25 else 26 for k = 1:length(obj.motors) 27 send(obj.motors(k)); 28 end 22 29 end 23 24 out = any(out); 30 -
branches/telle/RWTHMindstormsNXT/@NXTmotorsettings/stop.m
r246 r248 23 23 end 24 24 25 if ~iscell(withBrake)25 if ischar(withBrake) 26 26 withBrake = {withBrake}; 27 27 end … … 30 30 withBrake = repmat(withBrake, size(obj.motors)); 31 31 elseif numel(withBrake) ~= numel(obj.motors) 32 error(' MotorSettingsError:InvalidParameterSize',...32 error('RWTHMINDSTORMS:NXTmotorsettings:InvalidParameterSize',... 33 33 'Number of elements must be 1 or the number of motors.'); 34 34 end 35 35 36 for k = 1:length(obj.motors) 37 stop(obj.motors(k), withBrake{k}); 36 if length(obj.motors) == 3 37 if withBrake(1) == withBrake(2) && withBrake(1) == withBrake(3) 38 if iscell(withBrake) 39 StopMotor('all', withBrake{1}); 40 else 41 StopMotor('all', withBrake(1)); 42 end 43 return 44 end 38 45 end 39 46 40 47 if iscell(withBrake) 48 for k = 1:length(obj.motors) 49 stop(obj.motors(k), withBrake{k}); 50 end 51 else 52 for k = 1:length(obj.motors) 53 stop(obj.motors(k), withBrake(k)); 54 end 55 end 41 56 -
branches/telle/RWTHMindstormsNXT/GetMotorSettings.m
r201 r248 97 97 out.SyncToMotor = -1; 98 98 else % SYNC then... :-) 99 100 % THIS IS LIKELY NOT TO BE CORRECT AS THE USER MAY HAVE MODIFIED 101 % THE MOTOR SETTINGS WITHOUT HAVING SENT THEM TO THE BRICK YET !!!! 102 99 103 % shouldnt be necessary but whatever 100 104 NXTMOTOR_State(whatmotor + 1).SyncedToSpeed = false; -
branches/telle/RWTHMindstormsNXT/SendMotorSettings.m
r201 r248 95 95 96 96 97 %% One argument of type NXTmotor or NXTmotorsettings 98 % If there is exactly one argument of type NXTmotor or NXTmotorsettings 99 % just call the send function for this object 100 101 if nargin == 1 && ... 102 (isa(f_port,'NXTmotor') || isa(f_port, 'NXTmotorsettings')) 103 send(f_port); 104 return 105 end 106 107 97 108 %% check given arguments 98 109 if (nargin ~= 0) && (nargin ~= 7) … … 102 113 'Type "help SendMotorSettings" or see documentation!']); 103 114 end 115 116 104 117 105 118 %% get handle & motorstate -
branches/telle/RWTHMindstormsNXT/StopMotor.m
r201 r248 6 6 % 7 7 % Description 8 % StopMotor(port, mode) stops the motor connected to the given port. The value port can be 9 % addressed by the symbolic constants MOTOR_A, MOTOR_B, MOTOR_C and 'all' (all motor at at 10 % the same time) analog to the labeling on the NXT Brick. The argument mode can be equal to 11 % 'off' which cuts off the electrical power to the specific motor, so called "COAST" mode. The 12 % option 'brake' will actively halt the motor at the current position (until the next command). 8 % StopMotor(port, mode) stops the motor connected to the given port. The 9 % value port can be addressed by a string representing the label of the 10 % port on the brick ('A', 'B', or 'C') or the index of the port starting 11 % with 0, i.e., 0, 1, or 2 corresponding to A, B, and C respectively. The 12 % index may also be given as a string, e.g., '1'. If all motors shall be 13 % stopped the string 'all' can be used for the first argument. 14 % 15 % The argument mode can take the following values: 16 % 'nobrake', 'off', 0: The electrical power to the specified motor is 17 % simply disconnected, the so-called "COAST" 18 % mode. 19 % 'brake', 'on', 1: This will actively halt the motor at the 20 % current position (until the next movement 21 % command). 13 22 % 14 23 % Note: 15 % The value port equal to 'all' can be used to stopp all motors at the same time using only 16 % one single Bluetooth packet. After a StopMotor command the motor snychronization will be lost. 24 % The value port equal to 'all' can be used to stopp all motors at the 25 % same time using only one single Bluetooth packet. After a StopMotor 26 % command the motor snychronization will be lost. 17 27 % 18 % With mode equal to 'off', the motor will slowly stop spinning, but using 'brake' applies 19 % real force to the motor to stand still at the current position, just like a real brake. 28 % With mode equal to 'off', the motor will slowly stop spinning, but 29 % using 'brake' applies real force to the motor to stand still at the 30 % current position, just like a real brake. 20 31 % 21 % When calling StopMotor(..., 'off'), you also internally issue the commands22 % SpeedRegulation('off') and SyncToMotor('off'), while using 'brake' will call23 % SpeedRegulation('on') and SyncToMotor('off').32 % When calling StopMotor(..., 'off'), internally the speed regulation 33 % and motor synchronization are turned off, while using 'brake' will onle 34 % turn off synchronization but enable speed regulation. 24 35 % 25 36 % Example 26 % SetMotor(MOTOR_B); 27 % SetPower(-55); 28 % SetAngleLimit(1200); 29 % SendMotorSettings(); 37 % m = NXTmotor('A'); 38 % m.Power = -55; 39 % m.TachoLimit = 1200; 30 40 % 31 % WaitForMotor(MOTOR_A); 41 % m2 = NXTmotor('B'); 42 % m2.Power = 60; 32 43 % 33 % StopMotor(MOTOR_B, 'brake'); 44 % send(m); 45 % send(m2); 34 46 % 35 % See also: WaitForMotor, SendMotorSettings, MOTOR_A, MOTOR_B, MOTOR_C 47 % wait(m); 48 % 49 % StopMotor('all', 'brake'); 50 % 51 % See also: NXTmotor, NXTmotorsettings 36 52 % 37 53 % Signature 38 % Author: Linus Atorf, Alexander Behrens (see AUTHORS)39 % Date: 200 7/10/1554 % Author: Aulis Telle, Linus Atorf, Alexander Behrens (see AUTHORS) 55 % Date: 2008/09/02 40 56 % Copyright: 2007-2008, RWTH Aachen University 41 57 % … … 62 78 whatmotor = 255; 63 79 else 64 whatmotor = str2double(whatmotor); 80 switch lower(whatmotor) 81 case {'a', '0'} 82 whatmotor = 0; 83 case {'b', '1'} 84 whatmotor = 1; 85 case {'c', '2'} 86 whatmotor = 2; 87 otherwise 88 whatmotor = -1; 89 end%switch 65 90 end%if 66 91 end%if 92 93 switch lower(brakemode) 94 case {'nobrake', 'off', 0, false} 95 brakemode = 'off'; 96 case {'brake', 'on', 1, true} 97 brakemode = 'on'; 98 otherwise 99 brakemode = 'off'; 100 warning('MATLAB:RWTHMindstormsNXT:StopMotor:invalidBrakeMode', 'Invalid brakemode. Brakemode is switched to ''off''.'); 101 end%switch 67 102 68 103 69 104 %% Check Parameter 70 105 if (whatmotor < 0 || whatmotor > 2) && (whatmotor ~= 255) 71 error('MATLAB:RWTHMindstormsNXT:Motor:invalidPort', 'Input argument for motor port must be 0, 1 or2 or ''all''.');106 error('MATLAB:RWTHMindstormsNXT:Motor:invalidPort', 'Input argument for motor port must be ''A'', ''B'', ''C'', ''0'', ''1'', ''2'', 0, 1, 2 or ''all''.'); 72 107 end%if 73 108 74 109 75 %% get default handle & motorstate 76 h = COM_GetDefaultNXT(); 77 NXTMOTOR_State = h.NXTMOTOR_getState(); 110 %% Brake Mode 111 if strcmpi(brakemode, 'on') 78 112 79 %% reset regulation state 80 h.NXTMOTOR_resetRegulationState(whatmotor); 113 % set to power 0 with speed regulation 114 NXT_SetOutputState(whatmotor, ... 115 0, ... % power 116 true, ... % motoron 117 true, ... % brake 118 'SPEED', ...% regulation 119 0, ... % turnratio 120 'RUNNING', ... % runstate 121 0, ... % tacho limit 122 'dontreply'); % replymode 81 123 82 124 %% Turn Off Mode (Coast mode) 83 if strcmpi(brakemode, 'off') 84 85 125 else 126 86 127 % basically turn electric power to motor off, COAST mode 87 128 NXT_SetOutputState(whatmotor, ... … … 95 136 'dontreply'); % replymode 96 137 138 end%if 97 139 98 %% Brake Mode99 elseif strcmpi(brakemode, 'brake')100 101 102 % set speed regulation mode103 if whatmotor == 255104 NXTMOTOR_State(1).SyncedToSpeed = true;105 NXTMOTOR_State(2).SyncedToSpeed = true;106 NXTMOTOR_State(3).SyncedToSpeed = true;107 else108 NXTMOTOR_State(whatmotor+1).SyncedToSpeed = true;109 end%if110 111 % set to power 0 with speed regulation112 NXT_SetOutputState(whatmotor, ...113 0, ... % power114 true, ... % motoron115 true, ... % brake116 'SPEED', ...% regulation117 0, ... % turnratio118 'RUNNING', ... % runstate119 0, ... % tacho limit120 'dontreply'); % replymode121 122 123 %% Error124 else125 error('MATLAB:RWTHMindstormsNXT:Motor:invalidBrakeMode', ...126 ['Input argument for brake mode must either be ''off'' (motor will be turned off) ' ...127 'or ''brake'' (motor will be actively halted at speed 0)']);128 end%if129 130 131 %% save motor state back to handle132 h.NXTMOTOR_setState(NXTMOTOR_State);133 134 135 136 140 end%function 137 141
