Changeset 117

Show
Ignore:
Timestamp:
07/05/08 01:15:49 (5 years ago)
Author:
atorf
Message:

USB: Updated motor-related functions to handle-use, removed global NXTMOTOR_State var

Location:
branches/atorf/RWTHMindstormsNXT
Files:
1 added
12 modified
2 moved

Legend:

Unmodified
Added
Removed
  • branches/atorf/RWTHMindstormsNXT/GetMemoryCount.m

    r3 r117  
    4141% *********************************************************************************************** 
    4242 
    43 global NXTMOTOR_State; 
    44  
    45 if isempty(NXTMOTOR_State) 
    46     initializeGlobalMotorStateVar; 
    47 end%if 
     43% get default handle & motorstate 
     44h = COM_GetDefaultNXT(); 
     45NXTMOTOR_State = h.NXTMOTOR_State(); 
    4846 
    4947memory = NXTMOTOR_State(number+1).MemoryCount; 
  • branches/atorf/RWTHMindstormsNXT/GetMotorSettings.m

    r3 r117  
    6565% *********************************************************************************************** 
    6666 
    67 global NXTMOTOR_State; 
    68  
    69 if isempty(NXTMOTOR_State) 
    70     initializeGlobalMotorStateVar; 
    71 end%if 
    72  
    7367 
    7468if whatmotor < 0 || whatmotor > 2 
    7569    error('MATLAB:RWTHMindstormsNXT:Motor:invalidPort', 'Input argument for motor must be 0, 1, or 2') 
    7670end%if 
     71 
     72% get default handle & motorstate 
     73h = COM_GetDefaultNXT(); 
     74NXTMOTOR_State = h.NXTMOTOR_State(); 
    7775 
    7876 
     
    121119NXTMOTOR_State(whatmotor + 1).TachoCount = data.TachoCount; 
    122120 
     121% save motor state back to handle 
     122h.NXTMOTOR_State(NXTMOTOR_State); 
     123 
    123124end%function 
    124125 
  • branches/atorf/RWTHMindstormsNXT/NXT_ResetMotorPosition.m

    r110 r117  
    5353% check if bluetooth handle is given. if not use default one 
    5454if nargin > 2 
    55         handle = varargin{1}; 
     55    handle = varargin{1}; 
    5656else 
    5757    handle = COM_GetDefaultNXT; 
  • branches/atorf/RWTHMindstormsNXT/ResetMotorAngle.m

    r3 r117  
    4848% *********************************************************************************************** 
    4949 
    50 %% Parameter check 
    51 % check if bluetooth handle is given. if not use default one 
    52 if nargin > 1 
    53     if (ispc && isa(varargin{1}, 'serial')) || (isunix && isscalar(varargin{1})) 
    54         handle = varargin{1}; 
    55     else 
    56         error('MATLAB:RWTHMindstormsNXT:Bluetooth:invalidHandle', 'Optional NXT bluetooth handle specified, but not a valid serial port handle'); 
    57     end%if 
    58 else 
    59     handle = BT_GetDefaultHandle; 
    60 end%if 
    61  
    62     NXT_ResetMotorPosition(port, true, handle); 
     50% as we can see, just a little wrapper that maps the following NXT function and 
     51% parameter combination to a more obvious name 
     52NXT_ResetMotorPosition(port, true, handle); 
    6353     
    6454end%function 
  • branches/atorf/RWTHMindstormsNXT/SendMotorSettings.m

    r3 r117  
    6464end 
    6565 
    66  
    67 global NXTMOTOR_State; 
    68  
    69 if isempty(NXTMOTOR_State) 
    70     initializeGlobalMotorStateVar; 
    71 end%if 
     66%% get handle & motorstate 
     67h = COM_GetDefaultNXT(); 
     68NXTMOTOR_State = h.NXTMOTOR_State(); 
     69 
    7270 
    7371 
     
    204202end% 
    205203 
     204 
     205%% save motor state back to handle 
     206h.NXTMOTOR_State(NXTMOTOR_State); 
     207 
     208 
    206209end%function 
  • branches/atorf/RWTHMindstormsNXT/SetAngleLimit.m

    r3 r117  
    4949 
    5050%% Check parameter 
    51 global NXTMOTOR_State; 
    52  
    53 if isempty(NXTMOTOR_State) 
    54     initializeGlobalMotorStateVar; 
    55 end%if 
    56  
    5751whatmotor = GetMotor; 
    5852 
     
    6660 
    6761 
     62%% get default handle & motorstate 
     63h = COM_GetDefaultNXT(); 
     64NXTMOTOR_State = h.NXTMOTOR_State(); 
     65 
     66 
    6867%% Set angle limit 
    6968NXTMOTOR_State(whatmotor + 1).AngleLimit = NewLimit; 
     
    7473end%if 
    7574 
     75 
     76%% save motor state back to handle 
     77h.NXTMOTOR_State(NXTMOTOR_State); 
     78 
     79 
    7680end%function 
  • branches/atorf/RWTHMindstormsNXT/SetMemoryCount.m

    r3 r117  
    4141% *********************************************************************************************** 
    4242 
    43 global NXTMOTOR_State; 
    4443 
    45 if isempty(NXTMOTOR_State) 
    46     initializeGlobalMotorStateVar; 
    47 end%if 
     44% get default handle & motorstate 
     45h = COM_GetDefaultNXT(); 
     46NXTMOTOR_State = h.NXTMOTOR_State(); 
    4847 
    4948NXTMOTOR_State(number+1).MemoryCount = angle; 
    5049 
     50% save motor state back to handle 
     51h.NXTMOTOR_State(NXTMOTOR_State); 
     52 
     53 
    5154end % end function 
  • branches/atorf/RWTHMindstormsNXT/SetPower.m

    r3 r117  
    4545 
    4646%% Check parameter 
    47 global NXTMOTOR_State; 
    48  
    49 if isempty(NXTMOTOR_State) 
    50     initializeGlobalMotorStateVar; 
    51 end%if 
    52  
    5347whatmotor = GetMotor; 
    5448 
     
    6054    error('MATLAB:RWTHMindstormsNXT:Motor:invalidPower', 'Power must be between -100 and 100') 
    6155end%if 
     56 
     57%% Get handle & motorstate 
     58h = COM_GetDefaultNXT(); 
     59NXTMOTOR_State = h.NXTMOTOR_State(); 
    6260 
    6361 
     
    7876end%if 
    7977 
     78%% save state back to handle 
     79h.NXTMOTOR_State(NXTMOTOR_State); 
     80 
     81 
    8082end%function 
  • branches/atorf/RWTHMindstormsNXT/SetRampMode.m

    r3 r117  
    4646 
    4747%% Check parameter 
    48 global NXTMOTOR_State; 
    49  
    50 if isempty(NXTMOTOR_State) 
    51     initializeGlobalMotorStateVar; 
    52 end%if 
    53  
    5448% this catches errors if SetMotor wasn't called before 
    5549whatmotor = GetMotor; 
     50 
     51 
     52%% get default handle & motorstate 
     53h = COM_GetDefaultNXT(); 
     54NXTMOTOR_State = h.NXTMOTOR_State(); 
     55 
    5656 
    5757 
     
    7272end%if 
    7373 
     74 
     75%% save motor state back to handle 
     76h.NXTMOTOR_State(NXTMOTOR_State); 
     77 
     78 
    7479end%function 
  • branches/atorf/RWTHMindstormsNXT/SetTurnRatio.m

    r3 r117  
    6060 
    6161%% Check parameter 
    62 global NXTMOTOR_State; 
    63  
    64 if isempty(NXTMOTOR_State) 
    65     initializeGlobalMotorStateVar; 
    66 end%if 
    67  
    6862whatmotor = GetMotor; 
    6963 
     
    7569    error('MATLAB:RWTHMindstormsNXT:Motor:invalidTurnRatio', 'TurnRatio must be between -100 and 100') 
    7670end%if 
     71 
     72 
     73%% get default handle & motorstate 
     74h = COM_GetDefaultNXT(); 
     75NXTMOTOR_State = h.NXTMOTOR_State(); 
    7776 
    7877 
     
    8887end%if 
    8988 
     89 
     90%% save motor state back to handle 
     91h.NXTMOTOR_State(NXTMOTOR_State); 
     92 
     93 
    9094end%function 
  • branches/atorf/RWTHMindstormsNXT/SpeedRegulation.m

    r3 r117  
    5151 
    5252%% Check parameter 
    53 global NXTMOTOR_State; 
    54  
    55 if isempty(NXTMOTOR_State) 
    56     initializeGlobalMotorStateVar; 
    57 end%if 
    5853 
    5954% this catches errors if SetMotor wasn't called before 
    6055whatmotor = GetMotor; 
     56 
     57%% get default handle & motorstate 
     58h = COM_GetDefaultNXT(); 
     59NXTMOTOR_State = h.NXTMOTOR_State(); 
     60 
    6161 
    6262 
     
    100100end%if 
    101101 
     102%% save motor state back to handle 
     103h.NXTMOTOR_State(NXTMOTOR_State); 
     104 
     105 
    102106end%function 
  • branches/atorf/RWTHMindstormsNXT/SyncToMotor.m

    r3 r117  
    6464 
    6565%% Check parameter 
    66 global NXTMOTOR_State; 
    67  
    68 if isempty(NXTMOTOR_State) 
    69     initializeGlobalMotorStateVar; 
    70 end%if 
    7166 
    7267whatmotor = GetMotor; 
     
    7873    end 
    7974end 
     75 
     76%% get default handle & motorstate 
     77h = COM_GetDefaultNXT(); 
     78NXTMOTOR_State = h.NXTMOTOR_State(); 
     79 
    8080 
    8181%% Set synchronization mode 
     
    145145end%if 
    146146 
     147%% save motor state back to handle 
     148h.NXTMOTOR_State(NXTMOTOR_State); 
     149 
     150 
     151 
    147152end%function