Changeset 902

Show
Ignore:
Timestamp:
09/16/10 03:29:54 (3 years ago)
Author:
atorf
Message:

Updated comments and code for HiTechnic? Color V2 sensor…

Location:
trunk/mfiles
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/mfiles/CalibrateColor.m

    r896 r902  
    11function [] = CalibrateColor(port, mode, varargin) 
    2 % Enables calibration mode of the HiTechnic color sensor 
     2% Enables calibration mode of the HiTechnic color sensor V1 
    33% 
    44% Syntax 
     
    88% 
    99% Description 
    10 %   Calibrate the color sensor with white balance and black value. 
    11 %   I don't know whether calibration of color sensor makes sence 
    12 %   Hitech doku says nothing, some internet freaks say it is necessary, 
    13 %   but it works and has effect ;-) The sensor LEDs make a short flash 
     10%   Do not use this function with the HiTechnic Color Sensor V2. It has a 
     11%   bright white flashing LED. 
     12%   This function is intended for the HiTechnic Color Sensor V1 (milky, 
     13%   weak white LED). 
     14% 
     15%   Calibrate the color sensor with white and black reference value. 
     16%   It's not known whether calibration of the color sensor makes sense. 
     17%   HiTechnic doku says nothing, some people say it is necessary, 
     18%   but it works and has effect ;-). The sensor LEDs make a short flash 
    1419%   after successful calibration. When calibrated, the sensor keeps this 
    1520%   information in non-volatile memory. 
    1621%   There are two different modes for calibration:  
    17 %     |mode| = 1: white balance calibration 
     22% * |mode| = 1: white balance calibration 
    1823%          Puts the sensor into white balance calibration mode. For best results 
    1924%          the sensor should be pointed at a diffuse white surface at a distance 
     
    2126%          a second the sensor lights will flash and the calibration is 
    2227%          done.  
    23 %     |mode| = 2: black level calibration 
     28% * |mode| = 2: black level calibration 
    2429%          Puts the sensor into black/ambient level calibration mode. For best 
    2530%          results the sensor should be pointed in a direction with no obstacles 
     
    5459% Signature 
    5560%   Author: Rainer Schnitzler, Linus Atorf (see AUTHORS) 
    56 %   Date: 2008/08/01 
     61%   Date: 2010/09/16 
    5762%   Copyright: 2007-2010, RWTH Aachen University 
    5863% 
     
    8691    end%if 
    8792     
     93%% Check whether we're working with the right sensor 
     94    
     95   % found registers by trial & error, since V1 spec wasn't online 
     96   data = COM_ReadI2C(port, 8, 2, 16, handle); 
     97   data = strtrim(char(data')); 
     98   if ~strcmp(data, 'Color') 
     99       % thats bad, not a color sensor V1 
     100       if strcmp(data, 'ColorPD') 
     101           error('MATLAB:RWTHMindstormsNXT:Sensor:colorCalibrationForV2', ... 
     102                ['You''re trying to calibrate a HiTechnic Color V2 sensor. ' ... 
     103                 'This is not necessary for the V2 sensor hardware, and clearly ' ... 
     104                 'NOT RECOMMENDED if the sensor is working correctly. If you''re ' ... 
     105                 'absolutely sure you want to call the calibration anyway (and maybe ' ... 
     106                 'permanently deteriorate the sensor''s performance), ' ... 
     107                 'you''ll find a way around this error.']); 
     108       else 
     109           error('MATLAB:RWTHMindstormsNXT:Sensor:colorCalibrationForUnknown', ... 
     110                ['You''re trying to use color calibration for the HiTechnic ' ... 
     111                 'Color sensor V1. It seems this sensor is not connected to ' ... 
     112                 'the according port. Make sure sensor, hardware version (Color V1) ' ... 
     113                 'and port match, then try again.']); 
     114       end%if 
     115   end%if 
     116    
     117 
     118     
    88119     
    89120%% create this I2C command to start calibration 
  • trunk/mfiles/GetColor.m

    r896 r902  
    11function [index r g b] = GetColor(port, mode, varargin) 
    2 % Reads the current value of the HiTechnic Color sensor 
     2% Reads the current value of the HiTechnic Color V1 or V2 sensor 
    33% 
    44% Syntax 
    5 %   |[index r g b] = GetColor(port)| 
     5%   |[index r g b] = GetColor(port, mode)| 
    66% 
    7 %   |[index r g b] = GetColor(port, handle)| 
     7%   |[index r g b] = GetColor(port, mode, handle)| 
    88% 
    99% Description 
    10 %   |degree = GetColor(port)| returns the index color value and the RGB-values of the 
    11 %   HiTechnic Color sensor. The color index for mode=0 and mode=1 corresponds to the following 
    12 %   table, but the color values don't be pure RGB-values. Tests give best results for  
    13 %   RGB-colors in brackets: 
    14 %           0 = black (0-0-0) 
     10%   This function returns the color index and the RGB-values of the 
     11%   HiTechnic Color sensor. There are two different hardware versions of the sensor.  
     12% 
     13% * The old Color sensor V1 has a single weak LED which is always on once 
     14%   connected. You can spot little red, green and blue lights behind the 
     15%   milky lens. This sensor can be calibrated using the function 
     16%   |CalibrateColor|. It has sometimes trouble getting accurate results. 
     17%   You can use all values for |mode|. Try which one works best for you. 
     18% 
     19% * The new Color sensor V2 has a single bright white LED which is always flashing 
     20%   once connected. The lens is relatively clear. This sensor gives great 
     21%   accuary for most colors, even at some distance. Only |mode = 0| is 
     22%   supported. Other modes will return wrong values. The sensor works fine  
     23%   as it comes, it SHOULD NOT BE CALIBRATED. 
     24% 
     25% 
     26%   The color index values roughly correspond to the following 
     27%   table (when using modes 0 and 1): 
     28%           0 = black  
    1529%           1 = violet 
    1630%           2 = purple 
     
    2640%           17 = white 
    2741% 
    28 %   The color index (0..63) for mode=2 and mode=3 will return a 6 bit color index number, which encodes 
    29 %   red in bit 5 an 4, green in bit 3 and 2 and blue in bit. It gives good results to identify a color 
    30 %   by one value.  
     42%   The RGB-Values will be returned depending on the mode parameter. 
     43% * |mode = 0| : RGB = the current detection level for the color components red, green and blue 
     44%                  in an range of 0 to 255. Use this setting for color sensor V2 
    3145% 
    32 %   The RGB-Values will be returned depending on the mode parameter 
    33 %       mode = 0 : RGB = the current detection level  for the color components red, green and blue 
    34 %                  in an range of 0 to 255               
    35 %       mode = 1 : RGB = the current relative detection level  for the color components red, green and blue 
     46% * |mode = 1| : RGB = the current relative detection level  for the color components red, green and blue 
    3647%                  in an range of 0 to 255. The highest value of red, green and blue is set to 255 and 
    37 %                  the other components are adjusted proportionally.  
    38 %       mode = 2 : RGB = the analog signal levels for the three 
    39 %                  color components red, green and blue with an accurancy of 10 bit (0 to 1023). 
    40 %       mode = 3 : RGB = the current relative detection level  for the color components red, green and blue 
    41 %                  in an range of 0 to 3.  
     48%                  the other components are adjusted proportionally. Only 
     49%                  V1. 
     50% * |mode = 2| : RGB = the analog signal levels for the three 
     51%                  color components red, green and blue with an accurancy 
     52%                  of 10 bit (0 to 1023). Only V1. 
     53% * |mode = 3| : RGB = the current relative detection level  for the color components red, green and blue 
     54%                  in an range of 0 to 3. Only V1. 
     55% 
     56%   The color index (0..63) for mode 2 and mode 3 will return a 6 bit color index number, which encodes 
     57%   red in bit 5 and 4, green in bit 3 and 2 and blue in bit 1 (?).  
    4258% 
    4359%   The given |port| number specifies the connection port. The value |port| can be addressed by the 
     
    4561%   the NXT Brick.  
    4662% 
    47 %   For more complex settings the functions |NXT_LSRead| and |NXT_LSWrite| can be used. 
     63%   For more complex settings the function |COM_ReadI2C| can be used. 
    4864% 
    4965%   The last optional argument can be a valid NXT handle. If none is 
     
    6076% Signature 
    6177%   Author: Rainer Schnitzler, Linus Atorf (see AUTHORS) 
    62 %   Date: 2008/10/01 
     78%   Date: 2010/09/16 
    6379%   Copyright: 2007-2010, RWTH Aachen University 
    6480% 
     
    140156                  r = bitand(x,3); % Bit 4+5: red; 
    141157                else 
    142                   error('MATLAB:RWTHMindstormsNXT:illegalInputArgument', 'Mode has to be 0, 1 or 2.'); 
     158                  error('MATLAB:RWTHMindstormsNXT:illegalInputArgument', 'Mode has to be 0, 1, 2, or 3.'); 
    143159                end 
    144160             end 
  • trunk/mfiles/OpenColor.m

    r896 r902  
    1111%   port. The value |port| can be addressed by the symbolic constants 
    1212%   |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to the labeling on the NXT Brick. 
     13%   This functions works for both HiTechnic Color sensors V1 and V2. 
    1314% 
    1415%   With |GetColor(port)| you can receive color values as RGB or Index. 
     
    3132% Signature 
    3233%   Author: Rainer Schnitzler (see AUTHORS) 
    33 %   Date: 2008/10/01 
     34%   Date: 2010/09/16 
    3435%   Copyright: 2007-2010, RWTH Aachen University 
    3536%