0% found this document useful (0 votes)
115 views

Advanced Line Following Robot

The document describes the design and construction of an advanced line following robot. It uses a Teensy 3.6 microcontroller along with sensors for line detection, orientation, and odometry. The robot is built on a perfboard and uses compact gear motors and wheels. Detailed instructions are provided on prototyping the various electronic components and connecting them according to the circuit design to enable line following capabilities.

Uploaded by

minh nguyen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Advanced Line Following Robot

The document describes the design and construction of an advanced line following robot. It uses a Teensy 3.6 microcontroller along with sensors for line detection, orientation, and odometry. The robot is built on a perfboard and uses compact gear motors and wheels. Detailed instructions are provided on prototyping the various electronic components and connecting them according to the circuit design to enable line following capabilities.

Uploaded by

minh nguyen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

instructables

Advanced Line Following Robot

by midhun_s

This is an advanced line following robot based on Teensy 3.6 and QTRX line sensor that I have built and have been
working on for quite some time. There are some major improvements in the design and performance from my
earlier line following robot. The speed and response of the robot has improved. The overall structure is compact
and lightweight. The components are arranged close to the wheel axis so as to minimize angular momentum. High
power micro metal gear motors provide the adequate torque and aluminium hub silicone wheels o er much-
needed traction at high speeds. Prop shield and wheel encoders enable the robot to determine its position and
orientation. With Teensyview mounted on board, all the relevant information can be visualized and important
program parameters can be updated using pushbuttons.

To begin building this robot, you will need the following supplies (and a lot of time and patience at your disposal).

Supplies:

Electronics

Teensy 3.6 Development Board


Prop Shield with Motion Sensors
Sparkfun TeensyView
Pololu QTRX-MD-16A Re ectance Sensor Array
15x20cm double-side prototype PCB
Pololu Step-Up/Step-Down Voltage Regulator S9V11F3S5
Pololu Adjustable 4-5-20V Step-Up Voltage Regulator U3V70A
MP12 6V 1580 rpm micro gear motor with encoder (x2)
DRV8833 Dual Motor Driver Carrier (x2)
3.7V, 750mAh Li-Po battery
ON/OFF switch
Electrolytic capacitor 470uF
Electrolytic capacitor 1000uF (x2)
Ceramic capacitor 0.1uF (x5)
Pushbuttons (x3)
10mm Green LED (x2)

Hardware

Atom Silicone Wheel 37x34mm (x2)


Pololu Ball Caster with 3/8” Metal Ball

Advanced Line Following Robot: Page 1


N20 motor mount (x2)
Bolt and nuts

Cables and Connectors

24AWG exible wires


24 pin FFC to DIP breakout and FFC cable (Type A, 150mm length)
Round female pin header
Round female pin header long terminal
Right-angled dual row female header
Right-angled dual row male header
Male pin header
Male needle pin header

Tools

Multimeter
Soldering iron
Solder wire
Wire stripper
Wire cutter

https://www.youtube.com/watch?v=qrzdEw3NMq0

Step 1: Systems Overview

Advanced Line Following Robot: Page 2


As with my earlier design of a self-balancing robot, The major systems of the robot are outlined below.
this robot is an assemblage of breakout boards
mounted on a perfboard which also serves the Microcontroller : Teensy 3.6 development board
purpose of a structure. featuring 32-bit 180MHz ARM Cortex-M4 processor.

Line sensor : Pololu's QTRX-MD-16A 16-channel Power supply : 3.7V, 750mAh lipo battery as power
analog output line sensor array in medium-density source. 3.3V step-up/down regulator powers
arrangement (8mm sensor pitch). microcontroller, sensors, and display device.
Adjustable step-up regulator powers the two motors.
Drive : 6V, 1580rpm, high power micro metal gear
motors with magnetic wheel encoder and silicone User interface : Teensyview for displaying information.
wheels tted on aluminium hubs. Three-pushbutton breakout for accepting user inputs.
Two numbers of 10mm diameter green LEDs for
Odometry : Magnetic wheel encoder pairs for status indication while running.
estimating the coordinates and distance covered.

Orientation sensor : Prop shield with motion sensors


for estimating position and heading of the robot.

Step 2: Let's Start Prototyping

We will be implementing the above circuit on the perfboard. We have to rst keep our breakout boards ready by
soldering headers on them. The video will provide an idea regarding which headers should be soldered on which
breakout boards.

After soldering headers on breakout boards, stack the Teensyview and pushbutton breakout on top of Teensy.

https://www.youtube.com/watch?v=0vdxtk5EIHE

Advanced Line Following Robot: Page 3


Step 3: Prototyping - Perfboard

Get the 15x20cm double side prototype perfboard We will begin our prototyping by soldering the
and mark the boundary with a permanent marker as header pins and sockets on the perfboard. The
shown in the picture. Drill M2 size holes for mounting breakout boards will be later inserted on these
the sensor array, caster wheel, and micro metal gear headers. Give careful attention to the position of the
motors on locations marked with a white circle. We headers on the perfboard. We will be connecting all
will later cut the perfboard along the boundary after wires based on this layout of headers.
soldering and testing all components.

9 6

4 5
3
7 13 4
3 12
2 5
8 2
6
10 1

11 1

1. Prop shield with motion sensors 1. Female headers for prop shield
2. Teensy 3.6 2. Female headers for Teensy 3.6
3. Teensyview 3. Female headers for line sensor
4. 3.3V step-up/down voltage regulator 4. Female headers for voltage regulators
5. Adjustable step-up voltage regulator 5. Male headers for motor driver
6. QTRX-MD-16A line sensor 6. Male headers for battery
7. DRV8833 motor driver carrier
8. Switch
9. 24 pin FFC to DIP breakout
10. Micro metal gear motor
11. 10mm Green LED
12. Pushbutton breakout
13. Electrolytic capacitor

Step 4: Prototyping - Prop Shield

We will rst solder the connections to the prop shield. Since we are using only the motion sensors of the prop
shield, we need to connect only SCL, SDA and IRQ pins apart from the 3V and ground pins of prop shield.

Once the connection is complete, insert Teensy and prop shield and calibrate the motion sensors by following the
steps mentioned here.

Advanced Line Following Robot: Page 4


Step 5: Prototyping - Power and Ground

Solder all the power and ground connections referring to the picture. Insert all breakout boards in place and
ensure continuity using a multimeter. Verify the di erent voltage levels on board.

Li-po output voltage (usually between 3V and 4.2V)


Step-up/down regulator output voltage (3.3V)
Adjustable step-up regulator output voltage (set to 6V)

Advanced Line Following Robot: Page 5


2 3

1. 0.1uF ceramic capacitor


2. Header for 3.3V step-up/down voltage regulator
3. Header for adjustable step-up voltage regulator

Step 6: Prototyping - Motor Driver Carrier

The DRV8833 dual motor driver carrier board can deliver 1.2A continuous and 2A peak currents per channel. We will
connect the two channels in parallel to drive one motor. Solder the connections by following the steps below.

Parallel the two inputs and the two outputs of the motor driver carrier as shown in picture.
Connect input control wires to the motor driver.
Connect a 1000uF electrolytic capacitor and a 0.1uF ceramic capacitor across the Vin and Gnd
terminals of the two carrier boards.
Connect a 0.1uF ceramic capacitor across motor driver output terminals.

1. Electrolytic capacitor

Advanced Line Following Robot: Page 6


Step 7: Prototyping - Line Sensor Array Header

Teensy 3.6 has two ADCs - ADC0 and ADC1 that are multiplexed to 25 accessible pins. We can access any two pins
from the two ADCs at the same time. We will connect eight line sensors each to ADC0 and ADC1. The even number
sensors will be connected to ADC1 and odd number sensors to ADC0. Solder the connections by following the steps
below. We will later connect the line sensor using FFC to DIP adapter and cable.

Connect all even sensor pins (16,14,12,10,8,6,4,2) as shown in picture. Route the wire for connecting
sensor pin 12 through the reverse side of perfboard.
Connect emitter control pin (EVEN) to Teensy pin 30.
Connect all odd sensor pins (15,13,11,9,7,5,3,1) as shown in picture.
Connect a 470uF electrolytic capacitor across Vcc and Gnd.

If you closely observe the line sensor pins and their corresponding header pins on the perboard, you will notice
that the top row of the line sensor maps to the bottom row of the header on the perboard and vice versa. This is
because when we connect the line sensor to the perfboard using dual row right-angled headers, the rows will align
correctly. It took me quite some time to gure this out and correct the pin assignments in the program.

Advanced Line Following Robot: Page 7


2

1
1 3

1. Even sensor pins (16,14,12,10,8,6,4,2) 1. Odd sensor pins (15,13,11,9,7,5,3,1)


2. Connect on the reverse side of perfboard 2. 470uF electrolytic capacitor across Vcc and Gnd
3. Emitter control

1. QTRX-MD-16A pins

Step 8: Prototyping - Micro Gear Motor and Encoder

Fix the micro metal gear motor with encoder using N20 motor mounts.
Connect the motor and encoder wires as shown in the picture.
Left encoder - Teensy pins 4 & 0
Right encoder - Teensy pins 9 & 27

Advanced Line Following Robot: Page 8


2 1

1. 0.1uF ceramic capacitor across motor terminals


2. 0.1uF ceramic capacitor across motor terminals

Step 9: Prototyping - LEDs

The two LEDs indicate whether the robot has detected a turn or not. I have used a 470-ohm series resistor to
connect the LEDs to Teensy.

Left LED anode to Teensy pin 6


Right LED anode to Teensy pin 8

Step 10: Prototyping - Breakouts

Advanced Line Following Robot: Page 9


Now that we have completed all our soldering on the perfboard, we can carefully cut along the boundary marked
on the perfboard and remove the extra bits of perfboard. Also, attach the two wheels and caster wheel.

Insert all the breakout boards in their respective sockets. For inserting the FFC-DIP breakout and for xing the
QTRX-MD-16A line sensor, refer to the video.

https://www.youtube.com/watch?v=kw5KtEXQipE

Step 11: Software Libraries Overview

We will program the Teensy in Arduino IDE. We will need some libraries before we begin. The libraries that we will
use are:

Encoder
Teensyview
EEPROM
ADC
NXPMotionSense

And some that have been written speci cally for this robot,

PushButton
LineSensor
TeensyviewMenu
Motors

The libraries speci c to this robot are discussed in detail and are available for download in the next steps.

Advanced Line Following Robot: Page 10


Step 12: Libraries Explained - PushButton

This library is for interfacing the pushbutton breakout board with the Teensy. The functions used are

PushButton(int leftButtonPin, int centreButtonPin, int rightButtonPin);

Calling this constructor by creating an object con gures the pushbutton pins to INPUT_PULLUP mode.

int8_t waitForButtonPress(void);

This function waits until a button is pressed and released and returns the key code.

int8_t getSingleButtonPress(void);

This function checks if a button is pressed and released. If yes, returns the key code else returns zero.

Download
https://www.instructables.com/ORIG/FY3/OI4S/KF2JEJX6/FY3OI4SKF2JEJX6.cpp

Download
https://www.instructables.com/ORIG/FMQ/S725/KF2JEJX7/FMQS725KF2JEJX7.h

Step 13: Libraries Explained - Line Sensor

LineSensor is the library for interfacing the line sensor array with Teensy. The following are the functions used.

LineSensor(void);

Calling this constructor by creating an object initializes ADC0 and ADC1, reads threshold, minimum and maximum
values from EEPROM and con gures the sensor pins to input mode and emitter control pin to output mode.

void calibrate(uint8_t calibrationMode);

Advanced Line Following Robot: Page 11


This function calibrates the line sensors. The calibrationMode can be either MIN_MAX or MEDIAN_FILTER. This
function is explained in detail in a later step.

void getSensorsAnalog(uint16_t *sensorValue, uint8_t mode);

Reads sensor array in any of the three modes passed as argument. The mode is the state of the emitters and can be
ON, OFF or TOGGLE. TOGGLE mode compensates the sensor readings of re ectance due to ambient light. The
sensors connected to ADC0 and ADC1 are read synchronously.

int getLinePosition(uint16_t *sensorValue);

Calculates the position of the sensor array over the line by the weighted average method.

uint16_t getSensorsBinary(uint16_t *sensorValue);

Returns a 16-bit representation of the state of the sensors. A binary one indicates that the sensor is over the line
and a binary zero indicates that the sensor is o the line.

uint8_t countBinary(uint16_t binaryValue);

Passing the 16-bit representation of sensor values to this function returns the number of sensors that are over the
line.

void getSensorsNormalized(uint16_t *sensorValue, uint8_t mode);

Reads the sensor values and constrains each sensor value to its corresponding min and max values. The sensor
values are then mapped from their corresponding min to max range to 0 to 1000 range.

Download
https://www.instructables.com/ORIG/FOY/8KAV/KF2JEJX2/FOY8KAVKF2JEJX2.cpp

Download
https://www.instructables.com/ORIG/FOK/SOJ7/KF2JEJX3/FOKSOJ7KF2JEJX3.h

Step 14: Libraries Explained - TeensyviewMenu

TeensyviewMenu is the library where the functions for the display menu can be accessed. The following are the
functions used.

TeensyViewMenu(void);

Calling this constructor creates an object of class LineSensor, PushButton and TeensyView.

void intro(void);

This is for navigating the menu.

Advanced Line Following Robot: Page 12


void test(void);

This is called internally within the menu when the line sensor values are to be displayed on Teensyview for testing.

Download
https://www.instructables.com/ORIG/FS1/O6H0/KF2JEJX8/FS1O6H0KF2JEJX8.cpp

Download
https://www.instructables.com/ORIG/F1Q/H6DF/KF2JEJX9/F1QH6DFKF2JEJX9.h

Step 15: Libraries Explained - Motors

Motors is the library used for driving the two motors. The following are the functions used.

Motors(void);

Calling this constructor by creating an object con gures the motor direction control and PWM control pins to
output mode.

void setSpeed(int leftMotorSpeed, int rightMotorSpeed);

Calling this function drives the two motors at speeds passed as arguments. The value of speed can range from -255
to +255 with a negative sign indicating that the direction of rotation is reversed.

Download
https://www.instructables.com/ORIG/FSN/QS95/KF2JEJX4/FSNQS95KF2JEJX4.cpp

Download
https://www.instructables.com/ORIG/FZU/C4X4/KF2JEJX5/FZUC4X4KF2JEJX5.h

Step 16: Testing - Encoder Odometry

We will test the magnetic wheel encoders and display displays the position of the robot in terms of x-y
the position and distance covered by the robot. coordinates, displays the total distance covered in
centimeter and the angle turned in degrees.
Upload the DualEncoderTeensyview.ino. The program
displays the encoder ticks on Teensyview. The encoder I have referred the Implementing Dead Reckoning by
ticks increment if you move the robot forward and Odometry on a Robot with R/C Servo Di erential
decrement if you move it backward. Drive by Seattle Robotics Society for determining
position from encoder ticks.
Now upload the EncoderOdometry.ino. This program
Download
https://www.instructables.com/ORIG/F2Q/W2DD/KF13YIRB/F2QW2DDKF13YIRB.ino

Download
https://www.instructables.com/ORIG/F2I/LCG7/KF13YKUD/F2ILCG7KF13YKUD.ino

Advanced Line Following Robot: Page 13


Step 17: Testing - Prop Shield Motion Sensors

Make sure you have calibrated the motion sensors by following the steps mentioned here.

Now upload the PropShieldTeensyView.ino. You should be able to see the accelerometer, gyro and magnetometer
values of all three axes on the Teensyview.

Download
https://www.instructables.com/ORIG/FP3/T4HR/KF140VZC/FP3T4HRKF140VZC.ino

Step 18: Program Overview

The program for the advanced line follower is written in Arduino IDE. The program works in the following sequence
explained below.

Values stored in EEPROM are read and menu is displayed.


On pressing LAUNCH, the program enters the loop.
Normalized line sensor values are read.
Binary value of line position is obtained using normalized sensor values.
The count of the number of sensors that are over the line is calculated from binary value of line
position.
Encoder ticks are updated and total distance covered, x-y coordinates and angle are updated.
For di erent values of binary count ranging from 0 to 16, a set of instructions are executed. If the
binary count is in the range 1 to 5 and if the sensors that are over the line are adjacent to each other,
PID routine is called. Rotation is performed in other combinations of binary value and binary count.
In PID routine (which is infact a PD routine), the motors are driven at speeds calculated based on
error, change in error, Kp and Kd values.

The program at present does not measure orientation values from prop shield. This is a work in progress and is
being updated.

Upload TestRun20.ino. We will see how to navigate the menu, adjust settings and how to calibrate the line sensors
in the next steps following which we will test our robot.

Download
https://www.instructables.com/ORIG/FYV/R80R/KF2JEJV2/FYVR80RKF2JEJV2.ino

Step 19: Navigating Menu and Settings

The menu has the following settings which can be navigated using the left and right pushbuttons and selected
using the center pushbutton. The settings and their functions are described below.

Advanced Line Following Robot: Page 14


1. CALIBRATE: To calibrate line sensors.
2. TEST: To display line sensor values.
3. LAUNCH: To start line following.
4. MAX SPEED: To set the upper limit of the speed of the robot.
5. ROTATE SPEED: To set the upper limit of the speed of the robot when it performs a turn i.e. when
both wheels turn at equal speeds in opposite directions.
6. KP: Proportional constant.
7. KD: Derivative constant.
8. RUN MODE: To select between two operating modes - NORMAL and ACCL. In NORMAL mode, the
robot runs at prede ned speeds corresponding to line position values. In ACCL mode, the MAX
SPEED of the robot is substituted by ACCL SPEED at prede ned stages of the track. This can be
utilized to speed up the robot at straight sections of the track. The following settings are accessible
only if the RUN MODE is set as ACCL.
9. LAP DISTANCE: To set the total length of the race track.
10. ACCL SPEED: To set the acceleration speed of the robot. This speed replaces MAX SPEED at di erent
stages of the track as de ned below.
11. NO. OF STAGES: To set the number of stages where ACCL SPEED is used.
12. STAGE 1: To set the start and end distances of the stage in which MAX SPEED is substituted by ACCL
SPEED. For each stage, the start and end distances can be set separately.

https://www.youtube.com/watch?v=TsayV45mARk

Step 20: Line Sensor Calibration

Line sensor calibration is the process by which the threshold value of each of the 16 sensors is determined. This
threshold value is used to decide whether a particular sensor is over the line or not. To determine the threshold
values of 16 sensors, we use either of the two methods.

MEDIAN FILTER: In this method, the line sensors are placed above the white surface and a pre-de ned number of
sensor readings are taken for all 16 sensors. The median values of all 16 sensors are determined. The same process is
repeated after placing the line sensors over the black surface. The threshold value is the average of median values
of black and white surfaces.

MIN MAX: In this method, the sensor values are read repeatedly until the user prompts for a stop. The maximum
and minimum values encountered by each sensor are stored. The threshold value is the average of minimum and
maximum values.

The threshold values thus obtained are mapped to 0 to 1000 range.

The calibration of line sensors by the MIN MAX method is shown in the video. After calibrating the line sensors, the
data can be visualized as shown in the picture. The following information is displayed.

A 16-bit binary representation of line position with a binary 1 indicating that the corresponding line
Advanced Line Following Robot: Page 15
sensor is over the line and a binary 0 indicating that the line sensor is o the line.
A count of the total number of sensors that are over the line.
Minimum, maximum and sensor values (raw and normalized) of the 16 sensors, one sensor at a time.
Line position in the range -7500 to +7500.

The minimum and maximum line sensor values are then stored in EEPROM.

https://www.youtube.com/watch?v=w7dpLYpsPn4

1 2
3 4 5 6
7 8

1. 16-bit representation of line position


2. Number of sensors that are over the line
3. Sensor index
4. Min value
5. Sensor value
6. Max value
7. Normalized value
8. Line position value in the range -7500 to 7500

Step 21: Test Run

The video is of a test run in which the robot is programmed to stop after it completes one lap.

https://www.youtube.com/watch?v=04sliTk3wYA

Step 22: Final Thoughts and Improvements

Advanced Line Following Robot: Page 16


The hardware which is put together to build this to accurately determine the position and heading of
robot is not utilized to the full by the program which the robot. This data may then be used to program the
runs it. Lot of improvements could be made on the robot to learn the track in multiple laps. I encourage
program part. The motion sensors of prop shield is you to experiment on this part and share your results.
not used at present for determining position and
orientation. The odometry data from encoders can be Good luck.
combined with the orientation data from prop shield

Advanced Line Following Robot: Page 17

You might also like