Skip to content

[14] Line follower module

Features:

  • White/Black line position detection
  • Junction detection
  • Automatic line color detection
  • Automatic contrast calibration

Arduino example: 14_lineFollower.ino

TotemModule module(14);

Totem Module 14

Module commands

Before start

• Install programming environment by following tutorial on Arduino setup.
• Join our community forum for any questions: https://forum.totemmaker.net.

Command naming convention

Some commands controls various channels (A, B, C, ...). There is a logic behind command naming for flexibility:
write("commandA", 10) - will set value 10 for individual channel A.
write("commandAll", 100) - will set value 100 for all existing channels.
write("commandABCD", 10, 20, 30, 40) - will set individual values for A, B, C, D channels.
write("commandABC", 10, 20, 30) - will set individual values for A, B, C channels.
Only commands listed in "Module commands" will be accepted. Other variations will be discarded.
All commands are case sensitive! Calls like CommandA, COMMANDa, motorA/BRAKE will be ignored.

Line

line/junction ( )

Line junction detection feature allows to detect horizontal lines in its follow path. This is used for invoking some kind of action or to change direction (turn robot left or right).
Returns: sensor is reading horizontal line [true:false].
bool junction = module.readWait("line/junction").getInt();
module.subscribe("line/junction"); // Will send event onModuleData when junction is detected

line/color ( )

Currently detected line color. This can be White or Black. If color is not detected - 0 is returned. Color is returned in ASCII character. Use 'W', 'B' expression.
Returns: detected line color [W;B;false]. false - not detected.
int lineColor = module.readWait("line/color").getInt();
if (lineColor == 'W') {} // White
else if (lineColor == 'B') {} // Black
else { } // Not detected

line/pos ( )

Line position below sensor. (negative, 0, positive) = (left, center, right).
Returns: position [-35:35]. 0 - center.
int position = module.readWait("line/pos").getInt();

LED

led ( state )

Control red LED bar.
Each bit in 12bit value represents individual on-board LED. 1 - on, 0 - off.
This command disables line detection displaying. To re-enable - write -1.
Parameter:
state - [B00000000:B11111111].
module.write("led", B11110000); // Set leds A,B,C,D on

Sensor

sensor/threshold ( contrast )

Minimum contrast difference between line and ground required to start detection.
Lower value means more sensitivity when detecting line, but more susceptible to noise and misreadings. Should be changed only when there is an issue with detection on particular surface.
Parameter:
contrast - detection start range [10:80]%.
Default: 20.
module.write("sensor/threshold", 20);

sensor/range ( )

Percentage of current contrast difference between line and ground (maximum values).
Higher value means better detection accuracy. If value is lower than sensor/threshold, sensor won't be able to work properly. In this case lower sensor/threshold value or improve surface contrast.
Returns: current contrast difference [0:100]%.
int range = module.readWait("sensor/range").getInt();

sensor/raw ( )

Returns 8 byte array of contrast reading from each sensor.
0% - light does not reflect (black), 100% - light does reflect (white).
Array index 0 corresponds to sensor A, 1 - B, ...
Returns: 8 byte array of each sensor contrast [0:100]%.
Data data = module.readWait("sensor/raw");
uint8_t *contrast; // Get pointer to data array
data.getData(contrast);
// Print data array
for (int i=0; i<8; i++) {
    Serial.print(contrast[i]);
    Serial.print(" ");
}
Serial.println();