You are on page 1of 35

PATH TRACING SYSTEM FOR AN

AUTONOMOUS ROBOT
INTRODUCTION
The purpose of the project is to design a path tracing system for
a robot which is not under human control. The robot is designed
to move around at its own will. The movements of the robot
might depend on various factors which include information from
the sensors, some task specified by the user by programming the
microcontroller which specifies the movements based on the
task to be accomplished.
The path tracing system will track the movements of the robot
and makes a map from the starting point to the stopping point of
the robot. The path tracing system will help in supervising the
movements of the robot and, if required, in controlling the robot
to reach the destination. However, to trace the path to scale and
with accuracy, a lot of measuring devices need to be interfaced
with the microcontroller. Some of these devices are speedometer
(which will help in determining the speed of the robot), a device
to measure the r.p.m. of the motors and a device to measure the
angle of steering. Interfacing these devices with the
microcontroller will enhance the accuracy of the path tracing
system as more information is available regarding the
movements.

The path tracing system generates a map of the path traversed by


the robot on MATLAB. It uses the data available from the
microcontroller (controlling the robot) and manipulates the data
to generate an image showing the path of the robot.

APPLICATONS
Any process requiring a great deal of accuracy requires human
supervision. Hence, even if we design an autonomous system,
which is reliable as well as accurate, the essence of human
supervision cannot be ignored. The path tracing system helps us
to keep a track of the movements of the robot to make sure that
the robot is moving in the right direction to enable the robot to
reach the desired destination. The programs can be modified as
per need, if one wishes to control the robot to ensure that the
robot reaches the destination if it strays from the desired path.
Many other devices can be interfaced with the microcontroller,
in case, one wants to make the robot multi-tasking. These
devices can also be controlled by using the required programs.
However, in this project, we limit the application to tracing the
path followed by robot which is free to move randomly without
any human control.

REQUIREMENTS OF THE PROJECT


The project is based on both hardware and software. The
hardware section consists of the robot, two microcontrollers,
transmitter and receiver (RF-434 MHz), development boards
and DB9 connector to enable serial port communication through
USB. One of the microcontrollers is mounted on the robot and
the other microcontroller is connected to the computer for serial
port communication using DB9 connector (used to convert USB
port to a serial port). The RF-434 transmitter is connected to the
microcontroller of the robot and the data relevant to tracing the
path is sent to the RF-434 receiver connected to the computer.
The data received by the microcontroller is then sent to the
computer using serial port communication.
The software portion comes to play while programming the
microcontrollers and while processing the received data. The
programs for the microcontrollers are in Embedded C. The
AVR-GCC cross compiler converts the C- program into hex
code. MATLAB has been used to receive data from the serial
device. A program in MATLAB creates a map of the path
traversed by the robot by using the received data. The MATLAB
program also returns the final position of the robot (in terms of
the row and column of the matrix used to create the map) with
respect to the initial position which is, by default, the centre of
the matrix.

HARDWARE COMPONENTS
1. Robot (using D.C. motors)
2. Two ATMega32 Microcontrollers
3. Wireless Transmitter Section
4. Wireless Receiver Section
5. DB9 Connector
6. RS-232 Cable

HARDWARE DETAILS
1. Robot: The robot used for the project has two D.C. motors driven
using L293D (motor driver IC). The data to the motor driver is
provided by the microcontroller.

Figure 1: ROBOT

2. ATMega32 Microcontroller and Programmer:


LCD PORT

USB PORT

BUZZER

RESET

ISP

MCU

POWER LED

PWM LED

1 Microcontroller
The Mini Board is designed for AVR Atmega32.

LDR

DC JACK

2 Power Supply
The supply voltage to the AVR microcontroller is provided either
through DC Jack or USB. It is connected to the AVR's VCC pin.

2.1 DC Jack
Connect external power supply to this jack.

2.2 USB
Connect USB connector to this Port.

2.3 Power LED


LED will glow when Power in On.

3 Reset Button
Press this button to reset the Mini Board.
Reset Button is connected on Pin no. 9 (RESET)

4 LDR
LDR (Light Dependent Resistor) is
connected to microcontroller for
applications that are dependent on
intensity of external light source.
LDR is connected on Pin no. PA1

5 ISP
In-System Programming uses the AVR internal SPI (Serial Peripheral
Interface) to download code into the flash and EEPROM memory of
the AVR. ISP programming requires only VCC, GND, RESET and 3
signal lines for programming.
The AVR can be programmed at the normal operating
voltage, normally 2.7V-6.0V. No high voltage signals
are required. The ISP programmer can program both
the internal flash and EEPROM. It also programs fuse
bits for selecting clock options, startup time and
internal Brown Out Detector (BOD) for the device.
During ISP programming the 6-wire cable must always be connected to
the header marked ISP (6PIN).
ISP port also acts power source. ISP is connected on Pin nos.
MOSI
PB5

MISO
PB6

SCK
PB7

RESET
RESET (9)

VCC
VCC

6 PWM LED
PWM LED is connected to microcontroller for
applications that require PWM application. LED is
used to check proper functioning of PWM
application. PWM LED is connected on Pin no
PD5

GND
GND

7 PORT A, B, C & D
These Ports are connected to microcontroller for interfacing I/O Pins of
Microcontroller.

PORT A
PORT B
Pin B0 (PB0) - Pin B3 (PB3)
Pin B0 (PB3) - Pin B3 (PB7)

PORT C
PORT D

3. Wireless Transmitter Section : The wireless transmitter section


consists of an RF-434 MHz transmitter along with the HT-12E
encoder which performs the dual function of providing an address
to the transmitter as well as converting parallel input data into the
serial output data. The transmitter section is mounted on the robot.

Figure : Transmitter Section

4. Wireless Receiver Section : The wireless receiver section


consists of an RF-434 MHz receiver along with the HT-12D
decoder which performs the function of analyzing the address of
the data sender and converting the serial input data into parallel
output data. The receiver section is connected to the
microcontroller communicating with the computer.

Figure : Receiver Section

DB9 Connector : The DB9 (originally DE-9) connector is an analog 9pin plug of the D-Subminiature connector family (D-Sub or Sub-D). The
DB9 connector is mainly used for serial connections, allowing for the
asynchronous transmission of data as provided for by standard RS-232
(RS-232C).

Figure : DB9 Connector

Pins
Pin number Name
1

CD - Carrier Detect

RXD - Receive Data

TXD - Transmit Data

DTR - Data Terminal Ready

GND - Signal Ground

DSR - Data Set Ready

RTS - Request To Send

CTS - Clear To Send

RI - Ring Indicator
Shield

SOFTWARES USED
1. AVR Studio 4: For programming the microcontrollers to control
the robot and to communicate with the computer through USART.
2. MATLAB: For creating the map of path traced by using the data
provided b the microcontroller.
Hence, sufficient knowledge is required for programming the
microcontroller for USART communication and for using the serial data
on MATLAB to generate the map.

Programming the USART in ATMega32


It is necessary to get the desired output at a desired rate so that an
accurate map is generated on the computer. Hence, the microcontroller
USART should be programmed for required data rate. This is done by
initializing the bits of the USART baud rate register for the desired baud
rate. Besides, setting the baud rate, it is also necessary to set the frame
format. There are USART control registers and one USART baud rate
register.
1. USART Control and Status Register A (UCSRA)

2. USART Control and Status Register B (UCSRB)

3. USART Control and Status Register C (UCSRC)

4. USART Baud Rate Register

5. USART I/O Data Register

Basics of Serial Port Programming in MATLAB


The MATLAB serial port interface provides direct access to peripheral
devices such as modems, printers, and scientific instruments that you
connect to your computer's serial port. This interface is established
through a serial port object. The serial port object supports functions and
properties that allow us to

Configure serial port communications


Use serial port control pins
Write and read data
Use events and callbacks

Record information to disk

Supported Serial Port Interface Standards:


Over the years, several serial port interface standards have been
developed. These standards include RS-232, RS-422, and RS-485 - all of
which are supported by the MATLAB serial port object. Of these, the
most widely used interface standard for connecting computers to
peripheral devices is RS-232.
The original serial port interface standard was given by RS-232, which
stands for Recommended Standard number 232. The term RS-232 is still
in popular use, and is used in this guide when referring to a serial
communication port that follows the TIA/EIA-232 standard. RS-232
defines these serial port characteristics:

The maximum bit transfer rate and cable length


The names, electrical characteristics, and functions of signals
The mechanical connections and pin assignments

Primary communication is accomplished using three pins: the Transmit


Data pin, the Receive Data pin, and the Ground pin. Other pins are
available for data flow control, but are not required.

Connecting Two Devices with a Serial Cable


The RS-232 standard defines the two devices connected with a serial
cable as the Data Terminal Equipment (DTE) and Data CircuitTerminating Equipment (DCE). This terminology reflects the RS-232
origin as a standard for communication between a computer terminal
and a modem.
Throughout this guide, your computer is considered a DTE, while
peripheral devices such as modems and printers are considered DCEs.
Many scientific instruments function as DTEs.

Because RS-232 mainly involves connecting a DTE to a DCE, the pin


assignments are defined such that straight-through cabling is used,
where pin 1 is connected to pin 1, pin 2 is connected to pin 2, and so on.
The following diagram shows a DTE to DCE serial connection using the
transmit data (TD) pin and the receive data (RD) pin.

If you connect two DTEs or two DCEs using a straight serial cable, the
TD pins on each device are connected to each other, and the RD pins on
each device are connected to each other. Therefore, to connect two like
devices, you must use a null modem cable. As shown in the following
diagram, null modem cables cross the transmitting and receiving lines in
the cable.

Serial Port Signals and Pin Assignments


Serial ports consist of two signal types: data signals and control signals.
To support these signal types, as well as the signal ground, the RS-232
standard defines a 25-pin connection. However, most Windows and

UNIX platforms use a 9-pin connection. In fact, only three pins are
required for serial port communications: one for receiving data, one for
transmitting data, and one for the signal ground.
The following diagram shows the pin assignment scheme for a 9-pin
male connector on a DTE.

The pins and signals associated with the 9-pin connector are described in
the following table. Refer to the RS-232 standard for a description of the
signals and pin assignments used for a 25-pin connector.
Serial Port Pin and Signal Assignments
Pin Label Signal Name

Signal Type

CD

Carrier Detect

Control

RD

Received Data

Data

TD

Transmitted Data

Data

DTR Data Terminal Ready Control

GND Signal Ground

Ground

DSR Data Set Ready

Control

RTS

Request to Send

Control

CTS

Clear to Send

Control

RI

Ring Indicator

Control

The Data Pins


Most serial port devices support full-duplex communication meaning
that they can send and receive data at the same time. Therefore, separate

pins are used for transmitting and receiving data. For these devices, the
TD, RD, and GND pins are used. However, some types of serial port
devices support only one-way or half-duplex communications. For these
devices, only the TD and GND pins are used. This guide assumes that a
full-duplex serial port is connected to your device.
The TD pin carries data transmitted by a DTE to a DCE. The RD pin
carries data that is received by a DTE from a DCE.
The Control Pins
The control pins of a 9-pin serial port are used to determine the presence
of connected devices and control the flow of data. The control pins
include

The RTS and CTS Pins


The DTR and DSR Pins
The CD and RI Pins

The RTS and CTS Pins. The RTS and CTS pins are used to signal
whether the devices are ready to send or receive data. This type of data
flow controlcalled hardware handshakingis used to prevent data
loss during transmission. When enabled for both the DTE and DCE,
hardware handshaking using RTS and CTS follows these steps:
1. The DTE asserts the RTS pin to instruct the DCE that it is ready to
receive data.
2. The DCE asserts the CTS pin indicating that it is clear to send data
over the TD pin. If data can no longer be sent, the CTS pin is
unasserted.
3. The data is transmitted to the DTE over the TD pin. If data can no
longer be accepted, the RTS pin is unasserted by the DTE and the
data transmission is stopped.

The DTR and DSR Pins. Many devices use the DSR and DTR pins to
signal if they are connected and powered. Signaling the presence of
connected devices using DTR and DSR follows these steps:
1. The DTE asserts the DTR pin to request that the DCE connect to
the communication line.
2. The DCE asserts the DSR pin to indicate it is connected.
3. DCE unasserts the DSR pin when it is disconnected from the
communication line.
The DTR and DSR pins were originally designed to provide an
alternative method of hardware handshaking. However, the RTS and
CTS pins are usually used in this way, and not the DSR and DTR pins.
Refer to your device documentation to determine its specific pin
behavior.
The CD and RI Pins. The CD and RI pins are typically used to
indicate the presence of certain signals during modem-modem
connections.
A modem uses a CD pin to signal that it has made a connection with
another modem, or has detected a carrier tone. CD is asserted when the
DCE is receiving a signal of a suitable frequency. CD is unasserted if the
DCE is not receiving a suitable signal.
The RI pin is used to indicate the presence of an audible ringing signal.
RI is asserted when the DCE is receiving a ringing signal. RI is
unasserted when the DCE is not receiving a ringing signal (e.g., it is
between rings).

Serial Data Format


The serial data format includes one start bit, between five and eight data
bits, and one stop bit. A parity bit and an additional stop bit might be
included in the format as well. The following diagram illustrates the
serial data format.

The following notation expresses the format for serial port data:
number of data bits - parity type - number of stop bits
For example, 8-N-1 is interpreted as eight data bits, no parity bit, and
one stop bit, while 7-E-2 is interpreted as seven data bits, even parity,
and two stop bits.
The data bits are often referred to as a character because these bits
usually represent an ASCII character. The remaining bits are called
framing bits because they frame the data bits.

The Serial Port Session


This example describes the steps you use to perform any serial port task
from beginning to end.
The serial port session comprises all the steps you are likely to take
when communicating with a device connected to a serial port. These
steps are:
1. Create a serial port object Create a serial port object for a
specific serial port using the serial creation function.
Configure properties during object creation if necessary. In
particular, you might want to configure properties associated with
serial port communications such as the baud rate, the number of
data bits, and so on.

2. Connect to the device Connect the serial port object to the


device using the fopen function.
After the object is connected, alter the necessary device settings by
configuring property values, read data, and write data.
3. Configure properties To establish the desired serial port object
behavior, assign values to properties using the set function or dot
notation.
In practice, you can configure many of the properties at any time
including during, or just after, object creation. Conversely,
depending on your device settings and the requirements of your
serial port application, you might be able to accept the default
property values and skip this step.
4. Write and read data Write data to the device using the fprintf or
fwrite function, and read data from the device using the fgetl, fgets,
fread, fscanf, or readasync function.
The serial port object behaves according to the previously
configured or default property values.
5. Disconnect and clean up When you no longer need the serial
port object, disconnect it from the device using the fclose function,
remove it from memory using the delete function, and remove it
from the MATLAB workspace using the clear command.

Displaying Property Names and Property Values


After we create the serial port object, use the set function to display all
the configurable properties to the command line. Additionally, if a
property has a finite set of string values, set also displays these values.
s = serial('COM1');
set(s)

ByteOrder: [ {littleEndian} | bigEndian ]


BytesAvailableFcn
BytesAvailableFcnCount
BytesAvailableFcnMode: [ {terminator} | byte ]
ErrorFcn
InputBufferSize
Name
OutputBufferSize
OutputEmptyFcn
RecordDetail: [ {compact} | verbose ]
RecordMode: [ {overwrite} | append | index ]
RecordName
Tag
Timeout
TimerFcn
TimerPeriod
UserData

SERIAL specific properties:


BaudRate
BreakInterruptFcn
DataBits
DataTerminalReady: [ {on} | off ]
FlowControl: [ {none} | hardware | software ]
Parity: [ {none} | odd | even | mark | space ]
PinStatusFcn
Port
ReadAsyncMode: [ {continuous} | manual ]
RequestToSend: [ {on} | off ]
StopBits
Terminator

Use the get function to display one or more properties and their current
values to the command line. To display all properties and their current
values:
get(s)
ByteOrder = littleEndian
BytesAvailable = 0
BytesAvailableFcn =
BytesAvailableFcnCount = 48
BytesAvailableFcnMode = terminator
BytesToOutput = 0
ErrorFcn =
InputBufferSize = 512
Name = Serial-COM1
OutputBufferSize = 512
OutputEmptyFcn =
RecordDetail = compact
RecordMode = overwrite
RecordName = record.txt
RecordStatus = off
Status = closed
Tag =
Timeout = 10
TimerFcn =
TimerPeriod = 1
TransferStatus = idle
Type = serial
UserData = []
ValuesReceived = 0
ValuesSent = 0
SERIAL specific properties:
BaudRate = 9600
BreakInterruptFcn =
DataBits = 8

DataTerminalReady = on
FlowControl = none
Parity = none
PinStatus = [1x1 struct]
PinStatusFcn =
Port = COM1
ReadAsyncMode = continuous
RequestToSend = on
StopBits = 1
Terminator = LF
To display the current value for one property, supply the property name
to get.
get(s,'OutputBufferSize')
ans =
512
To display the current values for multiple properties, include the
property names as elements of a cell array.
get(s,{'Parity','TransferStatus'})
ans =
'none' 'idle'
Configuring Property Values
We can configure property values using the set function:
set(s,'BaudRate',4800);
or the dot notation:
s.BaudRate = 4800;

To configure values for multiple properties, supply multiple property


name/property value pairs to set.
set(s,'DataBits',7,'Name','Test1-serial')
In practice, we can configure many of the properties at any time while
the serial port object exists including during object creation.
However, some properties are not configurable while the object is
connected to the device or when recording information to disk. For
information about when a property is configurable, see Property
Reference.

Reading data :

The Input Buffer and Data Flow describes the flow of data from
the device to MATLAB software.
Reading Text Data describes how to read from the device, and
format the data as text.
Reading Binary Data describes how to read binary (numerical)
data from the device.

The following table shows the functions associated with reading data.
Functions Associated with Reading Data
Function
Name

Description

fgetl

Read one line of text from the device and discard the
terminator

fgets

Read one line of text from the device and include the
terminator

fread

Read binary data from the device

fscanf

Read data from the device and format as text

Function
Name

Description

readasync

Read data asynchronously from the device

stopasync

Stop asynchronous read and write operations

The following table shows the properties associated with reading data.
Properties Associated with Reading Data
Property Name Description
BytesAvailable

Number of bytes available in the input buffer

InputBufferSize Size of the input buffer in bytes


ReadAsyncMode Specify whether an asynchronous read operation is
continuous or manual
Timeout

Waiting time to complete a read or write operation

TransferStatus

Indicate if an asynchronous read or write operation is


in progress

ValuesReceived Total number of values read from the device

PROGRAMS :
1. Sample program for the microcontroller connected to the
robot: This program is written in Embedded C. The
microcontroller generates 4-bit values to control the D.C. motors.
1001 -> Forward movement
0101 -> Left turn
1010 -> Right turn
0110 -> Reverse gear
The microcontroller also sends the data about the movement of the
robot through the wireless transmitter section.
#define F_CPU 4000000UL
#include<avr/io.h>
#include<util/delay.h>
int main(void)
{
unsigned int count=1;
DDRC=0xFF;
DDRD=0xFF;
PORTC=0x09;
PORTD=0x01;
while(1)
{

if(count%4==1)
{
PORTC=0x09;
PORTD=0x01;
}
else if(count%4==2)
{
PORTC=0x05;
PORTD=0x02;
_delay_ms(255);
PORTC=0x09;
}
else if(count%4==3)
{
PORTC=0x0A;
PORTD=0x03;
_delay_ms(255);
PORTC=0x09;
}
else if(count%4==0)
{
PORTC=0x06;
PORTD=0x04;

}
_delay_ms(255);
_delay_ms(255);
_delay_ms(255);
_delay_ms(255);
if(count==160)
count=1;
else
count++;
}
}

2. Sample program for the microcontroller connected to the


computer: This program involves receiving the data from the
wireless receiver section and forwarding the interpreted data to the
computer via USART. The USART is first initialized by setting
the baud rate and the frame format. Then the data is sent
continuously to the computer.
#define F_CPU 4000000UL
#include <avr/io.h>

void USART_init(unsigned int b)


{
UBRRH=(unsigned char)(b>>8);
UBRRL=(unsigned char)b;

UCSRA=(1<<UDRE);
UCSRB=(1<<TXEN);
UCSRC=(1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ
0);
}

void USART_Transmit(unsigned char data)


{
while(!(UCSRA & (1<<UDRE)))
;
UDR=data;
}

int main(void)
{
DDRA=0x00;
unsigned char data;
unsigned int baud=25,count1=0,count2=0,count3=0,count4=0;
USART_init(baud);
while(1)
{
PINA=PORTA;
if((PINA & 0x0F)==0x01)

{
count2=0;
count3=0;
count4=0;
if(count1==0)
{
data=0x09;
count1++;
}
else if (count1==1)
{
data=0x19;
}
USART_Transmit(data);
}
else if((PINA & 0x0F)==0x02)
{
count1=0;
count3=0;
count4=0;
if(count2==0)
{
data=0x05;

count2++;
}
else if (count2==1)
{
data=0x15;
}
USART_Transmit(data);
}
else if((PINA & 0x0F)==0x03)
{
count1=0;
count2=0;
count4=0;
if(count3==0)
{
data=0x0A;
count3++;
}
else if (count3==1)
{
data=0x1A;
}
USART_Transmit(data);

}
else if((PINA & 0x0F)==0x04)
{
count1=0;
count2=0;
count3=0;
if(count4==0)
{
data=0x06;
count4++;
}
else if (count4==1)
{
data=0x16;
}
USART_Transmit(data);
}
}
}

3. Sample program for generating a map of the path traversed


by the robot on MATLAB: This sample program records a
particular number of moves, in this case a, and, finally, produces

a map of all the moves. The program gets its input data from a
serial port device (COM8) connected to the computer. However,
before executing the program it should be made sure that the frame
format of the data sent by the microcontroller should match the
frame format which is expected by the receiver.

Program:
function h=testmapserial(a)
m=ones(8*a);
s=serial('COM8');
set(s,'FlowControl','hardware','StopBits',2);
i=4*a+1;
j=4*a+1;
prev=1;
fopen(s);
for p=1:1:a
out=fread(s,1,'uint8');
if(out==9)
x=1;
elseif(out==5)
x=2;
elseif(out==10)
x=3;
elseif(out==6)
x=4;
end
if (x==1)
if (prev==1)
for y=1:1:4
m(i-y,j)=0;
end
i=i-4;
elseif (prev==2)
for y=1:1:4

m(i,j+y)=0;
end
j=j+4;
elseif (prev==3)
for y=1:1:4
m(i,j-y)=0;
end
j=j-4;
elseif (prev==4)
for y=1:1:4
m(i+y,j)=0;
end
i=i+4;
end
elseif (x==2)
if (prev==3)
for y=1:1:4
m(i-y,j)=0;
end
i=i-4;
prev=1;
elseif (prev==1)
for y=1:1:4
m(i,j+y)=0;
end
j=j+4;
prev=2;
elseif (prev==4)
for y=1:1:4
m(i,j-y)=0;
end
j=j-4;
prev=3;
elseif (prev==2)
for y=1:1:4

m(i+y,j)=0;
end
i=i+4;
prev=4;
end
elseif (x==3)
if (prev==2)
for y=1:1:4
m(i-y,j)=0;
end
i=i-4;
prev=1;
elseif (prev==4)
for y=1:1:4
m(i,j+y)=0;
end
j=j+4;
prev=2;
elseif (prev==1)
for y=1:1:4
m(i,j-y)=0;
end
j=j-4;
prev=3;
elseif (prev==3)
for y=1:1:4
m(i+y,j)=0;
end
i=i+4;
prev=4;
end
elseif (x==4)
if (prev==4)
for y=1:1:4
m(i-y,j)=0;

end
i=i-4;
elseif (prev==3)
for y=1:1:4
m(i,j+y)=0;
end
j=j+4;
elseif (prev==2)
for y=1:1:4
m(i,j-y)=0;
end
j=j-4;
elseif (prev==1)
for y=1:1:4
m(i+y,j)=0;
end
i=i+4;
end
end
h=imshow(m)
end
i
j
fclose(s);
delete(s);
clear s;
end

You might also like