Changeset 100

Show
Ignore:
Timestamp:
06/24/08 17:23:27 (5 years ago)
Author:
atorf
Message:

Added simple Accelerator demo, improved basic functions

Location:
branches
Files:
2 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/atorf/USB_ToolboxTest_Windows/NXT_LSRead.m

    r25 r100  
    169169 
    170170BytesRead = content(1); 
     171 
     172%TODO see below 
     173%FIXME fix outputting uint8, convert to double first! 
     174 
    171175% avoid index out of bounds 
    172176tmpEnd = min(BytesRead + 1, length(content)); 
  • branches/behrens/RWTHMindstormsNXT/SendMotorSettings.m

    r79 r100  
    11function SendMotorSettings(f_port, f_power, f_angle, f_speed, f_sync, f_ratio, f_ramp) 
    2 % Sends previously specified settings to current active motor. 
     2% Sends previously specified settings to the currently active motor. 
    33 
    44% Syntax 
     
    1919% 
    2020% Note: 
    21 %   All settings like power, angle limit and so on, will only take effect once you send them to the 
    22 %   motor using THIS function. Note that if you have synced two motors together, this function 
     21%   All settings like power, angle limit, and so on, will only take effect once you send them to the 
     22%   motor using THIS function. Note that if you have synced two motors together this function 
    2323%   internally sends two packets to both the motors. This is required, but you can work as if this 
    2424%   was just one command. 
  • branches/workshop/Accelerator/GetAccelerator.m

    r34 r100  
    44    %-----------------------------LSWRITE---------------------------------- 
    55 
    6     % create this I2C command. basically all we want to do is request 1 
    7     % byte, the current sensor reading! 
     6    % create this I2C command. basically all we want to do is request 6 
     7    % bytes, the current sensor reading! 
    88     
    99    RequestLen = 6; 
    10     I2Cdata = hex2dec(['02'; '42']); % Read Measurement Byte 0 (see LEGO Mindstorms NXT  
    11                                      % Ultrasonic Sensor - I2C Communication Protocol) 
     10    I2Cdata = hex2dec(['02'; '42']);  
    1211     
    1312        NXT_LSWrite(f_sensorport, RequestLen, I2Cdata, 'dontreply') 
     
    2322    % should never get ready... 
    2423     
     24    %instead of "wasting time" in the idle loop below, waiting for the 
     25    %sensor to get ready, we could also just wait some time here and 
     26    %collect the sensor bytes then... 
     27    %pause(0.015); 
     28     
     29     
    2530    BytesReady = 0; 
    26     while (BytesReady == 0) 
    27         %TODO some sort of timeout in here in case we never get an answer? 
     31    ticID = 34; %fixme randomly, dangerous 
     32    timeout = 2; % in s 
     33    tictic(ticID);  
     34    status = -1; 
     35    %idlecount = 0; 
     36    while ((BytesReady < 6) ||  (status ~= 0)) && (toctoc(ticID) < timeout) 
     37         
    2838        [BytesReady status] = NXT_LSGetStatus(f_sensorport); 
     39        if status == 221 % communication bus error 
     40            % recursive! 
     41            acc_vector = GetAccelerator(f_sensorport); 
     42            return 
     43        end%if 
     44        %idlecount = idlecount + 1; 
    2945    end%if 
    3046     
    31     acc_vector = -1; 
     47    %fprintf('idlecount = %d \n', idlecount) 
     48%     if (status ~= 0) || (BytesReady < 6) 
     49%         disp('whoa') 
     50%     end%if 
     51     
     52    acc_vector = [NaN NaN NaN]; 
    3253 
    3354%% If ready get object distance (ultrasonic sensor value)     
     
    3859        [data BytesRead] = NXT_LSRead(f_sensorport); 
    3960         
     61        % IMPORTANT, DON'T FORGET!!! 
     62        % or change in NXT_LSRead 
     63        data = double(data); 
     64         
    4065        if BytesRead > 5 
    41             if (data(1) > 127) data(1) = data(1) - 256; end 
     66            % as seen in the hitechnic example code... 
     67            % this is just a byte shift and could be done better, but 
     68            % should work 
     69            if (data(1) > 127)  
     70                data(1) = data(1) - 256;  
     71            end 
    4272            if (data(2) > 127) data(2) = data(2) - 256; end 
    4373            if (data(3) > 127) data(3) = data(3) - 256; end 
     
    4878         
    4979        %------------------------------------------------------------------ 
     80    else 
     81        [tmp msg] = checkStatusByte(status); 
     82        fprintf('Invalid sensor reading, %d bytes received, status %d: %s\n', BytesReady, status, msg); 
     83         
    5084    end%if 
    5185