0

Line Robot - Markers

Task

The robot must recognize green markers so it uses 2 pcs. of ML-R 6-channel color sensor CAN Bus (mrm-col-can).

Predefined actions

There is quite a number of different ActionBase derived classes related to ML-R 6-channel color sensor CAN Bus (mrm-col-can) in mrm-robot.h file. You do not have to study the code now.

class ActionColorIlluminationOff : public ActionBase {
	void perform();
public:
	ActionColorIlluminationOff(Robot* robot) : ActionBase(robot, "lof", "Light off", 4, ID_MRM_COL_CAN) {}
};

...

class ActionColorTestHSV : public ActionBase {
	void perform();
public:
	ActionColorTestHSV(Robot* robot) : ActionBase(robot, "hsv", "Test HSV", 4, ID_MRM_COL_CAN) {}
};
Appropriate functions that implement perform() are in mrm-robot.cpp:
void ActionColorIlluminationOff::perform() { _robot->colorIlluminationOff(); }
...
void ActionColorTestHSV::perform() { _robot->colorTestHSV(); }
The functions are defined in mrm-robot.cpp file. Purpose of these actions is just to display them in menu so that You can test the sensors and store patterns. They are just a part of RobotBase class - a black box for You, that delivers some nice functions for all the robots that use it. So, every robot that is derived from RobotBase class will have this menu. It will be displayed only if the system detects any color sensor.

Menu

Run the program and choose "col" in the main menu. This will show a submenu in the picture left.

  • lof and lon turn illumination off and on. It is almost always a good idea to turn it on. Different intensities can be chosen in code. Here, only the weakest can be selected.
  • per erases all the recorded patterns. More about patterns later. It is possible to erase only selected ones programmatically, but here all will be deleted.
  • ppr prints all the recorded patterns. This is an easy way to check what has been recorded.
  • pre not implemented yet (but is in code). Use "hsv" to get similar results.
  • par records a pattern.
  • 6co tests 6 colors of the current surface under the sensors: red, green, blue, orange, violet and cyan, with 6 built-in sensors.
  • hsv tests HSV (Hue Saturation Value) of the surface.
  • x main menu.

6 colors and HSV

Sensor's native mode is to measure 6 different colors. You can use them to recognize green markers. The other way is to use HSV (Hue Saturation Value). Sensor calculates the HSV values. The 6 colors or HSV values can be fetched from the sensor, or You can use recorded patterns. You can define a pattern by presenting a chosen color to the sensor and instruct it to store its characteristics: 6 colors. If You present an unknown color later, You can ask it which stored color (pattern) is the closest.

Main purpose of HSV values is to exclude external light intensity. Hue and saturation should be constant for a given color, under various illumination intensities. So, in theory, HSV is preferable. The reality is a little tricky however. White and black can have any H and S values, thus green included. So, taking V into account could be a good idea. What is worse, when the robot crosses black to white, or vice versa, it can pick the green V, too. Fortunately, in crossings, the color sensors should not experience the last problem.

In the end, which method is the best? It is difficult to say. You should try automatic pattern recognition by both HSV and 6 colors, but some manual tweaking will probably be needed.

Record pattern

Put a chosen color below a sensor, enter "lon" and "par" commands. Interactive screen will ask You for sensor's number and pattern's number. If You wait too much a timeout will occur. Otherwise, the pattern will be saved.

If You made a mistake, repeat the procedure and record it again. It is not necessary to repeat "lon". The new value will override previous one. Patterns are not lost when You switch power off.

It is a good idea to use "lof" to switch the illumination off after the session. LED is quite strong. Also be careful when choosing even higher intensities (not possible in menu, but is in code). Check the temperature.

Print patterns

Here is an example in which each sensor holds 5 recorded patterns. Choose "ppr" shortcut.

  • 0 red.
  • 1 blue.
  • 2 green.
  • 3 white.
  • 4 black.
The sensor doesn't come with predefined patterns. You must record them.

Test HSV

Choose "lon", followed by "hsv" shortcuts and put different surfaces below the sensor. For each sensor in system 3 HSV values will be displayed, followed by "By HSV" and "By col" columns. The last 2 are recognized patterns' numbers, by HSV and by 6 colors.

How does the sensor decide which pattern is the closest? It uses 6-dimensional space for 6 colors and 3-dimensional for HSV and calculates metric between test point in space and all the existing pattern-points. The metric is a close approximation of distance, but avoids square roots.

Test 6 colors

Testing 6 colors will display sensors' raw values. It is probably needles to say that "Bl" is blue, "Gr" green, "Or" orange, "Re" red, "Vi" violet, and "Ye" yellow. Use "lon" followed by "6co" to get these results. Do not forget "lon", otherwise You will get very small numbers. It is possible to increase them even in low light conditions, but You have to turn on-chip amplification on. You can choose different values.

Usage in code

Take a look at

void RobotLine::lineFollow(){
...
if (mrm_col_can->patternRecognizedBy6Colors(0) == 2) ...
...
code in mrm-robot-line.cpp. Also study mrm-col-can.h header in the sensor's library.