Path Tracing System for an Autonomous Robot

Embed Size (px)

Citation preview

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    1/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 themicrocontroller will enhance the accuracy of the path tracing

    system as more information is available regarding the

    movements.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    2/35

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    3/35

    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) withrespect to the initial position which is, by default, the centre of

    the matrix.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    4/35

    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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    5/35

    2.

    ATMega32 Microcontroller and Programmer:

    1 MicrocontrollerThe Mini Board is designed for AVR Atmega32.

    LCD PORT BUZZER MCU POWER LED LDR

    USB PORT RESET ISP PWM LED DC JACK

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    6/35

    2 Power Supply

    The supply voltage to the AVR microcontroller is provided eitherthrough 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) isconnected to microcontroller forapplications that are dependent onintensity of external light source.

    LDR is connected on Pin no. PA1

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    7/35

    5 ISP

    In-System Programming uses the AVR internal SPI (Serial PeripheralInterface) to download code into the flash and EEPROM memory of

    the AVR. ISP programming requires only VCC, GND, RESET and 3signal lines for programming.

    The AVR can be programmed at the normal operatingvoltage, normally 2.7V-6.0V. No high voltage signalsare required. The ISP programmer can program boththe 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 tothe header marked ISP (6PIN).

    ISP port also acts power source. ISP is connected on Pin nos.

    MOSI MISO SCK RESET VCC GND

    PB5 PB6 PB7 RESET (9) VCC GND

    6 PWM LED

    PWM LED is connected to microcontroller forapplications that require PWM application. LED isused to check proper functioning of PWMapplication. PWM LED is connected on Pin no

    PD5

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    8/35

    7 PORT A, B, C & DThese Ports are connected to microcontroller for interfacing I/O Pins ofMicrocontroller.

    PORT APORT BPin B0 (PB0) - Pin B3 (PB3)

    Pin B0 (PB3) - Pin B3 (PB7)

    PORT C

    PORT D

    3.Wireless Transmitter Section : Thewireless 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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    9/35

    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 paralleloutput data. The receiver section is connected to the

    microcontroller communicating with the computer.

    Figure : Receiver Section

    DB9 Connector : The DB9(originallyDE-9) connector is an analog 9-pin 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).

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    10/35

    Figure : DB9 Connector

    Pins

    Pin number Name

    1 CD - Carrier Detect

    2 RXD - Receive Data

    3 TXD - Transmit Data

    4 DTR - Data Terminal Ready

    5 GND - Signal Ground

    6 DSR - Data Set Ready

    7 RTS - Request To Send

    8 CTS - Clear To Send

    9 RI - Ring Indicator

    Shield

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    11/35

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    12/35

    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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    13/35

    Record information to disk

    Supported Serial Port Interface Standards:

    Over the years, several serial port interface standards have beendeveloped. 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 toperipheral devices is RS-232.

    The original serial port interface standard was given by RS-232, which

    stands for Recommended Standard number 232. The termRS-232is 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-232defines 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 Circuit-

    Terminating 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.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    14/35

    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 modemcable. 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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    15/35

    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-pinmale 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

    1 CD Carrier Detect Control

    2 RD Received Data Data

    3 TD Transmitted Data Data

    4 DTR Data Terminal Ready Control

    5 GND Signal Ground Ground

    6 DSR Data Set Ready Control

    7 RTS Request to Send Control

    8 CTS Clear to Send Control

    9 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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    16/35

    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-duplexcommunications. 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 nolonger be accepted, the RTS pin is unasserted by the DTE and thedata transmission is stopped.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    17/35

    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 tothe 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 thecommunication 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 pinbehavior.

    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 theDCE 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 theserial data format.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    18/35

    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 bitsusually represent an ASCII character. The remaining bits are called

    framing bitsbecause 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 theserialcreation 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.

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    19/35

    2.Connect to the device Connect the serial port object to thedevice using thefopenfunction.

    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 dotnotation.

    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 defaultproperty values and skip this step.

    4.Write and read dataWrite data to the device using the fprintfor

    fwritefunction, and read data from the device using thefgetl,fgets,

    fread,fscanf,orreadasyncfunction.

    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 thefclosefunction,

    remove it from memory using the delete function, and remove itfrom the MATLAB workspace using theclearcommand.

    Displaying Property Names and Property Values

    After we create the serial port object, use the set function to display allthe 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)

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    20/35

    ByteOrder: [ {littleEndian} | bigEndian ]

    BytesAvailableFcn

    BytesAvailableFcnCount

    BytesAvailableFcnMode: [ {terminator} | byte ]

    ErrorFcnInputBufferSize

    Name

    OutputBufferSize

    OutputEmptyFcn

    RecordDetail: [ {compact} | verbose ]

    RecordMode: [ {overwrite} | append | index ]

    RecordName

    TagTimeout

    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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    21/35

    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 = 512Name = 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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    22/35

    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;

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    23/35

    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 whilethe 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 Flowdescribes 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

    terminatorfgets 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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    24/35

    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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    25/35

    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

    #include

    int main(void)

    {

    unsigned int count=1;

    DDRC=0xFF;

    DDRD=0xFF;

    PORTC=0x09;

    PORTD=0x01;

    while(1)

    {

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    26/35

    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;

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    27/35

    }

    _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

    void USART_init(unsigned int b)

    {

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

    UBRRL=(unsigned char)b;

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    28/35

    UCSRA=(1

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    29/35

    {

    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;

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    30/35

    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);

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    31/35

    }

    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

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    32/35

    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 theframe format which is expected by the receiver.

    Program:

    functionh=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);

    forp=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)

    fory=1:1:4

    m(i-y,j)=0;

    end

    i=i-4;

    elseif(prev==2)

    fory=1:1:4

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    33/35

    m(i,j+y)=0;

    end

    j=j+4;

    elseif(prev==3)

    fory=1:1:4m(i,j-y)=0;

    end

    j=j-4;

    elseif(prev==4)

    fory=1:1:4

    m(i+y,j)=0;

    end

    i=i+4;end

    elseif(x==2)

    if(prev==3)

    fory=1:1:4

    m(i-y,j)=0;

    end

    i=i-4;

    prev=1;

    elseif(prev==1)

    fory=1:1:4

    m(i,j+y)=0;

    end

    j=j+4;

    prev=2;

    elseif(prev==4)

    fory=1:1:4

    m(i,j-y)=0;end

    j=j-4;

    prev=3;

    elseif(prev==2)

    fory=1:1:4

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    34/35

    m(i+y,j)=0;

    end

    i=i+4;

    prev=4;

    endelseif(x==3)

    if(prev==2)

    fory=1:1:4

    m(i-y,j)=0;

    end

    i=i-4;

    prev=1;

    elseif(prev==4)fory=1:1:4

    m(i,j+y)=0;

    end

    j=j+4;

    prev=2;

    elseif(prev==1)

    fory=1:1:4

    m(i,j-y)=0;

    end

    j=j-4;

    prev=3;

    elseif(prev==3)

    fory=1:1:4

    m(i+y,j)=0;

    end

    i=i+4;

    prev=4;end

    elseif(x==4)

    if(prev==4)

    fory=1:1:4

    m(i-y,j)=0;

  • 8/10/2019 Path Tracing System for an Autonomous Robot

    35/35

    end

    i=i-4;

    elseif(prev==3)

    fory=1:1:4

    m(i,j+y)=0;end

    j=j+4;

    elseif(prev==2)

    fory=1:1:4

    m(i,j-y)=0;

    end

    j=j-4;

    elseif(prev==1)fory=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