Show
Ignore:
Timestamp:
07/25/08 14:06:27 (5 years ago)
Author:
telle
Message:

NXTmotor.m:

  • FIX: When setting regulationMode, data.power was set.
  • When called with another NXTmotor object as first argument the object was just copied, thus the resulting object operated on the same data as the source object. This is not the intended behavior. Now a new set of data is created with the values of the source object, i.e., we then have two completely independent objects.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/telle/RWTHMindstormsNXT/@NXTmotor/NXTmotor.m

    r220 r221  
    3131% Author: Aulis Telle, IND, RWTH Aachen 
    3232 
     33data = []; 
    3334 
    3435if nargin > 0 && isa(varargin{1}, 'NXTmotor') 
    35     obj = varargin{1}; 
    36     return; 
     36    tmp = varargin{1}; 
     37    data = tmp.data(); 
     38else 
     39    port = 0; 
     40    if nargin > 0 
     41        val = varargin{1}; 
     42        if isscalar(val) && isnumeric(val) && val >= 0 && val <= 2 
     43            port = val; 
     44        elseif ischar(val) 
     45            switch lower(val) 
     46                case 'a' 
     47                    port = 0; 
     48                case 'b' 
     49                    port = 1; 
     50                case 'c' 
     51                    port = 2; 
     52                otherwise 
     53                    error('MotorSettingError:InvalidPort',... 
     54                        'Port may be one of ''A'', ''B'', or ''C''.'); 
     55            end 
     56        else 
     57            error('MotorSettingError:InvalidPort',... 
     58                'Port may be one of ''A'', ''B'', or ''C''.'); 
     59        end 
     60    end 
     61 
     62    data.port           = port; 
     63    data.power          = 0; 
     64    data.mode.motorOn   = 1; 
     65    data.mode.brake     = 1; 
     66    data.regulationMode = 'IDLE'; 
     67    data.turnRatio      = 0; 
     68    data.runState       = 'RUNNING'; 
     69    data.tachoLimit     = 0; 
    3770end 
    38  
    39 port = 0; 
    40 if nargin > 0  
    41     val = varargin{1}; 
    42     if isscalar(val) && isnumeric(val) && val >= 0 && val <= 2 
    43         port = val; 
    44     elseif ischar(val) 
    45         switch lower(val) 
    46             case 'a' 
    47                 port = 0; 
    48             case 'b' 
    49                 port = 1; 
    50             case 'c' 
    51                 port = 2; 
    52             otherwise 
    53                 error('MotorSettingError:InvalidPort',... 
    54                     'Port may be one of ''A'', ''B'', or ''C''.'); 
    55         end 
    56     else 
    57         error('MotorSettingError:InvalidPort',... 
    58             'Port may be one of ''A'', ''B'', or ''C''.'); 
    59     end 
    60 end 
    61  
    62 data.port           = port; 
    63 data.power          = 0; 
    64 data.mode.motorOn   = 1; 
    65 data.mode.brake     = 1; 
    66 data.regulationMode = 'IDLE'; 
    67 data.turnRatio      = 0; 
    68 data.runState       = 'RUNNING'; 
    69 data.tachoLimit     = 0; 
    70  
    7171 
    7272 
     
    105105     
    106106            case {'regulationMode'} 
    107                 data.power = varargin{2}; 
     107                data.regulationMode = varargin{2}; 
    108108     
    109109            case {'turnRatio'}