Changeset 502

Show
Ignore:
Timestamp:
12/05/08 16:07:15 (4 years ago)
Author:
atorf
Message:

Updated analog sensor functions to work on very fast USB connections (check valid flag)

Location:
trunk/mfiles
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/mfiles/Contents.m

    r501 r502  
    11% RWTH - Mindstorms NXT Toolbox 
    2 % Version 2.03 04-Dec-2008 
     2% Version 2.03 05-Dec-2008 
    33% Files 
    44%   CalibrateColor             - Enables calibration mode of the HiTechnic color sensor 
  • trunk/mfiles/GetLight.m

    r307 r502  
    3030% Signature 
    3131%   Author: Linus Atorf, Alexander Behrens (see AUTHORS) 
    32 %   Date: 2007/10/15 
     32%   Date: 2008/12/05 
    3333%   Copyright: 2007-2008, RWTH Aachen University 
    3434% 
     
    6060    in = NXT_GetInputValues(port, handle); 
    6161 
     62%% Check valid-flag, re-request data if necessary 
     63    if ~in.Valid 
     64        % init timeout-counter 
     65        startTime = clock(); 
     66        timeOut = 0.1; % in seconds 
     67        % loop until valid 
     68        while (~in.Valid) && (etime(clock, startTime) < timeOut) 
     69            in = NXT_GetInputValues(port, handle); 
     70        end%while 
     71        %TODO please note that we DO NOT warn or do anything else if this 
     72        %procedure above times out -- that seems ok, since we didn't do 
     73        %that before (old ver. up to 2.02) either... 
     74        % in that case, the returned value will probably be invalid... 
     75        % dangerous. 
     76        % solutions: either WARN, or return NaN... 
     77    end%if 
     78     
    6279%% Return normalized sound value (0...1023 / 10 Bit)     
    6380    light = double(in.NormalizedADVal); 
  • trunk/mfiles/GetSound.m

    r307 r502  
    3030% Signature 
    3131%   Author: Linus Atorf, Alexander Behrens (see AUTHORS) 
    32 %   Date: 2007/10/15 
     32%   Date: 2008/12/05 
    3333%   Copyright: 2007-2008, RWTH Aachen University 
    3434% 
     
    5959%% Call NXT_GetInputValues function 
    6060    in = NXT_GetInputValues(f_sensorport, handle); 
     61 
     62%% Check valid-flag, re-request data if necessary 
     63    if ~in.Valid 
     64        % init timeout-counter 
     65        startTime = clock(); 
     66        timeOut = 0.1; % in seconds 
     67        % loop until valid 
     68        while (~in.Valid) && (etime(clock, startTime) < timeOut) 
     69            in = NXT_GetInputValues(f_sensorport, handle); 
     70        end%while 
     71        %TODO please note that we DO NOT warn or do anything else if this 
     72        %procedure above times out -- that seems ok, since we didn't do 
     73        %that before (old ver. up to 2.02) either... 
     74        % in that case, the returned value will probably be invalid... 
     75        % dangerous. 
     76        % solutions: either WARN, or return NaN... 
     77    end%if 
     78         
    6179     
    6280%% Return normalized sound value (0...1023 / 10 Bit) 
  • trunk/mfiles/GetSwitch.m

    r307 r502  
    3131% Signature 
    3232%   Author: Linus Atorf, Alexander Behrens (see AUTHORS) 
    33 %   Date: 2007/10/15 
     33%   Date: 2008/12/05 
    3434%   Copyright: 2007-2008, RWTH Aachen University 
    3535% 
     
    7676    in = NXT_GetInputValues(f_sensorport, handle); 
    7777     
     78%% Check valid-flag, re-request data if necessary 
     79    if ~in.Valid 
     80        % init timeout-counter 
     81        startTime = clock(); 
     82        timeOut = 0.1; % in seconds 
     83        % loop until valid 
     84        while (~in.Valid) && (etime(clock, startTime) < timeOut) 
     85            in = NXT_GetInputValues(f_sensorport, handle); 
     86        end%while 
     87        %TODO please note that we DO NOT warn or do anything else if this 
     88        %procedure above times out -- that seems ok, since we didn't do 
     89        %that before (old ver. up to 2.02) either... 
     90        % in that case, the returned value will probably be invalid... 
     91        % dangerous. 
     92        % solutions: either WARN, or return NaN... 
     93    end%if 
     94         
    7895%% Do threshold decision 
    7996    % 511 should be ok, being right in the middle between both "peaks"