0% found this document useful (0 votes)
9 views72 pages

Line Following Robot For Weight-Based Goods Distribution: Mechatronics System Design Project

The document outlines a project on designing a line-following robot for weight-based goods distribution, detailing its components, market applications, and mechanical structures of various Autonomous Guided Vehicles (AGVs). It discusses the types of sensors used for line detection and weight measurement, as well as motor types and control structures for the robot. The project aims to enhance automated goods transportation by integrating advanced technologies in robotics.

Uploaded by

phanmquan2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views72 pages

Line Following Robot For Weight-Based Goods Distribution: Mechatronics System Design Project

The document outlines a project on designing a line-following robot for weight-based goods distribution, detailing its components, market applications, and mechanical structures of various Autonomous Guided Vehicles (AGVs). It discusses the types of sensors used for line detection and weight measurement, as well as motor types and control structures for the robot. The project aims to enhance automated goods transportation by integrating advanced technologies in robotics.

Uploaded by

phanmquan2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

FACULTY OF MECHANICAL ENGINEERING

MECHATRONICS SYSTEM DESIGN PROJECT


Line Following Robot for
Weight-Based Goods Distribution
CLASS CC02 – HK251

Advisor: Trương Ngọc Cường


Group member: Bùi Hoàng Nhân 2252557
Phan Minh Quân 2252686
Nhâm Gia Nghĩa 2252569
Đăng Lê Quang Nhật 2212235
CHAPTER 1: OVERVIEW
1.1 Overview of line-following delivery robot
1.1.1 Concept of line-following delivery robot
A line-following robot is an automated machine capable of following a predefined path
even when the path is changed by altering its shape. In the most basic case, the path can be
visible, such as a black line on a white surface (or vice versa), or invisible, such as a magnetic
field.
In addition to the line-following function, the robot is also designed with a loading
system for goods to be delivered. This system can detect whether goods have been loaded, as
well as distinguish the weight of the goods. From there, it delivers the goods to the
appropriate location based on the predefined weight.
A line-following delivery robot mainly consists of the following modules: power
supply, sensors, actuators, control system, communication between sensors and control
system, and communication between control system and actuators.

1.1.2 Products on the market applying line-following delivery robots


Autonomous Guided Vehicles (AGV):
AGVs are widely used in large industrial zones for automatic goods transportation.
They use photoelectric sensors for navigation and ultrasonic sensors to avoid collisions that
may affect goods and staff.
Advantages: long-term operation, ability to transport heavy loads. AGVs are
increasingly chosen to replace humans to reduce labor costs and increase accuracy.
AGV guidance technologies:
 Wire: Wires embedded in the floor transmit signals. AGV sensors detect
these. Limitation: inflexible, as routes are fixed.
 Guided tape: Magnetic tape or points stuck on the floor. They can be
replaced when routes change but may get dirty/damaged with heavy
traffic.
 Laser target navigation: AGV uses laser transmitters/receivers with
reflective strips.
 Inertial navigation : AGVs follow floor-embedded signal markers
controlled by computer systems.
 Vision guidance: AGVs use 360° cameras to capture route features and
1
build 3D maps.
 Geo-guidance: AGVs detect columns, walls, and fixed objects to self-
locate in real-time and adjust paths without infrastructure limits.
Three main AGV types:
AGV Cart (Image 1.1) : The automatically guided cart is the most basic
type of AGV. Navigation systems can range from simple systems such as
magnetic tape to more complex path-guiding systems, based on sensors using AI
for navigation.

Image 1.1 AGV Cart


AGV Forklift (Image 1.2): The automatically guided forklift is an AGV designed to
function as a forklift. The difference is that it does not require a human operator and is guided
by a pre-installed navigation system.

Image 1.2 AGV Forklift


AGV Tugger (Image 1.3): Automatically guided tug vehicles pull non-motorized load
carriers behind them. They are used to transport heavy goods over longer distances and may
have several stops along predefined routes in a factory or warehouse.

2
Image 1.3 AGV Tugger
1.2 Mechanical Structure of Some AGVs
1.2.1 Pioneer 3-DX
Developed by Adept MobileRobots in the USA, Pioneer 3-DX is a classic 3-wheel
differential-drive robot widely used for research in navigation, SLAM, and multi-robot
coordination. Its simple and reliable design makes it a popular choice for introductory
robotics projects and small research groups

(a) Robot Pioneer 3-DX (b) Principle Diagram


Figure 1.1 Robot Pioneer 3-DX
Advantages Disadvantages
- Simple structure - Easy to tip when carrying heavy loads
- 3 wheels always maintain contact with the - Uneven weight distribution
ground (flat)
- Front-driven wheels provide better
stability during turns

1.2.2 Segway RMP110


Produced by Segway Robotics (USA), the RMP110 is a self-balancing mobile

3
platform designed for field robotics and human-robot interaction research. Its advanced
control system and higher cost mean it is usually seen in well-funded labs rather than hobby
projects.

(a) Robot Segway RMP110 (b) Principle Diagram


Figure 1.2 Robot Segway RMP110
Advantages Disadvantages
- Simple structure - Easy to tip when carrying heavy loads
- 3 wheels always maintain contact (flat) - Must pay attention to center of gravity to
distribute load on wheels evenly
- Less stable than front-driven structure

1.2.3 Hunter 0406


Hunter 0406, made by AgileX Robotics in China, features Ackermann steering
for smooth outdoor navigation and autonomous driving studies. Its robust mechanical design
demands careful integration, which can make it a good challenge for more experienced
student teams or research projects.

(a) Robot Hunter 0406 (b) Principle Diagram


Figure 1.3 Robot Hunter 0406
Advantages Disadvantages
- Only needs Ackerman steering control - Many components require assembly,

4
- Most stable among configurations complex fabrication
- Reduces slippage when turning by shifting - Must resolve the issue of even contact
the instantaneous center of rotation between 4 wheels

1.2.4 Pioneer 3-AT


Also from Adept MobileRobots, Pioneer 3-AT is a 4-wheel all-terrain version
built for rough environments, search-and-rescue, and outdoor sensing applications. Its
traction and stability are excellent, but coordinating four drive motors and dealing with wheel
slip requires more sophisticated control, making it a platform typically used in advanced
projects.

(a) Pioneer 3-AT (b) Principle Diagram


Figure 1.4 Pioneer 3-AT
Advantages Disadvantages
- Well weight distribution ( on a - It uses skidding or slipping technique,
rectangle ). increases wheel wear, reducing life.
- Good for rough terrain so that ensure the - Difficult to synchronize 4 motors when
distance between sensors and road going straight or turning.
surface.. - The control algorithm is complicated.
- Great traction. Difficult to be coplanar.

1.3 Electrical device


1.3.1. Line Detecting Sensors for Line-Following Robots (AGV)
To make the robot follow the line from track, we have to use sensors to help it detect
the black line on the white background. There are some common sensors/tool can be used.

5
1.3.1.1. Camera (Vision system)

Figure 1: Industrial Camera


Principles: A camera will extract the black line from the recorded frames while robot is
moving. Image processing (OpenCV, AI) finds the black line vs white background and
computes the robot’s position relative to it.

Figure 2: Camera line detecting principle


Pros:
- Versatile, high accuracy
- Can detect obstacles at the same time.
Cons:
- High power source required.
- Complex image processing skills.
- Higher cost, processing time.

1.3.1.2. IR Sensor (Reflectance sensor)

6
An IR sensor uses an infrared LED as the emitter and a photodiode as the detector. It
measures reflected IR light to distinguish between black and white surfaces, making it
common in line-following robots.
Principles: The emitter is an IR LED and the detector is an IR photodiode. The IR
photodiode is sensitive to the IR light emitted by an IR LED. The photo-diode’s resistance
and output voltage change in proportion to the IR light received. This is the underlying
working principle of the IR sensor.

Figure 3: IR sensor principle


Pros:
- Cheap, small, easy to interface.
- Fast response, good for simple black-white tracks.
Cons:
- Sensitive to ambient light.
- Struggles with glossy or low-contrast surfaces.
- Needs multiple sensors for accuracy.

1.3.1.3. Phototransistor
A phototransistor functions like a normal transistor but is triggered by light instead of
electrical current at the base. It is simple, fast, and inexpensive, though sensitive to ambient
light.
Principles: Works like a normal transistor, but instead of using a base current to switch
it on, it is activated by incident light (visible or infrared). When photons strike the
7
semiconductor material, they generate electron–hole pairs, which increase the base current
and allow a larger current to flow between the collector and emitter.

Figure 3: Phototransistor's principles


Pros:
- Very cheap and simple.
- High processing speed.
Cons:
- Less reliability than dedicated reflectance sensors.
- Strongly affected by ambient light.

1.3.1.4. Color Sensor


A color sensor measures reflected RGB light to detect surface colors. It allows
recognition of different colored lines or markers, enabling robots to follow more complex
paths.
Principles: Measures RGB light reflected from the surface. Can distinguish between
multiple line colors (red, blue, green, black).
Pros:
- Detects more than just black/white.
- Useful if different colored paths represent different routes.
Cons:
- More expensive than IR reflectance.
- Slower response.
- Sensitive to lighting conditions.

1.3.1.5. Magnetic Sensor


A magnetic sensor detects magnetic tape embedded in the floor, guiding robots along
predefined paths. It is highly reliable in industrial environments and unaffected by lighting or
surface conditions.
8
Figure 4: Application of magnetic sensor in AGV
Principles: A magnetic sensor detects magnetic tape embedded on the floor. The robot
follows the magnetic path instead of an optical line.
Pros:
- Not affected by lighting, dust, or floor color.
- Very reliable in industrial AGVs.
- Can work in warehouses with poor visibility.
Cons:
- Requires magnetic tape installation → adds cost.
- Not as flexible (path fixed by tape).
- Higher sensor cost than simple IR.

1.3.2. Force Sensor


Choosing suitable sensor for product distinguish.

1.3.2.1. Load cell


A sensor that converts mechanical force (weight) into an electrical signal. The most
common type is the strain gauge load cell. The principle depends on electric resistance,
when weight is applied, the load cell body deforms slightly. Then it lead to the change in
electrical resistance. Greater deformation (compression) leads to a higher decrease in
resistance, which can be measured. The output is in the millivolt range and must be amplified
before being read by a microcontroller.

9
Figure 5: Load cell's structure and principles
Pros:
 High accuracy and repeatability.
 Wide measurement range (grams to tons).
 Reliable for long-term use.
Cons:
 Requires external amplifier (HX711).
 Sensitive to mounting and mechanical alignment.
 More expensive than simple pressure or force film sensors.

1.3.2.2. Force-Sensing Resistor (FSR)


A thin, flexible film sensor that changes its electrical resistance when a force or
pressure is applied. It consists of a pressure-sensitive resistive layer placed over conductive
traces. When no force is applied, the resistance is very high. As force increases, the resistance
decreases because more conductive particles make contact. This resistance change can be
measured using a voltage divider and read by a microcontroller’s ADC pin.

10
Figure 6: Relationship between force and resistance
Pros:
• Thin, lightweight, and easy to integrate.
• Simple to interface (just a resistor divider).
• Low cost for basic force detection.
Cons:
• Non-linear response, not suitable for precise measurements.
• Limited repeatability and drift over time.
• Less accurate compared to load cells.

1.3.3. Motor:
Motor receives command from microcontrollers to follow the path after tracking lines
with sensors. For the robot projects, there are some common motors that have been used.
 DC motor: An electrical machine that converts direct current (DC) electrical energy
into mechanical energy, typically in the form of rotation.
 BLDC motor: A brushless DC motor that uses electronic commutation instead of
brushes, offering higher efficiency, longer lifespan, and lower maintenance.
 Stepper motor: An electromechanical device that divides a full rotation into precise,
fixed steps, making it ideal for position control without feedback.
 Servo motor: A motor equipped with a control circuit and feedback mechanism
(often using a potentiometer or encoder) to achieve precise position, speed, or torque
control.

11
Table 1: Motor comparison
Type Pros Cons
DC motor  Simple, cheap  Short lifespan
 Easy control  Hard for precise position
 Good torque control
BLDC motor  Quieter than DC motor  Required advanced
 Long lifespan controller
 Good torque
Stepper motor  Precise step movement  Less efficiency at high
 Suitable for slow torque speed speed
Servo motor  Excellent precision  High price
 Fast response  Heavy
 Maintain accuracy over dynamic loads

1.4 Structure of control


1.4.1. Two main types of structure for control system.
1.4.1.1. The first type is: “Centralized control”
- Centralized control is utilizing one MCU for every process:
o Executing main program.
o Calculating the controlling algorithm.
o Use the calculated value to control the motor via PWM.
o Processing analog signal from encoders.
- This is the flowchart of centralized control

Pros Cons
12
1. Use one MCU for tons of tasks is
1. It minimize the size of control
potentially risky. Because the CPU
system. It cost less resources.
have to simultaneously processes
2. Easier for mechanical design. The
various task. It may cause RAM or
space only use for one MCU instead
Flash problems.
of three.
2. Find obstacles in debugging. When
3. The size and power circuit and
the system confronted with an error,
electronics circuit is smaller.
you have to dive into a central MCU
Leading to less power consumption.
which processes everything.
- Based on the Pros and Cons, this architecture only suitable for small project or
system.

1.4.1.2. The second type is: “Hierarchal control”


- Hierarchal control is the control that use more than one MCU for doing task, each
MCU is assigned for one specific task.
- There are two main types of MCU in hierarchal control are: “Master MCU” and
“Slave MCU”.
- “Master MCU” takes responsibility for executing the main program, doing the main
tasks.
- “Slave MCU” takes responsibility for:
o Receive analog signal from sensors and calculate the relative position of the
mobile robot to the line.
o Receive analog signal from encoders and calculating the motor control
algorithm and control the motor. Ensure that the motor is running accurately
as the Master MCU required.
- This is the flowchart of Hierarchal control:

13
Pros Cons
- The main advantage is this - This architecture consume more
architecture reduce the load of resources.
program on one MCU. Each MCU - It needs more space for mechanical
will only process a specific task. By design. Leading to Increase the
doing that, it reduce the chance of overall size of the robot.
error occurring in the MCU. - It needs more power to supply
- It is easier for developer to debug various MCU compared to one
the program. And easier to navigate MCU.
the source of problem, when each - It reduces the reliability of the whole
MCU is assigned a specific task. system. Because when more
You can easily isolate a MCU for components are added, the reliability
testing. of the system diminished.

1.4.2. Algorithm architecture.


1.4.2.1. ALF (Advance Line Follower) algorithm architecture

14
- The algorithm is designed for a line follower robot, that moving in a set of square line.
Therefore, they will use sensor to detect the junction (crossing point).
- The steps to control the Robot can be describe as followed:
o Read the input: “Sensor value” in this case.
o Solving and interpreting the sensor data: “Junction detected” in this case.
o After that, control the Robot based on the result of data, this is called
“Decision Making”.
o Repeat the process.

1.4.2.2. Industrial autonomous vehicle system architecture based on Finite-State


Machine.

15
- This is a system architecture for an industrial or an autonomous car. This system is
more complex. They divided the system into 3 classes:
o Perception and environment mapping.
o Motion Planning.
o Control system.
- This architecture is using hierarchal control system structure, the system is controlled
from low to high.
- Dive into the decision-making part, the articles mentioned they are using FSM
(Finite – System Machine) for decision making.

1.5 MODELING AND SIMULATION


1.5.1. Line tracking algorithm
1.5.1.1. Comparative algorithm
Signal collected from the sensor will be processed into 0 or 1, depending on whether its
value exceeds the predetermined threshold value or not. Based on the position of the 0 or 1
state signal value, LFR will control the speed of the two wheels of the robot to keep it in the
path.

16
1.5.1.2. Interpolation method
The purpose of the interpolation method is to find the estimated position of the center
of the line to the center of the robot, hence control the robot to track the line. The signal
collected from the array of sensors is a group of discrete data values. Interpolating here is to
create a group of new data about the position of the line from the signal of the sensor.
a. Quadratic interpolation
We begin with the process of defining the robot's position at the start point of the line.
Finding the sensor position with the highest values, we can determine the range of interest of
the line that the robot is following. Assuming that, in this range of interest, we can perform a
calculation of the quadratic curve from their output signal values (for example, a, b, c of
2
ax +bx +c ). Therefore, we can define the position of the line at the specific point in the range
of interest by calculating the position of the highest value of the curve.

b. Weighted Interpolation

17
-The coordinates of the 7 sensors are x 0 , x 1 , x 2 , x 3 , x 4 , x 5 , x 6 , respectively, and the

output values are y 0 , y 1 , y 2 , y 3 , y 4 , y 5 , y 6 as shown in the below figure. The estimated


position of the line can be calculated with the weighted average calculation as follows:

∑ xi yi 3 ( y 6− y 0 ) +2 ( y 5− y 1) +( y 4 − y 2 )
x= i=07 = 7

∑ yi ∑ yi
i=0 i =0

In the research "An intelligent line-following robot project for introductory robot
courses,", the line tracking of the quadratic interpolation and weighted interpolation are
5,4mm and 2,6mm, respectively. We conclude that Weighted Interpolation is the method that
provides the smallest tracking error.

1.5.1.3. Line Tracking Algorithm


In the paper “Smooth Tracking Controller for AGV Through Junction Using a CMU
Camera,” a tracking controller is employed.

18
The robot’s line-following control is formulated via an error model, and stability is
proven using the Lyapunov criterion.
After doing some kinematic analysis, we get the tracking error as following:

[][ ]
e1 cos ⁡( φ) sin ⁡( φ) 0
e 2 = −sin ⁡(φ) cos ⁡(φ) 0
e3 0 0 1

The error dynamic can be derived as follows after calculation:

[ ] [ ][ ][ ]
ė 1 v R cos ( e3 ) −1 e2
= + v
ė 2 v r sin ( e 3 ) 0 −d−e 1
ω
ė 3 ωr 0 −1
( 1)

1.5.2. Designing Controller


1.5.2.1. PID Controller
In the paper “PID Controller Optimization for Low-cost Line Follower Robots,”
the PID algorithm is applied to a line-following car with the following behavior:

The PID controller works well on straight segments. However, at sharp turns the robot
drifts off the line. This happens because the sensors lose the line, leading to incorrect error
computation and thus deviation. In this case an additional open-loop mechanism is used:
when all sensors lose the line, only the two outermost left/right sensors are used. If the last
error comes from the rightmost sensor ⇒ the line is to the right, so turn right; similarly for
the left. The motor speeds are then tuned to execute fixed-angle turns.
Remark: This is suitable for straight runs but not for curved profiles. On different
tracks, the motor speeds must be recalculated and retuned, so the approach is not optimal.

1.5.2.2. Fuzzy Controller


According to “Fuzzy Logic Approach For Line Following Robot Using An Array Of
Digital Sensors”, implementing fuzzy logic generally involves three basic procedures;

19
fuzzification, or fuzzy inference process that converts crisp sensors value into fuzzy world,
computation, where the fuzzy value is being treated, and defuzzification, where the fuzzy
output is converted back into crisp values mainly for actuators.
In this research, the Fuzzy Controller gives a better performance than the PID controller. In
detail, it performs a faster and efficient tracking compared to the PID controller.
But the process of the fuzzy controller is quite complicated. In this research, the author
had to process the value of digital sensors in the fuzzification stage, build a proper rule-based
decision-making process, and then defuzzify to obtain the output crisp value for the
differential drive of the motor. It’s quite challenging to understand, and needs experience at
some extent to build the rule-based decision-making process.

1.5.3. Analysis and Designing Option


1.5.3.1. Line tracking Algorithm
Based on the requirement that the line tracking error must remain within ±3 mm, we
selected the quadratic interpolation method. Among the three approximation methods
considered, quadratic interpolation provides the smallest error, making it the most suitable
choice for achieving the desired precision.

1.5.3.2. Control solutions


For this project, we adopted a centralized control structure due to its simplicity and
ease of implementation in both mechanical and electrical design. A PID controller was
employed to regulate the speed of the differential drive, as it is effective, reliable, and
straightforward to tune for this type of application.

20
Additionally, a line tracking algorithm based on Lyapunov stability theory was
integrated to ensure error convergence. With this approach, the system error asymptotically
approaches zero as t→∞, guaranteeing robust stability in the tracking process.
The Fuzzy Controller is not chosen here because the surface of the map is plain, which
couldn’t optimize the performance of the Fuzzy Controller. Moreover, building the rule-
based decision-making also requires experience to some extent.
The proposed block diagram for the control structure:

21
CHAPTER 2: ANALYZING AND DESIGN OPTIONS
2.1. Mechanical selection:
 We chose a three-wheel configuration with two front-driven wheels and a free caster
wheel at the rear. This setup is simple, reliable, and sufficient for our line-following
task, where the robot does not need to move at very high speeds.
 Using three wheels avoids the challenge of keeping four wheels perfectly coplanar,
which would otherwise require a suspension or leveling mechanism.
 Front-wheel drive is preferred since the robot mainly moves forward; it also improves
stability during turns by reducing the tendency to tip diagonally forward.

2.2. Electric components selection


2.2.1. Motor selection:
Base on calculation in mechanical selection and table 1, we have criteria for choosing
motors:
 Can produce torque at 0.08 Nm
 Minimum speed is 112.3 rpm
 Power is about 1.41 W
 Cost-effectiveness
Hence, we selected a DC gear motor with an integrated encoder to create closed-loop
system. We have categorized some of DC motors from supplier’s catalog.
Table 2.1: Motors specification
Motors
Specification GA12 - GA25 - 370 GA37 – V1 Required
N20
Voltage 12 VDC 12 VDC 12 VDC N/A

No-load speed 300 rpm 280 rpm 333 rpm N/A


22
Loaded speed 240 rpm 215 rpm 250 rpm 146,7 rpm
Power 4W 4.5 W 9W 1,38 W
Loaded torque 0,16 Nm 0,2 Nm 0.343 Nm 0,06 Nm
Speed ratio 50:1 21,3:1 30:1 N/A
Price 150k 195k 215k N/A
Conclusion: The GA25-370 is fitted most for our project because it meets mechanical
requirements and cost-effective.

2.2.2. Sensor selection:


2.2.2.1. Line detection:
From the overall sensor, we saw each method for line detecting has pros and cons.
Based on some requirements to choose, there are:
 Function well in black and white distinction.
 Fast response.
 Least affected by outside light.
 Cost-efficiency
Compared these requirements to sensors in overall part, we can see that:
 Camera has high accuracy and versatile detection, however, it is costly and takes long
time to response.
 IR Reflectance Sensor: Works very well in black/white distinction, responds quickly,
and is inexpensive, but is sensitive to ambient light and may struggle with glossy
surfaces.
 Phototransistor: Very fast and cheap, but less reliable than dedicated reflectance
sensors and strongly affected by outside light.
 Color Sensor: Can detect multiple line colors, useful for more complex paths, but
slower and more expensive, also sensitive to lighting conditions.
 Magnetic Sensor: Completely immune to lighting and surface issues, highly reliable in
industrial AGVs, but requires magnetic tape installation, making it less flexible and
more expensive.

23
Conclusion: IR reflectance sensor is most suitable choice for our line-following robot, it
offers good black/white distinction, fast response, minimal influence from outside light, and
cost-efficiency. Moreover, its weakness can be solved by calibrating in code or hardware.
Based on prior experience and supplier recommendations, we propose using the
TCRT5000 IR sensor, which offers reliable performance and cost-effectiveness for student
projects.
Table 2.2: Technical Specifications of TCRT5000 Sensor
Parameter Value Unit
Operating range 0.2 – 15 mm
Wavelength of emitted 950 nm
light
Emission angle 16 °
Reception angle 30 °
Maximum current through 100 mA
phototransistor
Maximum current through 60 mA
LED

24
Figure 7: IR sensor diagram
 Sensor arrangement:
From document references and debate in robot forum, number of sensors should be at
least 3. With 1 at center and 2 sensors on two sides to detect direction and send to MCU.

Figure 8: Sensor arrangement with 3 sensors


25
However, with the junction, we should use 5 sensors. The center sensor ensures the
robot stays aligned with the track, while the two inner side sensors (left-inner and right-inner)
detect small deviations from the center, allowing the controller to apply smooth corrections.
Meanwhile, the two outer sensors (far-left and far-right) become crucial at increase the
stability and calculate a weighted error (–2, –1, 0, +1, +2).

Figure 9: Sensor arrangement with 5 sensors


2.2.2.2. Weight detection:
From the overall sensor, we saw each method for weight detecting has pros and cons.
Based on some requirements to choose, there are:
 Accuracy.
 Fast response.
 Stability, reliable.
 Cost-efficiency
 Easy for integration into mechanical design
Based on these criteria and sensor overall section, the load cell is most suitable. It may
be complex and require an amplifier but more accurate and stability.
Based on prior experience and supplier recommendations, we propose using the Load
Cell 2Kg 24bit HX711, which has range of measurements up to 2 kg and cost-effectiveness
for student projects. The amplifier for it is HX711.

26
Figure 2.10: Load cell

Table 2.3: Technical Specifications of Load Cell


PARAMETER VALUE UNIT
MAXIMUM LOAD 5 kg
ERROR 0.05 %
INPUT VOLTAGE 5 V
MATERIAL Aluminum –
OUTPUT 2 mV/V

2.2.3. Driver selection:


Criteria for drivers:
 Can handle maximum current of 1.8A per motor, 15VDC.
 Capable of controlling 2 independent motors.
 Linear relationship between output voltage and PWM.
From these criteria and consider some drivers in market, team decided to choose driver
TB6612 because it provides suitable current handling (2A) for motors, required voltage and
ensures the linear PWM-voltage relationship with high efficiency and reliability.
Driver will receive PWM from MCU to control motor speed.

27
Figure 2.11: BT6612 driver
Table 2.4: BT 6612's technical specification
Parameter Value / Range

Motor Supply Voltage (VM) 2.5 V ~ 13.5 V

Logic Supply Voltage (VCC) 2.7 V ~ 5.5 V

Output Current (Iout) 1.2 A continuous / 3.2 A peak per channel

Number of Channels 2 (dual H-bridge, can drive 2 DC motors)

Standby Current (Istb) < 1 µA (typical)

PWM Frequency Up to 100 kHz

Output ON-Resistance (Ron) ~0.25 Ω (total, high + low side, typ.)

Control Inputs IN1, IN2, PWM, STBY (logic level: 2.7–5.5 V)

Brake Modes Short brake, standby

Operating Temperature –20 °C to +85 °C

Package SSOP24 (0.65 mm pitch)


Examining the linearity of driver

28
RPM
40
35
30
25
20
15
10
5
0
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 00 10 20 30 40 50 60 70 80 90 00 10 20 30 40 50
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2

RPM

2.2.4. DC-DC converter selection:


We use LM2596S to reduce voltage to maximum voltage that motors and sensors can
handle.

Figure 10: LM2596


Table 2.5: LM2596S's technical specification
Parameter Value

Input Voltage Range 4.5 V – 40 V

Output Voltage Range 1.2 V – 37 V (adjustable)

Maximum Output Current 3 A (typical continuous), 2 A (stable)

Efficiency Up to 80–90 %

Switching Frequency ~150 kHz

Output Ripple ~30 mV (typical)

Protections Thermal shutdown, current limit, short-circuit

29
Package TO-263 (LM2596S IC) / module available

Isolation:

Use isolation to protect mcu from back emf.


Table 2.6:
Parameter Typical / Max Value Unit

Input Voltage (max) 1.65 → 5.5 V

DC Input Current 2 mA

Input Forward Voltage 1.3 (at I_in = 1 mA) V

Output Collector Current 50 mA

Output Collector-Emitter Voltage 70 V

Propagation Delay 18 (typical) ns

Supply Current (V_CC) 2 mA

Common-mode Rejection Ratio 10 kV/µs —

Isolation Voltage 5 kV RMS V RMS

From electric component selections, the electric diagram as shown below:

30
31
CHAPTER 3: MECHANICAL DESIGN
3.1. Wheel selection:
Driving Wheels: Select V3 wheels with a diameter of 65 mm from Hshop.
Caster Wheel: Select a caster wheel with a height of 40 mm from Hshop. P

3.2. Basic Dimensions of the Vehicle


Robot mass: m=4 kg (robot estimated mass 2 kg + maximum payload 2 kg)
Assume that within 1 second the robot accelerates from 0 m/s → v max=0 ,5 m/ s, and
vice versa. Therefore, robot acceleration is:
v max −v 0 0 , 5−0 2
a= = =0 ,5 (m¿ s )
t 1
Rolling friction coefficients of the drive wheels and caster wheel are μ1=0,015 and
μ2=0 ,04
We analyze the robot's dynamics based on the document [1]

Figure 3.3. Robot dynamics analysis


Where:
N1: Reaction force at the drive wheel
N2: Reaction force at the driven wheel
Fms1: Rolling friction on drive wheel

32
Fms2: Rolling friction on driven wheel
Pstop: Motor stopping force
L = L1 + L2 = 0,3m: Distance between front and rear wheel axles
h=0,0015m: Height from vehicle center of mass to ground
r: Wheel’s radius
M=4kg: robot’s mass
g = 9.8 𝑚/𝑠2: Gravitational acceleration
a=0,5 m/s2: Acceleration
Force balance equation when robot start to slow down:

{
∑ F x =0
∑ F y =0
∑ M x /C=0

{
2 P stop +2 F ms 1 + F ms2=2 P stop +2 μ 1 N 1 + μ2 N 2=Ma
2 N 1+ N 2 =Mg
N 2 L1−F ms 2 h−2 F ms1 h−2 N 1 L2=0

{
2 P stop +0 , 03 N 1 +0 , 04 N 2=2
→ 2 N 1 + N 2=39 , 2
N 2 L1−2 N 1 L2 + F ms2 h+2 F ms1 h+2 Pstop =0

{
N 1=40 Pstop −8 , 64
→ N 2=56 , 48−80 P stop
16,974−24 P stop−39 , 2 L2=0

In order to make the robot stay flat on surface, both N1 and N2 must grater than 0N


{ 0,216 N < Pstop < 0,706 N
16,974−24 P stop−39 , 2 L2=0
→ 0,002 m< L2 <0,301 m
We choose L2 = 200mm.

𝐺 𝐹𝑙𝑡

𝑁𝑤
𝑁𝑤

𝑃

Figure 3.1: Rollover calculation diagram


33
From motor length and wheel width, choose distance between wheel centers is
b=180 mm.
Condition to avoid side rollover when cornering: the gravitational moment about the
rotation center must be greater than the centrifugal moment:

2
Pb Mv Mgb
F ¿ h− ≤0⇒ h− ≤0
2 R 2
gb R min 9 , 81× 0 ,18 × 0 ,5
⇒h≤ 2
= 2
=1 , 77(m)
2v max 2 ×0 , 5
In order for the car not to slide when cornering, the centripetal force, in this case, the
total frictional force acting on the vehicle is greater than the centrifugal force:
2
∑ F ms ≥ Ma ⇒ μMg ≥ MRv ⇒ v ≤ √ μgR

We have speed 𝑣 ≤ 1.56 (𝑚/𝑠)

3.3. Motor selection calculation:


Centripetal acceleration:
a 0,5 2
γ= = ≈ 11, 76(m¿ s )
R 42 , 5× 10−3
Wheel mass: mwheel =0 , 05 kg
Wheel radius: R=42 ,5 mm

34
Figure 3.3: Vehicle force calculation diagram
Where Pk is Motor traction force
Newton’s Second Law:

{
2 P k −2 f r 1 −f r 2=2 P k −2 μ 1 N 1−μ 2 N 2=Ma
2 N 1 + N 2=Mg
2 N 1 L2=N 2 L1

→ N 1=6 , 53 ( N )∧N 2=26 ,13 (N)


Motor traction force:
Ma+ f r 2+2 f r 1
Pk = =1 ,62(N )
2

𝑅 𝜏
𝑎

𝑚 𝑃

𝑁
𝑓𝑟 𝑃𝑘

Figure 3.2 Drive wheel force calculation diagram


Drive wheel motion equation:
1 2
τ −Pk R +f r 1 R=Iγ= mwheel R γ
2
1 2 1 2
→ τ=P k R+ mwheel R γ−f r R=1 ,62 ×0,0425+ × 0 , 05 ×0,0425 ×15 , 38−0 ,1 ×0,0425
2 2
¿ 0 , 07(N . m)
With:
τ : Motor Torque
R :Wheel radius
Pk :Traction Force exerted by the road surface on the contact area of the wheel
f r 1 ∷ Friction Force
Iγ : Rotational InertiaTorque
Angular velocity of the drive wheel:
v max 0 ,5
ω= = =11 ,76 rad /s ≈ 112 , 4 rpm
R 0,0425

35
Based on section 4.2 of [1], we choose motor’s safety factor is 1.5.
Motor power:
P=1 , 5 τω=1, 5 ×0 , 06 × 15 ,38=1 ,38 (W )
Table 3.1: Motor selection
Specification GA25 - 370 Required
Voltage 12 VDC /
No-load speed 280 rpm /
Loaded speed 215 rpm 112,4 rpm
Power ? 1,38 W
Loaded torque 0,2 0,07 Nm
Encoder pulse 11 /
Speed ratio 21,3 : 1 /
Price 195k /

3.4. Designation of Robot frame

To manufacture the robot frame and motor mounts, we use AWEA F-87 CNC Milling
machine, with the accuracy of 0,008mm.1
Based on Chapter 2 of book [2], we calculate:
T 8
a= = =5.4
i 1 , 48
With
T =8 μm:range of tolerance
i=0 , 45 √ D+0,001 × D=1 , 48
3

D=33 mm: nominal dimension of milling slot


Based on Table 2.1 and Table 2.3 of book [2], we choose the tolerance grade IT5

1
Raza N.Jazar, Vehicle Dynamic: Theory and Application
36
Figure 3. Dimensional chain formed along the y direction.
Where:
A1 and A2 are the increasing component link.
A3 and A4 are the decreasing component link.
AΣy is the closed loop link.
Therefore, we have:

{
E S 1=+0.08 mm
+ 0.008
A1=2 E I 1=0 mm
T 1=0.08 mm

{
E S 2=+0.08 mm
+0.008
A2=19.75 E I 2=0 mm
T 2=0.08 mm

{
e s3 =0 mm
A3 =2−0.008 e i 3=−0,008 mm
T 3 =0.08 mm

{
e s 4 =0 mm
A 4=19.75−0.008 e i 4 =−0,008 mm
T 4 =0.08 mm

{
A Σy =0 mm
→ E S Σy =+0,016 mm
E I Σy =−0,016 mm
+ 0.016
→ A Σy =0−0.016

Figure 3. Dimensional chain formed along the y direction.


Where:
A1 and A2 are the increasing component link.
A3 and A4 are the decreasing component link.
AΣx is the closed loop link.
Therefore, we have:

{
E S 1=+0.08 mm
+0.008
A1=0 E I 1=0 mm
T 1=0.08 mm

37
{
E S 2=+0.08 mm
+0.008
A2=13.25 E I 2=0 mm
T 2=0.08 mm

{
e s 3=0 mm
A3 =0−0.008 e i3 =−0,008 mm
T 3=0.08 mm

{
e s 4 =0 mm
A 4=13.25−0.008 e i 4 =−0,008 mm
T 4 =0.08 mm

{
A Σx =0 mm
→ E S Σx =+0,016 mm
E I Σx =−0,016 mm
+ 0.016
→ A Σx =0−0.016
Concentricity error is √ 0.032 +0.0322=0.045 mm , which is acceptable.
2

3.5. Strength Simulation for the Structure


3.5.1. Strength Simulation for the Chassis
Simulation is performed with a 2 kg load.

Figure 3.4 Stress distribution on the chassis

The maximum displacement occurs at the load application point.

38
Figure 3.5 Displacement on the chassis

3.5.2. Strength Simulation for the Load Holder

Figure 3.6 Stress distribution on the load holder

Figure 3.7 Displacement on the load holder

39
3.6. 3D Model of the Vehicle Structure

Figure 3.8 Virtual model of the vehicle

40
CHAPTER 4: ELECTRICAL DESIGN
4.1. Sensor circuit design:
4.1.1. Resistor selection for line sensor:

From [tcrt50 datasheet], we have the basic structure for sensor operation as shown
below:

Figure 4.111: TCRT5000's operation


With I F : Forward current
I C : collector current
The figure shows that the sensor operates with suitable I F and I C, thus, we have the
diagram for sensor circuit:

Figure 4.2: TCRT 5000 diagram


With the input power is about 5v, we also have the relationship between current transfer
ratio and forward current:

41
Figure 4.312: Current Transfer Ratio vs. Forward Current and Forward Current vs. Forward
Voltage of TCRT5000
Hence we choose I F =10 mA to achieve most efficient CTR, hence we choose
V F=1.12 V corresponding to the right figure.
From the left haft of figure 4.2, we have formula to calculate the R1:
V cc −V F 5−1.12
R 1= = =388 Ω
IF 0.01
Hence, we choose R1=470 Ω according to standard resistor in the market.

Figure 4.413: Collector current characteristics of TCRT5000


From the figure, I C =1 mA corresponding to I F , thus, V CE =0.4 V .
Assume the transistor is opened, R2 can be calculated with
V cc −V CE 5−0.4
R 2= = −3
=4600 Ω
IC 1× 10
Hence, we choose R1=4 k 7 Ω according to standard resistor in the market.

4.1.2. Distance from line to the sensor:

To calculate this value, we must examine value from sensor with each level of height
with each step = 1 mm.

42
Figure 4.514: Examine model schematic

43
Table 4.1: The result after measuring
DISTANC BLACK WHITE DIFF
E

1 1011 738 273


2 1021 800 221
3 1019 792 227
4 935 336 599
5 904 40 864
6 830 38 792
7 845 35 810
8 868 38 830
9 891 34 857
10 895 37 858
11 928 38 890
12 931 39 892
13 921 40 881
14 911 39 872
15 894 41 853

We can see from the table, the result reached highest stability from the distance 11 to
14, hence we stop measuring at height of 15.

Difference between Black and White detection


1200

1000

800

600

400

200

0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Black White
Figure 4.6: Chart of difference between black and white
44
The most difference between 2 background (Black and White) is at height at 12.
For better consideration, we examine the contrast when measure the ADC value within
each 2 mm from centerline.

Figure 15: Model for examining

And we have the result:


Table 2: Result

Position Value
-20 44
-18 116
-16 325
-14 843
-12 902
-10 905
-8 902
-6 902
-4 920
-2 920
0 924
2 921
4 918
6 902

45
8 916
10 904
12 892
14 890
16 592
18 110
20 45

Value range with h = 12 mm


1000
900
800
700
600
500
400
300
200
100
0
-20 -18 -16 -14 -12 -10 -8 -6 -4 -2 0 2 4 6 8 10 12 14 16 18 20
Figure 16: The value range

In the black line (-14 to 14), the ADC value is higher noticeably than the white line (-16 to -20 and 16
to 20).
Hence the distance from sensor to line is 12 mm is our choice.
4.1.3. Distance from the sensor to sensor:

First, we will see the model:

46
Figure 17: Model alone

We have Lsmin is the projection area distance of sensor and 10.2 mm is the width of sensor according
to datasheet.
Lsmin =R+r −d
With:
R( 12−0.7 ) tan 15o : Radius of detector area
r = ( 12−0.7 ) tan 8o : Radius of emission area
d = 3.8 mm: Distance between emission and detector
Hence,
Lsmin =8.4 mm
The smallest distance is the distance that help avoid projection overlap between each sensor.
The projection area of sensor has distance Lsmin =8.4 mm while it’s width is 10.2 mm, thus, the
smallest distance is 10.2 +1 = 11.2 mm with 1 is safety coefficient. The distance between each sensor
must be larger than 11.2 mm. [1]
And we also want two sensors to be at the edge of the line which will play a role in detecting line for
straight movement. [2]
From figure 21, we see that at 14 mm from the center line, the analog signal is still considerable
contrast between black and white area. [3]
From [1], [2], [3], we decided the distance between each sensor is 14 mm
4.1.4. Sensor’s arrangement:

Figure 18: Comparison of reflection of 2 position

The switching distance is the distance from the sensor to the target surface at which the sensor’s
output changes state (ON/OFF).
Figure 23 shows that when we arrange sensors like in position 2, the switching distance is higher,
thus, the result is the line detection is much smoother. We decided to make sensors on our board
perpendicular to the line for higher switching distance.
The number of the line detection board is 5 sensors. 3 sensors will help detecting line and when our
robot does the curve, however, we will use two more sensors on two sides for higher efficiency when
making the curve or at junction.

47
Figure 19: Sensor arrangement

4.1.5. Calib sensor:

When testing sensors, we saw that the range of each sensor is difference although they are in the same
position with the same height. The result is that the value they gave is different and not like each
other. This can be an obstacle for coding and choosing thresholds.
Thus, we will make calibration to receive similar value from sensors at the same position.
From data from “Calibrating sensor” by Bill Earl, we have the equation for calibrating sensor is:
( xi −ximin )
y i= y min +
x imax −ximin
( y max − y min )
With:
 x i :The current value∈the original range
 x min , x max :The original minimum∧maximum values when∈the white∧black area
 y min , y max :The desired minimum∧maximum values when∈the white∧black area
 y i :Value after calibration

To determine x min , x maxand choosing y min , y max , we measure 5 sensors in black and white area.

48
Figure 20: Measure model

Table 3: The value from 5 sensors

Senso x imax x imin


r

1 3843 866

2 3865 984

3 3945 1426

4 3771 1128

5 3987 1869

Then we use average method to achieve y min , y max


5

∑ x imin
1
y min = =3883
5
5

∑ ximax
1
y max = =1255
5
Thus, calibration equation for 5 sensors are:

( x i−866 ) × 2628
y 1=1255+
2977

( i
x −984 ) ×2628
y 2=1255+
2881

( x i−1426 ) × 2628
y 3=1255+
2519

( x i−1128 ) × 2628
y 4 =1255+
2643

( i
x −1869 ) × 2628
y 5=1255+
2118
49
4.1.6. Schematic and board simulation:

Figure 21: TCRT5000 schematic

Figure 22: PCB layout

Figure 23: 3D model

50
CHAPTER 5: CHOOSING THE CONTROL STRUCTURE
AND MCU
1. Choosing the control structure
Based on the load of algorithm programming and data processing, we believe that the
working ability of a MCU can totally handle all of the work. Therefore, we decided to choose
Centralized control Structure.
2. Choosing the MCU

There are several famous MCU in the market so-far, however, there 3 main
types that are famous and suitable for the college student:
2.1. Arduino

There are several Pros and Cons for Arduino:


Pros Cons
- Beginner-Friendly Development: - Limited Hardware Robustness:

51
Easy to program using the Arduino Boards are not very durable or
IDE, which is intuitive and widely reliable for demanding or long-term
adopted. industrial use.
- Large Supportive Community: A - Poor Noise Immunity: Prone to
huge global community provides electrical disturbances and not
tutorials, forums, and suitable for harsh industrial
troubleshooting help. environments.
- Extensive Library Ecosystem: - Restricted Peripheral Options:
Thousands of open-source libraries Fewer built-in peripherals and
are available, enabling quick expansion options compared to
integration with sensors, modules, professional-grade microcontrollers,
and IoT functions. which limits complex IoT
applications.

2.2. STM32

Pros Cons
- Industrial-Grade Reliability: - Steep Learning Curve: Requires
Designed for robust operation with developers to have deep knowledge
strong noise immunity, making it of hardware architecture and low-
suitable for industrial environments. level programming.

52
- Powerful Processing: Based on - Limited HAL Library Quality:
ARM Cortex architecture, enabling Vendor-provided Hardware
high-speed computation and Abstraction Layer (HAL) libraries
efficient task handling. are often poorly structured and not
- High Flexibility & Optimization: developer-friendly.
Direct register-level configuration - No Built-In Wireless Connectivity:
allows fine performance tuning and Lacks integrated Wi-Fi or Bluetooth
efficient resource usage. modules, limiting IoT application
development without external
components.

2.3. ESP32

Pros Cons
- High Processing Capability: - Lower Robustness: Not as durable
Equipped with a strong CPU (up to or reliable as industrial-grade MCUs
… MHz), capable of handling like STM32, especially in harsh
multitasking and complex environments.
operations. - Moderate Processing Power:
- Robust Development Framework: While capable, its computational
Comes with ESP-IDF, a well- performance is generally lower than
maintained vendor-provided API STM32’s high-performance Cortex
framework, along with cores.

53
comprehensive documentation for - Learning Curve for Developers:
easier development. Although easier than pure register-
- Built-In Wireless Connectivity: level programming, developers still
Includes integrated Wi-Fi and need to become familiar with ESP-
Bluetooth modules, making it ideal IDF, FreeRTOS concepts, and Wi-
for wireless communication and IoT Fi/Bluetooth stack integration.
applications.
- Cost-Effective: Offers powerful
features at a low price point, making
it one of the most affordable MCUs
for IoT projects.

→ I think with our application, we use a simple line – follower robot, with many
IOT application, I think ESP32 is the most suitable for our application.

Coding Process
Pin assignment

54
Motor Direction Control

55
56
Encoder Reading and Interpreting with 4x Decoding
/* ---------- APIs ---------- */
esp_err_t encoderInit(void)
{
pcnt_unit_config_t unit_config =
{
//* Because this is a signed 16-bit counter
.high_limit = 32767, // upper limit
.low_limit = -32768 // lower limit
};
57
ESP_ERROR_CHECK(pcnt_new_unit(&unit_config, &pcnt_unit_motor_a)); // Initialize
counter for motor A
ESP_ERROR_CHECK(pcnt_new_unit(&unit_config, &pcnt_unit_motor_b)); // Initialize
counter for motor B
ESP_LOGI(TAG, "Created PCNT units: motorA=%p, motorB=%p", pcnt_unit_motor_a,
pcnt_unit_motor_b);

/*
* Use both Channel A and Channel B for 4× decoding:
* - Each encoder cycle has 11 pulses per motor rev (per channel).
* - With gearbox ratio 21.3:1 → ~11 × 21.3 = 234 cycles/output rev.
* - 4× decoding counts every edge (rise+fall of A and B):
* 234 × 4 ≈ 936 counts per output revolution.
* - Resolution = 360° / 936 ≈ 0.38° per count.
*
* → Therefore, we must use BOTH channels (A & B) to detect direction
* and to maximize resolution (4× decoding).
*/

// -------- Motor A Channels Configuration --------


pcnt_chan_config_t chan_a_motor_a_config =
{
.edge_gpio_num = ENCODER_MOTORA_PHASEA_PIN, // Channel A drive the
counter
.level_gpio_num = ENCODER_MOTORA_PHASEB_PIN // Channel B for decide
the direction to increment or decrement
};
ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit_motor_a, &chan_a_motor_a_config,
&pcnt_chan_a_motor_a)); // Config channel from a unit
/**
* @note: - Increment at rising edge - rotate CCW.
* - Decrement at falling edge - rotate CW.
* - esp_err_t pcnt_channel_set_level_action(pcnt_channel_handle_t chan,
* pcnt_channel_level_action_t high_act, pcnt_channel_level_action_t low_act)
*/
ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_a_motor_a,
PCNT_CHANNEL_EDGE_ACTION_INCREASE,
PCNT_CHANNEL_EDGE_ACTION_DECREASE));
/**
* @note: - pcnt_channel_set_level_action(channel, action_if_level_is_low,
action_if_level_is_high);
* - PCNT_CHANNEL_LEVEL_ACTION_KEEP, // if B is LOW → keep edge
action as is
PCNT_CHANNEL_LEVEL_ACTION_INVERSE // if B is HIGH → invert
edge action
*/
ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_a_motor_a,
PCNT_CHANNEL_LEVEL_ACTION_INVERSE,
PCNT_CHANNEL_LEVEL_ACTION_KEEP));

58
pcnt_chan_config_t chan_b_motor_a_config =
{
.edge_gpio_num = ENCODER_MOTORA_PHASEB_PIN, // Channel B drive the
counter (Motor A)
.level_gpio_num = ENCODER_MOTORA_PHASEA_PIN // Channel A decides
direction (Motor A)
};
ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit_motor_a, &chan_b_motor_a_config,
&pcnt_chan_b_motor_a)); // Config channel from a unit
ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_b_motor_a,
PCNT_CHANNEL_EDGE_ACTION_INCREASE,
PCNT_CHANNEL_EDGE_ACTION_DECREASE));
ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_b_motor_a,
PCNT_CHANNEL_LEVEL_ACTION_INVERSE,
PCNT_CHANNEL_LEVEL_ACTION_KEEP));

// -------- Start counter for motor A --------


ESP_ERROR_CHECK(pcnt_unit_enable(pcnt_unit_motor_a));
ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit_motor_a));
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit_motor_a));
int countA = 0;
ESP_ERROR_CHECK(pcnt_unit_get_count(pcnt_unit_motor_a, &countA));
ESP_LOGI(TAG, "Motor A PCNT started (count = %d)", countA);

// -------- Motor B Channels Configuration --------


pcnt_chan_config_t chan_a_motor_b_config =
{
.edge_gpio_num = ENCODER_MOTORB_PHASEA_PIN, // Channel A drives the
counter (Motor B)
.level_gpio_num = ENCODER_MOTORB_PHASEB_PIN // Channel B decides
direction (Motor B)
};
ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit_motor_b, &chan_a_motor_b_config,
&pcnt_chan_a_motor_b));
ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_a_motor_b,
PCNT_CHANNEL_EDGE_ACTION_INCREASE,
PCNT_CHANNEL_EDGE_ACTION_DECREASE));
ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_a_motor_b,
PCNT_CHANNEL_LEVEL_ACTION_INVERSE,
PCNT_CHANNEL_LEVEL_ACTION_KEEP));

pcnt_chan_config_t chan_b_motor_b_config =
{
.edge_gpio_num = ENCODER_MOTORB_PHASEB_PIN, // Channel B drives the
counter (Motor B)
.level_gpio_num = ENCODER_MOTORB_PHASEA_PIN // Channel A decides
direction (Motor B)
};
ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit_motor_b,
&chan_b_motor_b_config, &pcnt_chan_b_motor_b));
59
ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_b_motor_b,
PCNT_CHANNEL_EDGE_ACTION_INCREASE,
PCNT_CHANNEL_EDGE_ACTION_DECREASE));
ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_b_motor_b,
PCNT_CHANNEL_LEVEL_ACTION_INVERSE,
PCNT_CHANNEL_LEVEL_ACTION_KEEP));

// -------- Start counter for motor B --------


ESP_ERROR_CHECK(pcnt_unit_enable(pcnt_unit_motor_b));
ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit_motor_b));
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit_motor_b));
int countB = 0;
ESP_ERROR_CHECK(pcnt_unit_get_count(pcnt_unit_motor_b, &countB));
ESP_LOGI(TAG, "Motor B PCNT started (count = %d)", countB);
return ESP_OK;
}

int get_encoder_count_motor_a(void)
{
int count = 0;
pcnt_unit_get_count(pcnt_unit_motor_a, &count);
return count;
}

int get_encoder_count_motor_b(void)
{
int count = 0;
pcnt_unit_get_count(pcnt_unit_motor_b, &count);
return count;
}

60
CHAPTER 6: SYSTEM MODELLING
6.1. Robot Kinematic Modelling
Because of the working conditions of the robot: constant load, plain map, we decided to
use the kinematic model because using the dynamic model in this case is unnecessary.
From the principle diagram of the robot, the kinematic model can be denoted as
follows:
 GR= d (m): the length from the driving shaft to the tracking point
 ω : Rotation velocity of the robot
 R (m): Radius of the driven wheels
 G, R: Center point of the driving shaft and tracking point, respectively.
 E: is the reference point that the robot needs to follow.
For the robot to track the line properly, an error model of the robot must be made to
design the line tracking model. The model in the figure below defines the error of the system.
We define the errors as follows:
 e 1: is the error from the reference point E to the tracking point R in the horizontal
direction.
 e 2: is the error from the reference point E to the tracking point R in the vertical
direction.
 e 3: is the error from the GR axis to the line-tracking vector.

Kinematics model of the robot


We have the kinematic equation:

61
x˙G=v × cosθ
y˙G=v × sinθ
θ˙G=ω

[ ] [ ][ ]
x˙G cos θ 0
→ y˙G = sin θ 0 v
ω
θ˙G 0 1

The coordinate of the reference point R:

{ x R=x G + dcosθ
y R = y G +dsinθ
The kinematic equation at the point R is:

{
x˙R = x˙G−d θ̇ sinθ
y˙R = y˙G +d θ̇ cosθ
θ˙R=θ̇

The kinematic equation at the point E:

{
x˙E =v E cos θ E
y˙ E=v E sin θ E
θ˙E =ω E

6.2. Determine positional error

[][ ][ ]
e1 cosθ sinθ 0 x E−x R
=
e 2 −sinθ cosθ 0 y E− y R
e3 0 0 1 θ E−θ R

{
e1=( x E−x R ) cosθ+ ( y E − y R ) sinθ
→ e =−( x −x ) sinθ+ ( y − y ) cosθ
2 E R E R
e3 =θE −θ R
( 1)
Take the derivative of the 2 side of equation (1):

{
ė1=( x˙E− x˙R ) cos θ−( x E −x R ) sin θ θ̇+ ( y˙E− y˙R ) sinθ+ cosθ ( y E − y R ) θ̇
ė 2=−( x˙E − x˙R ) sin θ−( x E −x R ) cos θ d θ̇+ ( y˙E − y˙R ) cosθ−sinθ( y E − y R ) θ̇
ė3=θ˙E −θ̇

{
e˙1=v E cos ( θ E −θ R )−v +e 2 ω
→ ė2=v E sin ( θ E −θ R )−(d +e 1)ω
e˙3 =ω E−ω

We get the following equation:

62
[ ][ ][ ][ ]
e˙1 v E cos e3 −1 e2
v
e˙2 = v E sin e3 + 0 −d−e 1
ω
e˙3 ωE 0 −1

6.3. Determine the simulation error


At the beginning, the starting velocity v 0 ≈ v E , so that the e 1can be neglected. The
purpose of the algorithm is to make the tracking point G follow the reference point E. To do
that, we must determine error e 2 and e 3. In reality, e 2 is measured from the sensor array, so
that we just have to calculate the error e 3. To compute this error, we make the robot go a
distance ds as small as when we connect R and R' , we have a tangential line to the tracking
path. So, we have the equation of e 3 as follows:
'
e 2−e2
e 3=arctan
ds

The coordinate of e 3

6.4. Design the Line Tracking Algorithm


We choose Lyapunov’s function as follows:
1 2 1 2 1−cos e 3
V = e1 + e 2+ ≥ 0 withk i> 0
2 2 k2
Take the derivative, we get:
1
V̇ =e1 ė 1+ e2 ė 2+ sin e3 ė 3
k2
63
1
¿ e 1 ( v r cos e 3−v +e 2 ω ) +e 2 ( v r sin e 3−dω−e 1 ω ) + sin e 3 ( ωr −ω )
k2
sin e3
¿ e 1 ( v r cos e 3−v ) + ( k 2 v r e 2+ ω R−ω )−dω e 2
k2
To obtain the stability condition ¿)

{ ( v r cos e 3−v )=−k 1 e1


( k 2 v r e 2 +ω R−ω ) =−k 3 sin e 3
 We get the equation:

{ v=v r cos e 3+ k 1 e1
ω=k 2 v r e 2 +ωr + k 3 sin e3
Therefore, it means that the system is stable, with the tracking error converging to 0 as t
→ ∞ because V̇ <0 with k i> 0.
We define the linear velocity and angular velocity of the left wheels and right wheels as
v l , v r ,ω l ,ω r , respectively.
Based on the law of the differential drive, we have a relationship between the above
parameters as follows:
v l +v r ωl +ω r
v= ω=
2 2
ωb ωb
 v l=v − =r ω l ( rpm ) , v r =v + =r ωr ( rpm ) ,
2 2
vl v
 ω l= ( rpm ) , ωr = r ( rpm )
r r

6.5. Controller Design


6.5.1. Motor and driver investigation
We have the 2 motors, GA25-370, with a maximum output shaft speed of 280 RPM,
and driver TB6612FNG. Using Arduino Nano to test with the PWM(%) signal = 75%. The
result is as follows:

64
Using the Matlab System Identification Toolbox, we can find the Transfer function of
the above motors, with the input value is a PWM signal (0-255), the output signal is the
output shaft revolution per minute. The result is as follows:
Motor 1:
45.82
G ( s )=
s +38.93

- Motor 2:
37.16
G ( s )=
s +31.84

65
6.5.2. PID Controller Design
After having the transfer function of the two motors, we can use the PID tuner and
MATLAB Simulink to get the two PID controllers for the 2 motors. The result is as follows:
The performance criteria are stated as follows:
 Rise time ≤ 0.1(s)
 Settling time ≤ 0.2(s)
 Overshoot ≤ 5(% )
 e ss ≈ 0
The block diagram setup in MATLAB Simulink is as follows:

Using the PID tuner in addition to the trial and error method, we get the results as
follows:

PI Compensator standard form:


Ki
Gc =K p +
s
Therefore, the TF of Motor 1 become:

(
Gs = K p +
Ki
s )( s+38.93
45.82
)
Hence, the characteristic equation:
2
s +38.93 s + K p 45.82 s +45.82 K i=0
2
↔ s + ( 38.93+ K p × 45.82 ) s+ 45.82 × K i=0
Besides, we have the criteria for the controller:
−δπ
√ 1−δ 2
%OS ≤ 5 % → e ≤0.05 → δ=0.6901
4
T s ≤0.2 → ≤ 0.2→ ωn ≥ 28.9813
δ ×ω n
3 2
1.76 δ −0.417 δ +1.039 δ+1
T r ≤0.1 → ≤0.1 → ωn ≥ 20.9687
ωn

66
Therefore, we will choose,

{ωδ=0.6901
≥ 28.9813
n

We have the standard form of Second-Order TF is:


2 2
s +2 δ ω n s+ ωn=0
Then we will synchronize the formula, we have:

{
2 δ ω n=38.93+ K p × 45.82
ω 2n=45.82 × K i

{
40=38.93+ K p × 45.82
839.9157=45.82× K i


{
K p =0.02335
K i=18.3307
After we simulate with MATLAB, here is the response

As we can see from the graph, the response has Overshoot 5%.

Next, we move to the second motor, the second motor after compensated:

(
Gs = K p +
Ki
s )( s+31.84
37.16
)
Hence, the characteristic equation:
2
s +31.84 s+ K p 37.16 s+37.16 K i =0
2
↔ s + ( 31.84+ K p ×37.16 ) s +37.16 × K i=0
Besides, we have the criteria for the controller:
−δπ
√ 1−δ 2
%OS ≤ 5 % → e ≤0.05 → δ =0.6901
4
T s ≤0.2 → ≤ 0.2→ ωn ≥ 28.9813
δ ×ω n
3 2
1.76 δ −0.417 δ +1.039 δ+1
T r ≤0.1 → ≤0.1 → ωn ≥ 20.9687
ωn
Therefore, we will choose,

{ωδ=0.6901
≥ 28.9813
n

67
We have the standard form of Second-Order TF is:
2 2
s +2 δ ω n s+ ωn=0
Then we will synchronize the formula, we have:

{
2 δ ω n=31.84+ K p ×37.16
ω 2n=37.16 × K i

{
40=31.84 + K p ×37.16
839.9157=37.16 × K i


{
K p=0.2195
K i =22.6027
After we simulate with MATLAB, here is the response

Finally, we tune the PID and achieve the results as bellow:


Motor 1:
Parameter Value
Kp 1.2
KI 44
KD 0
Rise time 0.0427 (s )
Settling time 0.0809(s)
Overshoot 0%

Motor 2:
Parameter Value
Kp 0.66

68
KI 40
KD 0
Rise time 0.0428(s)
Settling time 0.0773(s)
Overshoot 0%

 The result satisfies the controller design criteria

6.6. Simulation and Result


Because the error from the left or right side of the line is ± 3(mm) and the width of the
line is 26(mm), the allowable range of e 2 is from -16 mm to 16 mm.
For the line tracking factor k 1 , k 2 , k 3are 5, 0.00040, 0.6, respectively, in addition to the
transfer function of the two models and the two PID controllers, with the reference velocity is
400mm.
The result is as follows:
1kg-load case 2kg-load case

1kg- load case 2kg-load case

69
1kg-load case 2kg-load case

1kg-load case 2kg-load case

 We can see that e 2is in the allowable range

70
References:

1.
Iman Ghaffari Barzegar . Motor-Reducer Sizing Procedure for Robotic Application .
Retrieved September 26th, 2025, from https://www.politesi.polimi.it/retrieve/83894122-
77e9-41e2-8af0-514bed35156a/imanghaffariFinalThesis.pdf
2.
Raspberry Pi Foundation. (n.d.). Build a line-following robot with Python. Raspberry Pi
Projects. Retrieved September 12, 2025, from
https://projects.raspberrypi.org/en/projects/rpi-python-line-following/2
3.
Circuit Digest. (n.d.). Arduino Uno line follower robot. Circuit Digest. Retrieved
September 12, 2025, from https://circuitdigest.com/microcontroller-projects/arduino-uno-
line-follower-robot
4.
Instructables. (n.d.). Line following robot. Instructables. Retrieved September 12, 2025,
from https://www.instructables.com/Line-Following-Robot/
5.
AUMI. (n.d.). Magnetic line-based navigation solutions for AGV line detector sensor from
MLS SICK. AUMI. Retrieved September 12, 2025, from
https://aumi.com.vn/en/magnetic-line-based-navigation-solutions-for-agv-line-detector-
sensor-from-mls-sick/#:~:text=Built%2Din%2010%20markers%20(Makers,CANopen
%2C%20Modbus%20RTU%20RS%2D485
6.
Robu. (n.d.). IR sensor working. Robu. Retrieved September 12, 2025, from
https://robu.in/ir-sensor-working/
7.
NShopVN. (n.d.). Nguyên lý hoạt động của cảm biến cân nặng Loadcell: Cách sử dụng
cảm biến với Arduino để làm một cân điện tử đơn giản. NShopVN Blog. Retrieved
September 12, 2025, from https://nshopvn.com/blog/nguyen-ly-hoat-dong-cua-cam-bien-
can-nang-loadcell-cach-su-dung-cam-bien-voi-arduino-de-lam-mot-can-dien-tu-don-gian/
8. Mechatronics System Design through Project – A Case Study
9. Analysis of Line Sensor Configuration for the Advanced Line Follower Robot
10. A Hierarchical Control System for Autonomous Driving towards Urban Challenges
11. Nguyễn Hữu Cẩn, Lý thuyết Ô tô – máy kéo.

71

You might also like