Me RGB Line Follower

微信截图_20160129150749

General

ME RGB line follower is designed for line-following. It has 4 RGB supplement lights and 4 light-sensitive receivers. The module applies to line following for either light-colored tracks on dark backgrounds, or dark tracks on light-colored backgrounds. All kinds of RGB line following modules are applicable, as long as the grey scale of the chromatic aberration between the background and the track is higher than the threshold (the higher the chromatic aberration, the better the line following performance). The module is characterized by fast detection, field learning function through keys and excellent adaptability. A blue-white labeled interface is equipped, indicating that it is a dual-digital, I2C interface that needs to be connected to the mainboard with a blue-white marking interface.

Technical Specification

  • Operating voltage: 5V DC
  • Operating temperature: 0 ºC~70 ºC
  • Detection height: it is suggested that the sensor is 5mm~15mm from the track, depending on material of the track and illumination.
  • Signal mode: I2C communication (corresponding to the blue and white labels)
  • Dimensions: 48 x 72 x 26.5 mm (W x H x D)

Functional Characteristics

  • Arduino IDE programmable, with runtime library to simplify programming;
  • Four LEDs for feedback of line-following and learning of new surroundings;
  • RJ25 interface for convenient connection;
  • Suitable for metal parts of Makeblock DIY platform: the white area on the module is the reference area in contact with metal beams;
  • Modularized installation, compatible with LEGO;
  • Equipped with interfaces compatible with most Arduino control boards;
  • Field learning function: identifying and recording background of the field and color of the route;
  • Supporting eeprom storage: data learned will be stored in eeprom, preventing data loss in case of power failure;
  • Colors of RGB supplement lamps switchable: currently 3 colors switchable (read, green and blue), by pressing the switching key for 2 seconds;
  • Sensitivity of line-following is adjustable;
  • Reverse polarity protection, protecting IC in case of reverse polarity;
  • Up to 4 line following sensors available on one main board.

Principle

Me RGB line follower provides 4 pairs of RGB transmitters and light-sensitive receivers, as shown in the following figure:

When RGB passes through different color backgrounds, the light-sensitive receivers converts the received light information into electrical signals, and outputs specific values from the analog ports after passing through the amplifier. The software then uses the analog values of the four light-sensitive receivers as a fusion algorithm to finally calculate the deviation of the position of the output sensor module from the track. The user can directly use this offset to control the rotation speed of the left and right two motors.

Definitions of Pins

Me RGB line follower provides a 6-pin interface. The following table describes the function of each pin.

S/N Pin Function
1 SDA I2C data interface
2 SCL I2C clock interface
3 VCC Power line
4 GND Ground line
5 S2 I2C address assignment port
6 S1 2C address assignment port


Connection

RJ25 Connection

Me RGB line follower supports interfaces labeled white or blue. Therefore, you can connect it to an RJ25 interface with the blue or white label.

Taking Makeblock MegaPi as an example, you can connect to interfaces 5, 6, 7, and 8, as shown in the following figure:

微信截图_20160129151012

DuPont Connection

When using a DuPont cable to connect RGB line follower to the Arduino Uno mainboard, the A0 pin of the module needs to be connected to the ANALOG port as shown below:

微信截图_20160129151050

Learning Methods

In case of any change to the field, the surroundings or location where the RGB sensor is installed, it is suggested to start learning again.

The data learned will be stored in eeprom, avoiding data loss in case of power failure. The learning process includes 4 steps:

  1. Adjusting colors of supplement lamps: select suitable colors of the supplement lamps by long pressing the switching key according to colors of the field background and the line.
  2. Learning color of the background: install the RGB sensor in position, face the 4 RGB lamps right against the background, and click the key to make the 4 LEDs flash slowly. Learning will finish in 2~3 seconds, upon which the LEDs will stop flashing.
  3. Learning color of the track: install the RGB sensor in position, make the 4 RGB lights right against the track, and double-click the key to make the 4 LEDs flashing slowly. Learning will finish in 2~3 seconds, upon which the LEDs will stop flashing.
  4. Test and confirmation: keep the module in position, and adjust locations of the 4 sensors, to make sure they can detect colors of the background and the line properly. When detecting the background, LED of corresponding sensor will be on; and when detecting the line, the corresponding LED will be off.

Programming

Arduino Programming

When conducting Arduino programming, Makeblock-Library-master shall be called to control the RGB line follower.

Two enhanced 180 encoder motors are used for line-following control. Source files "MeRGBLineFollower" and "MeEnhanceEncoderOnBoard" must be included in the project root directory as follows:

Program Download Link

微信截图_20160129151123

"MeRGBLineFollower180motorAuriga.ino" is an example of line following, based on the Auriga control board, with 180-encoded motor as chassis. The following code is used:

微信截图_20160129151123

List of Main Functions and Features of Me RGB Line Follower

Function Features
void setKp(float value) Setting line following sensitivity, which is used for adjusting line following response speed. The larger the value is,more sensitive it turns.
uint8_t getStudyTypes(void) Obtaining learning status of the RGB sensor: 0-not learning, 1-learning background color, 2-learning track color
int16_t getPositionOffset(void) Obtaining offset of the sensor from the track. The output is taken as the product of the line following sensitivity Kp and the analog value resulted from fusion algorithm of the 4 sensors, ranging from -512 to 512. If it is larger than 0, it means that the line deflects to RGB4. The larger the value, the higher the offset. If it is smaller than 0, it means that the line deflects to RGB1. The greater the negative value, the higher the offset.
uint8_t getPositionState(void) As shown in the figure, bit0~bit3 represent RGB4, RGB3, RGB2 and RGB1 from left to right respectively.
"1" means that the background is detected (corresponding LED is on), while "0" means that the line is detected (corresponding LED is off).
"0000" means that all the 4 sensors detect the line (all the LEDs are off), with 0 returned;
"0111" means that the 4 sensors from left to right detect "line", "background", "background" and "background" respectively (the LEDs are off, on, on and on), with 7 returned;
"0011" means that the 4 sensors from left to right detect "line", "line", "background" and "background" respectively (the LEDs are off, off, on and on), with 3 returned.
uint8_t getADCValueRGB1(void) uint8_t getADCValueRGB2(void) uint8_t getADCValueRGB3(void) uint8_t getADCValueRGB4(void) Obtaining the ADC value of each probe, with a value ranging from 0 to 255 returned.
int8_t setRGBColour(uint8_t colour) Setting the color parameter for the RGB supplement light. The value "1" indicates red, "2" indicates green, and "3" indicates blue.


mBlock programming

Me RGB Line Follower is mBlock programmable, but "RGBLineFollower" or "RGBLineFollowerAdvanced" must be installed. Besides, if you use the 180 encoder motor as the chassis, the "EnhanceEncoderOnBoard " enhanced encoder motor is also needed.

RGBLineFollower

RGBLineFollower provides the basic functions for implementing line following.

To install this plug-in:
Open the mBlock software→ Extension → Extension Manager → Find plug-in packages "RGBLineFollower’ and "EnhanceEncoderOnBoard" → Download the plug-in packages. The following blocks are displayed:

微信截图_20160129151218

Description of the blocks:

  • Interface: Port1–Port12
  • Address: add1–add4 (0–3). Any port can be bound to any address, but one port of all related blocks in one program can be bound to only one address, and each address corresponds to only one RGB line following module.
Statement block Description
微信截图_20160129151218 Setting line following sensitivity, which is used for adjusting line following response speed. The larger the value is, the more sensitive it turns.
微信截图_20160129151218 Obtaining offset of the sensor from the track. The output is taken as the product of the line following sensitivity Kp and the analog value resulted from fusion algorithm of the 4 sensors, ranging from -512 to 512. If it is larger than 0, it means that the line deflects to RGB4. The larger the value, the higher the offset. If it is smaller than 0, it means that the line deflects to RGB1. The greater the negative value, the higher the offset.
微信截图_20160129151218 s shown in the figure, bit0~bit3 represent RGB4, RGB3, RGB2 and RGB1 from left to right respectively.
"1" means that the background is detected (corresponding LED is on), while "0" means that the line is detected (corresponding LED is off).
"0000" means that all the 4 sensors detect the line (all the LEDs are off), with 0 returned;
"0111" means that the 4 sensors from left to right detect "line", "background", "background" and "background" respectively (the LEDs are off, on, on and on), with 7 returned;
"0011" means that the 4 sensors from left to right detect "line", "line", "background" and "background" respectively (the LEDs are off, off, on and on), with 3 returned.
微信截图_20160129151218 Obtaining learning status of the RGB sensor. Output: 0-not learning, 1-learning background color, 2-learning track color.

The following is an example of line following based on the Auriga control board, with the 180 encoder motor as the chassis:

微信截图_20160129151218

The following is an example of line following based on mCore control board, with the TT motor as the chassis:

微信截图_20160129151218

RGBLineFollowerAdvanced

RGBLineFollowerAdvanced provides the more underlying blocks, which also include the original returned values of the probes. It facilitates more flexible education and application scenarios.

To install this plug-in:

Open the mBlock software→ Extensions → Manage Extensions → Find plug-in packages "RGBLineFollower’ and "EnhanceEncoderOnBoard" → Download the plug-in packages. The following blocks are displayed:

Description of the blocks:

  • Interface: Port1–Port12
  • Sensor number: 1–4. Any port can be bound to any sensor, but one number can be bound to only one RGB line following module.
Statement block Description
Initializing the RGB line follower, binding it to the port it has been connected to. To use blocks related to the RGB line follower, you need to invoke this block first.
Setting the color of the RGB supplement light. Currently, you can set the color to red, green, or blue.
Setting the line following sensitivity, which is used for adjusting line following response speed. The value ranges from 0 to 1. The larger the value is, the more sensitive it turns.
Obtaining the analog value (ADC value) collected by each probe of the line follower. The value ranges from 0 to 255. The closer to black the color detected by the probe is, the closer to zero the value is; the closer to white the color is, the closer to 255 the value is.
Obtaining offset of the sensor from the track. The output is taken as the product of the line following sensitivity Kp and the analog value resulted from fusion algorithm of the 4 sensors, ranging from –512 to 512. If it is larger than 0, it means that the line deflects to RGB4. The larger the value, the higher the offset. If it is smaller than 0, it means that the line deflects to RGB1. The greater the negative value, the higher the offset.
As shown in the figure, bit0~bit3 represent RGB4, RGB3, RGB2 and RGB1 from left to right respectively.
"1" means that the background is detected (corresponding LED is on), while "0" means that the line is detected (corresponding LED is off).
"0000" means that all the 4 sensors detect the line (all the LEDs are off).
"0111" means that the 4 sensors from left to right detect "line", "background", "background" and "background" respectively (the LEDs are off, on, on and on).
"0011" means that the 4 sensors from left to right detect "line", "line", "background" and "background" respectively (the LEDs are off, off, on and on).
If the state detected by the probe is the same as the one you set, the value "True" is returned; and if the state detected is not the same as the one you set, "False" is returned.
Obtaining the state of a probe, determining whether it detects a background or track. If it detects the background, the value "True" is returned; and if it detects the track, "False" is returned.

The following is an example (using the default strategy) of line following based on the Auriga control board, with the 180 encoder motor as the chassis. If the robot comes to a crossroad during line following, it stops moving for two seconds, runs forward for half a second, and then continues the line following.

The following is an example of line following based on the Auriga control board, with the 180 encoder motor as the chassis. In this example, the user obtains the ADC value of each probe and compiles the line following algorithm. It uses the dark-track-on-light-background mode.

mBlock 5 programming

The following uses Auriga as an example to describe how to add the RGB Line Follower extension.

1. Add the device mBot Ranger.

2. Add the RGB Line Follower extension.

Then, you can see the blocks in the Blocks area.

Description of the blocks

Port: Port 1–Port 12

Sensor number: 1–4. Any port can be bound to one and only one RGB line follower.

Statement block Description
Initializing the RGB line follower, binding it to the port it has been connected to. To use blocks related to the RGB line follower, you need to drag this block to the Scripts area first.
Setting the color of the RGB supplement light. Currently, you can set the color to red, green, or blue.
Setting the line following sensitivity, which is used for adjusting line following response speed. The value ranges from 0 to 1. The larger the value is, the more sensitive it turns.
Obtaining the analog value (ADC value) collected by each probe of the line follower. The value ranges from 0 to 255. The closer to black the color detected by the probe is, the closer to zero the value is; the closer to white the color is, the closer to 255 the value is.
Obtaining offset of the sensor from the track. The output is taken as the product of the line following sensitivity Kp and the analog value resulted from fusion algorithm of the 4 sensors, ranging from –512 to 512. If it is larger than 0, it means that the line deflects to RGB4. The larger the value, the higher the offset. If it is smaller than 0, it means that the line deflects to RGB1. The greater the negative value, the higher the offset.
As shown in the figure, bit0~bit3 represent RGB4, RGB3, RGB2 and RGB1 from left to right respectively.
"1" means that the background is detected (corresponding LED is on), while "0" means that the line is detected (corresponding LED is off).
"0000" means that all the 4 sensors detect the line (all the LEDs are off).
"0111" means that the 4 sensors from left to right detect "line", "background", "background" and "background" respectively (the LEDs are off, on, on and on).
"0011" means that the 4 sensors from left to right detect "line", "line", "background" and "background" respectively (the LEDs are off, off, on and on).
If the state detected by the probe is the same as the one you set, the value "True" is returned; and if the state detected is not the same as the one you set, "False" is returned.
Obtaining the state of a probe, determining whether it detects a background or track. If it detects the background, the value "True" is returned; and if it detects the track, "False" is returned.

Example program

Download the Example Program

results matching ""

    No results matching ""