Changeset 902
- Timestamp:
- 09/16/10 03:29:54 (3 years ago)
- Location:
- trunk/mfiles
- Files:
-
- 3 modified
-
CalibrateColor.m (modified) (5 diffs)
-
GetColor.m (modified) (5 diffs)
-
OpenColor.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/mfiles/CalibrateColor.m
r896 r902 1 1 function [] = CalibrateColor(port, mode, varargin) 2 % Enables calibration mode of the HiTechnic color sensor 2 % Enables calibration mode of the HiTechnic color sensor V1 3 3 % 4 4 % Syntax … … 8 8 % 9 9 % 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 14 19 % after successful calibration. When calibrated, the sensor keeps this 15 20 % information in non-volatile memory. 16 21 % There are two different modes for calibration: 17 % |mode| = 1: white balance calibration22 % * |mode| = 1: white balance calibration 18 23 % Puts the sensor into white balance calibration mode. For best results 19 24 % the sensor should be pointed at a diffuse white surface at a distance … … 21 26 % a second the sensor lights will flash and the calibration is 22 27 % done. 23 % |mode| = 2: black level calibration28 % * |mode| = 2: black level calibration 24 29 % Puts the sensor into black/ambient level calibration mode. For best 25 30 % results the sensor should be pointed in a direction with no obstacles … … 54 59 % Signature 55 60 % Author: Rainer Schnitzler, Linus Atorf (see AUTHORS) 56 % Date: 20 08/08/0161 % Date: 2010/09/16 57 62 % Copyright: 2007-2010, RWTH Aachen University 58 63 % … … 86 91 end%if 87 92 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 88 119 89 120 %% create this I2C command to start calibration -
trunk/mfiles/GetColor.m
r896 r902 1 1 function [index r g b] = GetColor(port, mode, varargin) 2 % Reads the current value of the HiTechnic Color sensor2 % Reads the current value of the HiTechnic Color V1 or V2 sensor 3 3 % 4 4 % Syntax 5 % |[index r g b] = GetColor(port )|5 % |[index r g b] = GetColor(port, mode)| 6 6 % 7 % |[index r g b] = GetColor(port, handle)|7 % |[index r g b] = GetColor(port, mode, handle)| 8 8 % 9 9 % 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 15 29 % 1 = violet 16 30 % 2 = purple … … 26 40 % 17 = white 27 41 % 28 % The color index (0..63) for mode=2 and mode=3 will return a 6 bit color index number, which encodes29 % red in bit 5 an 4, green in bit 3 and 2 and blue in bit. It gives good results to identify a color30 % 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 31 45 % 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 36 47 % 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 (?). 42 58 % 43 59 % The given |port| number specifies the connection port. The value |port| can be addressed by the … … 45 61 % the NXT Brick. 46 62 % 47 % For more complex settings the function s |NXT_LSRead| and |NXT_LSWrite| can be used.63 % For more complex settings the function |COM_ReadI2C| can be used. 48 64 % 49 65 % The last optional argument can be a valid NXT handle. If none is … … 60 76 % Signature 61 77 % Author: Rainer Schnitzler, Linus Atorf (see AUTHORS) 62 % Date: 20 08/10/0178 % Date: 2010/09/16 63 79 % Copyright: 2007-2010, RWTH Aachen University 64 80 % … … 140 156 r = bitand(x,3); % Bit 4+5: red; 141 157 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.'); 143 159 end 144 160 end -
trunk/mfiles/OpenColor.m
r896 r902 11 11 % port. The value |port| can be addressed by the symbolic constants 12 12 % |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. 13 14 % 14 15 % With |GetColor(port)| you can receive color values as RGB or Index. … … 31 32 % Signature 32 33 % Author: Rainer Schnitzler (see AUTHORS) 33 % Date: 20 08/10/0134 % Date: 2010/09/16 34 35 % Copyright: 2007-2010, RWTH Aachen University 35 36 %
