-
Notifications
You must be signed in to change notification settings - Fork 0
color.h
Contains functions for normalized grey scale color sensing.
The struct type for color sensors is defined as
typedef struct Color
{
sensor s;
double k, l;
}
color;
consisting of a color sensor object (s
) and calibration parameters k
and l
.
The constructor for color
is defined as
color colorNew(char sport);
where sport
is the port of the designated color sensor in a character format.
If, for example, a color sensor is connected to the port 2, the corresponding color
would be constructed using
color foo;
foo = colorNew('2');
Note, the default color profile (defined by k
and l
fields), where k = 1.0
and l = 0.0
, is used when constructing color
. The profile can be changed manually by changing the values of k
and l
fields manually,
...
foo.k = 2.33;
foo.l = 1.23;
or by using colorProfileCalib
,
...
colorProfileCalib(&foo, "path/to/some/profile_k", "path/to/some/profile_l");
or colorProfileLoad
,
...
colorProfileLoad(&foo, "path/to/some/profile_k", "path/to/some/profile_l");
functions.
double colorRead(color cs);
- reads and returns normalized grey scale color value from color sensor in %
- Parameters:
-
color cs
- color sensor object
-
void colorProfileCalib(color *cs, char *profile_k, char *profile_l);
- calibrates and loads color profile
- Parameters:
-
color *cs
- pointer to color sensor object -
char *profile_k
-k
profile file name string -
char *profile_l
-l
profile file name string
-
void colorProfileLoad(color *cs, char *profile_k, char *profile_l);
- loads color profile from profile files
- Parameters:
-
color *cs
- pointer to color sensor object -
char *profile_k
-k
profile file name string -
char *profile_l
-l
profile file name string
-
Suppose the k
and l
are the sensor calibration parameters, then the normalization of sensor reading is calculated by
normalized reading = k * ( reading + l )
The k
and l
parameters are derived from the raw readings of black and white color values and are calculated as
k = 100 / (white - black)
and
l = - black
The colorProfileCalib
function uses the averages 50 raw readings of black and white to achieve greater accuracy when calibrating k
and l
parameters. This number is hard-coded, but can be modified easily by changing the code under // read and sum some number of values
and // divide by number of values read
comments in color.c
.