Flagbot Robotics Design Report
Flagbot Robotics Design Report
Version 1.0
Robotics Design Report
Team 1, Group C
English for Computer Science 3
Foundation Year
Vietnamese-German University
April 12, 2018
(This page intentionally left blank)
Dinh Quy Tri Thong
Student ID: 13249
Group C2, CS 2017
April 7, 2018
Enclosed is our Robotics Design Report for our class project, FlagBot, submitted to partially meet
the requirements for English for Computer Science 3.
This Report discusses the context for the project, gives a detailed description of the mechanical,
sensor, control, and software sub-systems, addresses the feasibility of the project and includes all
code produced for this project.
I appreciate the time you are taking to review this Report and hope that it meets your approval. If
you have any more questions feel free to contact me by e-mail: [email protected].
Sincerely yours,
We declare that this report is a product of our own work, unless otherwise referenced. We also
declare that all opinions, results, conclusions and recommendations are our own and may not
represent the policies or opinions of the Vietnamese-German University.
i
(This page intentionally left blank)
ii
Abstract
Team 1, Group CD
FlagBot, Version 1.0, is an in-class project that was assembled and programmed in order to
meet the demands of the course for Computer Science 3. Besides, it is required to perform all the
tasks in the contest which will be held at the end of the course.
FlagBot is an independent, automatic, and self-sufficient ground vehicle. This robot can start
automatically when the barrier is removed, then navigate through a given path (which will not curve
greater than 45 degrees) until it is 10 cm in front of to the wall. At that point, the wheels stop, a flag
attached with the robot will be raised. Finally, the robot must return to the starting point. When the
robot turns left or right, the light on that direction will light up accordingly. When the robot stops,
both lights must be turned on. Otherwise, the lights remained off. The FlagBot’s structure is based
on the Turtle Robot chassis and uses an Arduino Uno board as its main controller.
iii
(This page intentionally left blank)
iv
Table of Contents
Disclaimer.............................................................................................................................................i
Abstract...............................................................................................................................................iii
Table of Contents.................................................................................................................................v
Acknowledgements.............................................................................................................................vi
1. Introduction......................................................................................................................................1
1.1. Purpose......................................................................................................................................1
1.2. Audience....................................................................................................................................1
1.3. Project Scope.............................................................................................................................1
2. Context of the Project.......................................................................................................................2
2.1. Requirements and Constraints...................................................................................................2
2.1.1. Requirements......................................................................................................................2
2.1.2. Constraints..........................................................................................................................2
2.2. Current System..........................................................................................................................3
3. Overview of the Proposed System...................................................................................................4
3.1. Description................................................................................................................................4
3.2. Mechanical sub-systems............................................................................................................4
3.2.1. Chassis................................................................................................................................5
3.2.2. Drive sub-system................................................................................................................5
3.2.3. Power sub-system...............................................................................................................5
3.2.4. Flag sub-system..................................................................................................................5
3.3. Sensor sub-system.....................................................................................................................6
3.3.1. Ultrasonic sensor................................................................................................................6
3.3.2. Line tracking sensor...........................................................................................................6
3.4. Control sub-system....................................................................................................................6
3.4.1. Arduino Board....................................................................................................................6
3.4.2. Motor Control Shield..........................................................................................................6
3.5. Software sub-system..................................................................................................................7
3.5.1. Overall Design....................................................................................................................7
3.5.2. Routines..............................................................................................................................8
3.5.2.1. Tracking and signaling routine..................................................................................8
3.5.2.2. Stopping routine........................................................................................................9
3.5.2.3. Turning around routine..............................................................................................9
3.5.2.4. Flag raising routine....................................................................................................9
3.5.3. Device controlling..............................................................................................................9
3.5.3.1. Distance measuring...................................................................................................9
3.5.3.2. Track recognizing......................................................................................................9
3.5.3.3. Wheel controlling and light signaling.....................................................................10
3.6. Communications Interfaces.....................................................................................................10
3.6.1. LEDs signaling.................................................................................................................10
4. Conclusion......................................................................................................................................11
5. References......................................................................................................................................12
Appendix A: Glossary of Terms...........................................................................................................1
Appendix B: Gantt Chart......................................................................................................................1
Appendix C: FlagBot Sketch................................................................................................................1
v
Acknowledgements
I would also like to thank all my friends and classmates for their suggestions and assistance
• Nguyen Tien Dat and Dinh Quy Tri Thong wrote reports and helped assembling the robot.
• Hoang Van Thien was responsible for building and programming the robot, as well as
• Phan Nhat Nguyen designed the group’s presentations and helped assembling the robot.
• Nguyen Tat Dat was responsible for supplying materials and looking for reference sources.
vi
1. Introduction
1.1. Purpose
This Robotics Design Report for FlagBot, Version 1.0, is submitted for partial fulfillment of the
requirements of the course “English for Computer Science 3” at the Vietnamese-German University
and includes descriptions of the system, specifically of the mechanical sub-systems, and software
development.
1.2. Audience
The intended audience of this document is the course instructor, who will use it as the basis for a
determination of a portion of our grade for the class “English for Computer Science 3”.
This report provides a detailed description of the line-following robot’s design, including the
mechanical, control, and software sub-systems, together with the communication methods. The
project’s schedule and the code are also included in the appendices. The design of the flag attached
with the robot, however, is not included and described in the report.
1
2. Context of the Project
2.1.1. Requirements
The robot’s operations must obey the contest rules as provided in [1]:
The robot must be equipped with two rear LEDs. When turning left or right, the LED on that
side will light up to indicate its turning direction. If the robot does not move, both LEDs
The robot must be able to detect when the barrier is removed. This implies that we need a
distance sensor.
Then, the robot must be able to navigate and follow along a given path, which is colored in
black and 18 mm wide. This implies that we need to use at least one line tracking sensor.
The robot must be able to stop 10cm in front of a wall. This implies that we need a distance
sensor.
The robot will then raise a flag with “VGU” written on it at the end of the course. This
Finally, the robot must do a half-circle turn, following the path to the starting point.
2.1.2. Constraints
Given the availability of devices supplied by VGU and the contest rules in [1], we have
identified that the following constraints may limit the options for us:
Hardware:
2
Battery: maximum of 20V
No chemical reactions are allowed. The robot must not cause damage to people and
other equipments.
Software: a compiled Arduino program uploaded to the Arduino board via the Arduino
IDE v1.8.5.
3
3. Overview of the Proposed System
3.1. Description
The Flagbot includes the Arduino Uno as the main controller. Besides, the robot has two wheels
powered by DC motors and controlled by a motor shield. An ultrasonic sensor is used to determine
the distance from the FlagBot to the starting gate and to the wall at the end of the path. The three
line tracking sensors are responsible for tracking the line. Additionally, a servo is needed to raised
The FlagBot's mechanical sub-systems consists of the chassis, the drive sub-system, the power
4
3.2.1. Chassis
The chassis of the FlagBot consists of two plastic plates with to hold the equipments. The plates
are put parallel to each other. It is based on the Turtle Robot model.
The drive sub-system of FlagBot consists of the Arduino Uno, motor shield, two DC motors, and
three tracker sensors. The two motors are mounted to the chassis and connected with the Arduino
board via the motor shield. At the back of the robot, a caster is installed to keep balance.
According to [2], the connection between the DC motors and the Arduino board via the Arduino
• Right wheel: Pin 5 Arduino (speed control) and Pin 4 Arduino (direction control)
• Left wheel: Pin 6 Arduino (speed control) and Pin 7 Arduino (direction control)
• Each wheel’s two poles are connected to the shield’s motor terminal.
The power source for the robot is a rechargeable 7.4V Li-Po battery. It is placed between the two
plates of the chassis. Two poles of the battery are connected to the Arduino’s GND and VIN pin.
Two wires are then used to connect the second GND pin and the 5V Pin of the Arduino to a
breadboard attached on the top of the chassis. The power wire and ground wire of any other device
The flag sub-system includes a servo (Servo Motor V9) mounted on the right hand side of the
chassis, attached to a flag with “VGU” written on it, in contrast colors. The rod of the flag is 10 cm.
5
3.3. Sensor sub-system
FlagBot’s sensor sub-system is responsible for recognizing the path and obstacles. The sub-
system consists of one ultrasonic sensor and three line tracking sensors.
An ultrasonic sensor (Model URM37 V3.2) is used to detect the starting gate and the wall at the
end of the path. It is placed at the front of the robot. The sensor is configured in PWM passive
control mode, specified in [3], and is connected to the Arduino board as following:
• Pin PWM of the sensor connects with Pin 10 of the Arduino board
• Pin COMP/TRIG of the sensor connects with Pin 9 of the Arduino board
Three line tracking sensors (Tracker Sensor V4) are used to keep track of the black colored path.
They are placed under the chassis and close to the ground. Pin 2, 8, and 12 are connected to the
signal wires of the left, middle, and right sensor, respectively. These pins are set as input pins to
FlagBot’s control sub-system consists of the Arduino board to control the FlagBot and the Motor
The Arduino board used in the robot is Arduino Uno. The Arduino Uno is based on the
The motor control shield (Model L298N) is attached with the Arduino board, and is configured
as instructed in [2]:
6
• Since the motors take power from the Arduino power supply, the power source selection
• FlagBot uses PWM control mode to control the wheels, hence the control mode selection
The FlagBot software is a compiled C++ program, starts immediately once the system is
A setup process to declare the input and output pins for all of the appliances installed
A routine to move the robot along the track and brighten the LEDs in accordance with the
robot’s movement
In the subsequent sections, we describe the function of each routine and the methods of handling
7
3.5.2. Routines
This routine tries to set the directions of the wheels, based on the signals from three line tracking
sensors, in order to keep track of the line. It is worth noting that the routine does not alter the
wheels’ speeds, and the wheels’ directions are controlled together with the signal lights within a
1. If the middle sensor sees black color, that means the robot can move forward and the routine
2. The robot tries to turn left or right in order to meet the black color at the middle sensor
again. It is sure that both left and right sensors cannot see the black color at once because
this will lead to the middle sensor to see color black, which conflicts with the condition in
step 1. There are three cases for the status of the two sensors:
a. Color black on the left, but not on the right: This shows that the path has a left turn. The
routine set the right wheel spin forward while the left wheel spin backward, making the
robot turn left and waits until the middle sensor sees color black.
b. Color black on the right, but not on the left: This shows that the path has a right turn.
The routine set the left wheel spin forward while the right wheel spin backward, making
the robot turn right and waits until the middle sensor sees color black.
c. Color black not on any side: This shows that the robot may accidentally run out of track.
The routine set both wheels spin backward. In this particular case, the LEDs will
automatically light up while the robot is moving, so this can be fixed by setting the
LEDs off immediately. The program then waits until any of the three sensors sees color
black again.
8
3.5.2.2. Stopping routine
This routine simply sets the directions of both wheels as “backward” and their speeds as zero,
Given the fact that while turning around, there must be one moment that all three line tracking
sensors do not see color black, this routine makes the robot turn right (left wheel spinning forward,
right wheel spinning backward) and waits until all the three sensors do not see color black. Next, it
keeps waiting until one of the three sensors see color black again and terminates at last.
As the robot reaches the wall and stops, the function will set the angle of the servo at 110
The function measures the duration (in microseconds) of a low pulse from pin 10 (connected to
the PWM pin of the ultrasonic sensor). According to [3], each 50 microsecond pulse stands for a
distance of 1 cm from the ultrasonic sensor to the obstacle. Hence, the function returns the distance
(in centimeters) by dividing the time measured by 50. However, if the time is 50,000 microseconds,
the distance is classified as invalid and the function will return an error value of 999. We choose
this particular large value due to the fact that invalid distance usually happens when an obstacle is
The function reads simultaneously three digital signals from the left, middle, and right line
tracking sensor. The signal received from a sensor is low if the recognized color is black, and is
9
high otherwise [5]. Since the signal of each sensor is binary, the function combines three signals
The function’s parameters are the position of the wheel (left or right), the expected speed, and
the expected direction. The speed of the right (or left) wheel is set by writing a PWM signal from 0
to 255 to pin 5 (or pin 6). The direction of the right (or left) wheel is set by writing a digital signal
to pin 4 (or pin 7). This digital signal will be set low if the expected direction is “forward,” and will
When a wheel’s direction is set backward, the LED on that side will illuminate. The light is
brightened by sending a high digital signal to the pin connected with that light. Please refer to
The robot can stop by calling two functions for two wheels, each function set the wheel’s speed
as zero and the direction as backward, so that both LEDs will light up. If the robot needs to turn left,
the right wheel’s direction is set backward and the left wheel’s direction is set forward, making the
robot turn left and the left LED light up. The similar rule applies when the robot needs to turn right.
Two rear LEDs are attached on the top of the chassis, one on the left and one on the right side of
the robot. When turning left or right, the LED on that side will light up to indicate its turning
direction. If the robot does not move, both LEDs must light up. Otherwise, the LEDs remain off.
10
4. Conclusion
vehicle controlled by an Arduino Uno. The report includes the overall requirements and constraints,
as well as the mechanical, control, sensor, and software sub-systems, and the communication signal
of the robot. The robot can start automatically when the barrier is removed, then navigate through a
given 18 mm black path until it is 10 cm in front of the wall. At that point, the wheels stop, a flag
attached with the robot will be raised. After that, the robot must turn around and return to the
11
5. References
[1] R.Bradley, Specification for CS Flagbot, The Vietnamese-German University, HCMC, VN:
VGU 2017.
[2] DFRobot Wiki. (2017, June). Arduino Motor Shield (L298N) (SKU:DRI0009). [Online].
Available: https://www.dfrobot.com/wiki/index.php/Arduino_Motor_Shield_(L298N)_
(SKU:DRI0009)
[3] DFRobot Wiki. (2017, May). URM37 V3.2 Ultrasonic Sensor (SKU:SEN0001). [Online].
Available: https://www.dfrobot.com/wiki/index.php/URM37_V3.2_Ultrasonic_Sensor_
(SKU:SEN0001)
[4] Arduino Store. (undated). Arduino Uno Rev3. [Online]. Viewed 2018 April 11. Available:
https://store.arduino.cc/usa/arduino-uno-rev3
[5] DFRobot Wiki. (2017, August). Line Tracking Sensor for Arduino V4 SKU:SEN0017. [Online].
Available: https://www.dfrobot.com/wiki/index.php/Line_Tracking_Sensor_for_Arduino
_V4_SKU:SEN0017
12
Appendix A: Glossary of Terms
Terms Definitions
Analog signal A type of signal that is continuously variable
Arduino Uno Rev3 An open-source micro-controller board developed by Arduino
ATmega328P A low-power single-chip micro-controller created by Atmel
C++ A general-purpose object-oriented programming language, and
is an extension of the C language
DC Direct Current, the unidirectional flow of electric charge
Digital signal A type of signal with two distinguishable levels
GND Ground, the reference point in an electrical circuit from which
voltages are measured, a common return path for the current.
IDE Integrated Development Environment, a software suite that
consists of the basic tools to develop software
LED Light-Emitting Diode, a two-lead semiconductor light source
Li-Po battery A rechargeable battery of lithium-ion technology using a
polymer electrolyte instead of a liquid one
Micro-controller A small computer on a single integrated circuit
Pin A part used for validating electronic transactions
A-1
Appendix B: Gantt Chart
Deliverables Legend
Constraints and requirements Week 2 Critical Path █████
Progress Report 1 Week 5 Non-Critical █████
Progress Report 2 Week 6 Slack Time █████
Final Report Week 7
B-1
Appendix C: FlagBot Sketch
/*
* Project: FlagBot
* Vietnamese-German University
* Team 1 (Hoang Van Thien, Dinh Quy Tri Thong, Nguyen Tien Dat, Nguyen Tat Dat, Phan Nhat
Nguyen)
* Move the robot through a black path, stop at 10 cm in front of the wall, raise the flag, return to
the starting point
* Reference sources:
* L298N Manual, by DFRobot:
https://www.dfrobot.com/wiki/index.php/Arduino_Motor_Shield_(L298N)_(SKU:DRI0009)
* URM37 V3.2 Manual, by DFRobot:
https://www.dfrobot.com/wiki/index.php/URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001)
* Tracker Sensor V4, by DFRobot:
https://www.dfrobot.com/wiki/index.php/Line_Tracking_Sensor_for_Arduino_V4_SKU:SEN0017
* Connections:
* Two poles of Right DC Motor -> two terminals M1+ and M1- (Motor Shield)
* Two poles of Left DC Motor -> two terminals M2+ and M2- (Motor Shield)
* E1 (Motor Shield) -> Pin 5 (Arduino) (built-in connection, controlling Right DC Motor's speed)
* M1 (Motor Shield) -> Pin 4 (Arduino) (built-in connection, controlling Right DC Motor's
direction)
* E2 (Motor Shield) -> Pin 6 (Arduino) (built-in connection, controlling Left DC Motor's speed)
* M2 (Motor Shield) -> Pin 7 (Arduino) (built-in connection, controlling Left DC Motor's
direction)
* Right Tracker Sensor -> Pin 12 (Arduino)
* Middle Tracker Sensor -> Pin 8 (Arduino)
* Left Tracker Sensor -> Pin 2 (Arduino)
* Pin PWM (URM V3.2) -> Pin 10 (Arduino)
* Pin COMP/TRIG (URM V3.2) -> Pin 9 (Arduino)
* Pin 3 (Arduino) -> Right LED -> GND (Arduino)
* Pin 13 (Arduino) -> Left LED -> GND (Arduino)
* Servo -> Pin 11 (Arduino)
* Note: The power wires and ground wires of Servo, Tracker Sensors, and Ultrasonic Sensors are
respectively connected to VIN and GND of the Arduino
*
*/
#include <Servo.h>
// Notes: The right device has index 0, the left device has index 1
const int right = 0, left = 1, ignore = -1, forward = 0, backward = 1;
const int white = 1, black = 0;
int URPWM = 10, URTRIG = 9;
int pinSpeeds[2] = {5, 6};
int pinDirections[2] = {4, 7};
int pinTrackers[3] = {12, 8, 2};
int wheelSpeeds[2] = {100, 105};
int threshold, dir;
int servoPin = 11, servoPosition;
int pinLEDs[2] = {3, 13};
C-1
Servo servo;
void setup()
{
Serial.begin(9600);
pinMode(pinDirections[0], OUTPUT); // Right Motor's direction pin
pinMode(pinDirections[1], OUTPUT); // Left Motor's direction pin
pinMode(pinSpeeds[0], OUTPUT); // Right Motor's speed pin
pinMode(pinSpeeds[1], OUTPUT); // Left Motor's speed pin
pinMode(pinTrackers[0], INPUT); // Right Line tracking Sensor's pin
pinMode(pinTrackers[1], INPUT); // Middle Line tracking Sensor's pin
pinMode(pinTrackers[2], INPUT); // Left Line tracking Sensor's pin
servo.attach(servoPin); // Servo
servo.write(20); // Set servo's initial angle 20 degrees
threshold = 10; // Stopping point in front of the wall, in cm
pinMode(pinLEDs[0], OUTPUT); // Right LED's pin
pinMode(pinLEDs[1], OUTPUT); // Left LED's pin
}
/*
* Control the wheel:
* - side: 0 (right) or 1 (left)
* - Speed: an integer from 0 to 255, or -1 to set the default speed
* - Direction: 0 (forward) or 1 (backward) or -1 to not change the Direction
*/
void runWheel(int side, int Speed, int Direction)
{
if (Direction != ignore) {
if (Direction == forward) {
digitalWrite(pinDirections[side], LOW);
digitalWrite(pinLEDs[side], LOW);
} else {
digitalWrite(pinDirections[side], HIGH);
digitalWrite(pinLEDs[side], HIGH);
}
}
if (Speed == ignore) Speed = wheelSpeeds[side];
analogWrite(pinSpeeds[side], Speed);
}
C-2
int getLineStatus()
{
int l = digitalRead(pinTrackers[2]), m = digitalRead(pinTrackers[1]), r =
digitalRead(pinTrackers[0]);
// Return a three-bit integer representation of the three signals from sensors
return l*4 + m*2 + r;
}
void tracking()
{
while (getDistance() > threshold) {
int lineStatus = getLineStatus();
if ((lineStatus & 0b010) != 0) { // cannot move forward anymore
if (lineStatus == 0b111) { // cannot move anywhere
// Reminder: -1 for speed means setting the default speed
runWheel(left, -1, backward);
runWheel(right, -1, backward);
// Wait until any of the three sensors sees color black
while (getLineStatus() == 0b111 && getDistance() > threshold);
} else if ((lineStatus & 0b001) != 0) { // cannot turn right, so turn left
runWheel(left, -1, backward);
runWheel(right, -1, forward);
// Wait until the middle sensor sees color black
while ((getLineStatus() & 0b010) != 0 && getDistance() > threshold);
} else { // Turn right
runWheel(left, -1, forward);
runWheel(right, -1, backward);
// Wait until the middle sensor sees color black
while ((getLineStatus() & 0b010) != 0 && getDistance() > threshold);
}
}
// Go straight forward
runWheel(left, -1, forward);
runWheel(right, -1, forward);
}
}
void Stop()
{
runWheel(left, 0, backward);
runWheel(right, 0, backward);
}
void loop()
{
Stop();
while (getDistance() <= threshold); // Wait until the gate opens
tracking();
Stop();
servo.write(110); // Raise the flag
// Turn right
C-3
runWheel(left, -1, forward);
runWheel(right, -1, backward);
while ((getLineStatus() & 0b010) == 0);
while ((getLineStatus() & 0b010) != 0);
tracking();
Stop();
while(1); // Infinite loop to make the program idle
}
C-4