0

Line Robot - Basic lessons - Color 1/2

The robot uses 2 ML-R 6-channel color sensor CAN Bus (mrm-col-can) to detect green markers. You can use values for each of the 6 basic colors the sensor outputs. The problem with this approach is variable external illumination. For example, green (one of the mentioned 6) sub-sensor returns value 150 when positioned over green and 50 over black. It seems appropriate; we can say that if value is over 100, then the color under sensor must be green. However, later sun starts shining more brightly and the situation changes: with sensor positioned above green, we get value 250 and above black 120. As both of them report values bigger than 100, comparing the value to 100 is meaningless now.

We are not the first one noticing this problem, so a solution was invented: HSV (Hue-Saturation-Value) scale. Hue and saturation are intrinsic properties of a particular color which do not change (much) when external illumination changes. We are lucky that the sensor can return HSV values, too, besides 6 colors.

First, You must determine HSV values of the color You are interested in. Take Your robot and position one of the color sensors above a green marker. For example, choose left sensor. Issue "lon" command in the terminal and watch illumination diodes turning on. Now a second command: "hsv". HSV values will be displayed, like in the picture on the right: hue is 54, saturation is 148 and value is 96. Let's make a program that will recognize green with left color sensor (C++ ordinal number 0) based on this result:
void RobotLine::loop() {
	if (setup())
		illumination(0, 1);

	if (hue(0) >= 50 && hue(0) <= 58)
		print("Green");
	print("\n\r");
}
During the first run, command
illumination(sensorNumber, intensity);
turns on left sensors' (number 0) illumination LEDs, intensity 1 (second argument). This is mandatory. Otherwise the values will be very small, unless You increase chip's sensitivity. We will note cope with that functionality here. Just turn the lights on.

In the second "if"
hue(0)
returns measured color's hue. "0" stands again for the left sensor. To measure right sensor, the function will be "hue(1)". If You are interested in saturation or value, use:
saturation(0)
or
value(0)

Task: stop on green.

Display "?" (code 63). Follow line. On intersection stop. If there is any marker, display "G" (code 71). Use the following line-following code as a basis for Your program:

void RobotLine::loop() {
	if (line(5))
		go(10, 80);
	else if (line(3))
		go(80, 10);
	else
		go(60, 60);
}