SlideShare una empresa de Scribd logo
1 de 26
202CDE
    Coventry University
    Assignment 1




                                         GROUP BTP


            Divay Khatri                           -               4073084
            Aleksandr Fedunov                      -               3238989
            Cagdas Degirmenci                      -               3052983


[EMBEDDED MICROPROCESSOR GROUP PROJECT]
To design a robotic vehicle using a PIC18F4520 microcontroller board, stepper motors, Darlington driver,
photo reflective optical sensors and a proximity sensor such that it can follow a black line over a white
surface and can perform a 180 degree turn sensing an obstacle from 15 cms away.
Index
                 Contents                 Page No.

Introduction                                          3–4

Design Process     - Hardware Design               5–7
                   - Software Design             8 – 11

Implementation                                   12 – 16
                   -   The Code                  17 – 20

Components used                                          21

Test Methodology                                 22 – 24

Conclusion                                               25

References                                               26




                                                     Page | 2
Introduction:
To be useful in real world, robots need to move safely in unstructured environments and achieve
their given goals despite unexpected changes in their surroundings. The environments of real robots
are rarely predictable or perfectly unknown so it does not make sense to make precise plans before
moving.

The robot is left on a path and it approximates/ follows its path with the help of line following
sensors called photo reflective optical sensors and avoids obstacles with the help of distance
measuring sensor called the opto proximity sensor.

This task is to use a PIC18F4520 microcontroller board to control a robotic vehicle consisting of two
stepper motors that control the locomotion aspect of the vehicle via a Darlington driver, two photo
reflective optical sensors for a line following task and a single opto proximity sensor for obstacle
avoidance tasks. We are given a robotic vehicle which we have to program such that it follows a
black line that is placed or drawn on a white background. Also it should perform a 180 turn
following the track in the opposite direction when it reaches at an approximate distance of 15 cm
from any obstacle.

We were given three weeks to complete this project both from the hardware and software aspects.
During the first week, we set up the hardware using the stepper motors and the photo reflective
optical sensors and studied the movement of the stepper motor and noted down the pattern of the
same.

The second week, we attached the opto proximity sensors to the hardware using ADC at PORTA of
the PIC microcontroller board, assigned the hexadecimal values of 15cms away from the obstacle to
the code and tested it along with the previous week’s code. When it worked fine, then we shifted
the hardware over the robotic vehicle. Connected the stepper motors accordingly and it worked
fine. Now only the 180 turn was left to implement.

For the week three, our objective was to make the robot turn 180 if it reaches at an approximate
distance of 15 cms from the obstacle. But because someone took away our robotic vehicle also the
PC we used to sit on was occupied by someone else so we could not even access the code that we
wrote and then setting up the hardware again took most of the time and we could not complete it.
So we went to work on this in our free time and completed the task.



Objectives that we were trying to achieve and were successfully completed:

                Stepper motor 1 should rotate in anti-clockwise direction
                Stepper motor 2 should rotate in clockwise direction at the same time as motor 1
                Photo reflective optical sensors should be able to sense the black line and white line
                separately
                According to the optical sensors response, stepper motors should make changes to
                their movements.



                                                                                             Page | 3
Opto proximity sensor should be able to sense the obstacle from approximately
                15cms apart
                To perform 180 turn when an obstacle approaches.



The image below is an overview of what exactly needs to happen. The robotic vehicle should move
along with the black line and as it gets out of it, the vehicle should stop one of its motor and move
the other accordingly so as to keep the vehicle in control and within the black line. This diagram is
not accurate but roughly gives an idea about the concept.




We made two videos of our robotic vehicle which can be found on the links
below:




   1. http://youtu.be/1OGTFqqK8hc


   2. http://youtu.be/nTTH_TFyoAw



                                                                                            Page | 4
Design Process
Hardware Design:
Below is the figure that shows the set-up of the hardware, all the components together (including
the PIC development board, sensors and the motors)




                                                                                         Page | 5
To understand more about this let us have a look at the UML activity diagram for the hardware
design.


          UML activity diagram for Hardware Design




                                                                                     Page | 6
From previous classes we figured out that for a full step sequence in a clockwise direction, the values
for the steps should be:
                                 STEP 1             0x09
                                 STEP 2             0x05
                                 STEP 3             0x06
                                 STEP 4             0x0A

And thus for the full step sequence in an anticlockwise direction, the values for the steps should be
reversed:
                                 STEP 1             0x0A
                                 STEP 2             0x06
                                 STEP 3             0x05
                                 STEP 4             0x09

This sequence applies only for one stepper motor but if we have to make two stepper motors move
simultaneously then the stepping sequence will be:

    1. Make both the motors move in clockwise direction:

                                 STEP 1             0x99
                                 STEP 2             0x55
                                 STEP 3             0x66
                                 STEP 4             0xAA

    2. Make both the motors move in anti-clockwise direction:


                                 STEP 1             0xAA
                                 STEP 2             0x66
                                 STEP 3             0x55
                                 STEP 4             0x99


    3. Make one motor in anti-clockwise direction and the other in clockwise direction


                                 STEP 1             0xA9
                                 STEP 2             0x65
                                 STEP 3             0x56
                                 STEP 4             0x9A

This was the general idea of how to make the motors move. In our Project we have connected 4-7
bits of PORTD with Motor 1 and 0-3 bits of PORTD with Motor 2. Now let us have a look at the
software design.


                                                                                              Page | 7
Software Design:
   After making the connections according to the circuit as shown above, MPLAB was launched and a
   new project was created so as to program the PIC18f4520 through the ICD 3. We started
   programming the PIC in C language.

   1.
           a. First we configured the operational parameters of the PIC by setting OSC mode to HS
              high speed clock.
           b. Then the watchdog timer was set to OFF.
           c. Low Voltage Programming was also set to OFF.
           d. And a state to compile without extra Debug compile code was set.

   2. Header files (Include files) were included in the program
         a. #include <p18f4520.h>                    -      device used is the PICF4520
         b. #include <delays.h>                      -      to include the delay routines
         c. #include <adc.h>                         -      to include the files used in the analogue to
                                                            digital conversion
         d. #include <stdio.h>                       -      this describes the interface to the library
                                                            which contains basic I/O functions

   3. The stepping sequence was figured out in the previous classes and according to that stepping
      sequence where the stepper motors did a clockwise and anti-clockwise turn; the steps were
      assigned hexadecimal values.



           We know that

                                   0x00                          For the 0-3 bits of the PORT

Used to represent hexadecimal
values
                                                 For the 4-7 bits of the PORT



   Thus to make a robotic vehicle move in the forward direction, we need to make one motor move in
   anti-clockwise direction (i.e. Motor 1) and the other motor in clockwise direction (i.e. Motor 2) and
   we have to make changes in the directions of both the motors according to the response from the
   photo reflective optical sensors and the proximity sensors. For that we have assigned appropriate
   hexadecimal values to the steps and they are:




                                                                                               Page | 8
STEP 1                         0xA9
                    STEP 2                         0x65
                    STEP 3                         0x56
                    STEP 4                         0x9A
                    STEP 5                         0xA0
                    STEP 6                         0x60
                    STEP 7                         0x50
                    STEP 8                         0x90
                    STEP 9                         0x09
                    STEP 10                        0x05
                    STEP 11                        0x06
                    STEP 12                        0x0A


4. Then we initialized all the bits (0-7) of PORTD for outputs and all the bits of PORTC and PORTA
   for inputs. Also included a while loop (with while = 1) such that the code can run forever.

5. Then we included the code for the Analogue and Digital conversion and transferred that
   converted digital value to output.

6. Now starts the main logic to control the locomotion aspect of the vehicle using 1 proximity
   sensor and two photo reflective optical sensors.

       a. First we check that whether the value from the proximity sensor which is now in output.
          If it is not within 340 and 390 decimal values then it will sense the photo reflective
          optical sensors (defined as LED1 and LED2 in the program). According to their values we
          have given some steps in sequence with appropriate delay. Four combinations arise and
          they are:
                 i. When LED1 == 1 && LED2 == 1
                ii. When LED1 == 1 && LED2 == 0
               iii. When LED2 == 1 && LED1 == 0
               iv. When LED1 == 0 && LED2 == 0




       b. But if this is not the case, as in if the value from the photo reflective optical sensor is
          within the range of 340 and 390 (15 cm or less) then it will go to the else part of the
          program where we have given repeated commands with a condition for a 180 degree
          turn. This 24 number was calculated from the step angle given in the stepper motor
          documents.



                                                                                            Page | 9
Step angle (given) = 7.5 degree




           Thus,




           And this comes out to be 24.

           This was a way to do but this was not much efficient so found another way and that was
           to take the robot out of its way and then keep rotating it by making one motor stop and
           the other rotate until both the LED’s (photo reflective sensors) get the sense 1.

7. Step 5 and step 6 were repeated as we used a while loop to make the code run forever.




All these steps are presented through a UML activity diagram, please see
below.




                                                                                           Page | 10
UML Activity Diagram for Software Design




                                           Page | 11
Implementation of the Design

Implementation of the design wasn’t as challenging as we expected and this is due to all the
exercises we have carried out since the start of the module. Because we have been introduced a
new component weekly; setting up the connection and understanding how the circuit worked was
quiet easy. When we came across a problem; such as unresponsive equipment, it did not take us
long to figure out what the problem was because we were familiar with the equipment.

Having these advantages we quickly setup the circuit. We have explained below how we setup the
circuit step by step and the explained further the reason of these connections.




                                        D
                                                          C1
                G                   A   B     B C1      D 12V
                                                C2
            D

                     A                                         C2
                                                           D 12V
                      F                       D
                            F
                                E




                                                           E




Above is our initial connection of the circuit which later on we slightly modified, such as using the
Darlington Connector instead of the PIC Port.




                                                                                           Page | 12
About the hardware set up:

  a) Firstly we connected the PIC I/O board and the PIC development board with a 10-pin ribbon
     cable. This connection was made from the PIC I/O board to Port D on the development
     board. Using this connection we were able to cross-over 8-bit of information.

  b) Then with an 8-way connected wire, we have connected I/O board with the
     microcontroller’s input.

  c) The output of the microcontroller is then connected to the stepper motors. 0-3 bits to one
     of the stepper motor and 4-7 bits into the other stepper motor.

  d) After completing the main connections, we moved on and to power supply connections
     where 5V were connected to most of the boards and 12V was only connected to the stepper
     motors.

  e) We then connected the optical sensors to the sensor board which was already powered by
     5V.

  f)   We have connected the sensor board to Port C on the PIC board.

  g) Finally with an RJ11 cable, we connected the PIC board to MBLAB ICD3 (programmer and
     debugger) device.




                                                                                     Page | 13
Power Supply                                     Power Supply

         +5 V              0V                               0V              +12 V




                                                                   Distance Sensor
                                                                   To be placed in
                                                                     front of the
                                                                        vehicle




                                            Port E        Port A
                                                                       RJ11 connector to
                                                                         MBLAB ICD 3
                                                PIC 18


                       Port C                 Port D         Port B



                                              Darlington
                                                                          Stepper
                                              Connector                 Motor on the
                                                                          robotic
                                                                          vehicle
Sensor Interface
    Board                                                                 Stepper
                                                                        Motor on the
                                                                          robotic
                                                                          vehicle
                                                                                     Page | 14

             Optical Sensors to be placed
             under the vehicle
Implementation (further explained)

While connecting the circuit we did encounter simple problems. They are seen simple because we
easily found solutions to it. For example when we were planning on how to move the robotic vehicle
and how to keep it going constantly, we come across logical difficulties. At first we didn’t know how
the keep the vehicle on the black tape when the tape was curved to a different direction. Then we
talked and confirmed on mutual decisions which is explained further down in the report.

The simple circuit shown above is the complete version which we used on our robotic vehicle. As
seen above the so called ‘brain` of this circuit is the PIC18f4520 and it has been programmed with a
C language code which we have wrote and it works according to our preferences.

Firstly we have connected the Darlington board with the Port D on the PIC. The port D on the PIC is
an output interface and we use this output to control the stepper motors. The pins 0-3 are
programmed to use the Sensor 2 (mentioned LED 2 in the program) and the pins 4-7 are for Sensor 1
(mentioned LED1). The pins 9 and 10 are for ground connections. A 5V power supply was connected
to the PIC Board.

The other end of the Darlington driver is used to connect the Stepping motors on the robotic vehicle.
The wires coming out windings of the stepping motors had to be individually connected on the
Darlington board. At first we connected the wires incorrectly and we got to know this as the
components were behaving strange but then after carefully checking them we were able to put
them in correctly. The Darlington driver was powered with 12Volts.

The stepping motors surely needed power to run so we also connected the two with 12Volts
through +Vmotor connection.

The next connection we made was connecting the two Optical sensors to the PIC board. We
configured our program in such way that each sensor was assigned to a stepping motor. In simplicity
each sensor acted as an eye for the motor it was assigned to. We did this connection by using the
help of a Sensor Interface board.




                                                 The output cable from the sensors are connected
                                                 through the connections shown as ‘Connector S1’
                                                 and ‘Connector S2`. The Vcc and the 0V are for the
                                                 power connections and the sensor output
                                                 connections 1 and 2 are directed to Port C.




          Figure 1i – Panos Abatis



                                                                                           Page | 15
The Sensor output 1 and 2 are connected to the Port C (as they were the input senses for the
program) on the PIC Board and these inputs are configured in the program so the motors act on
these values. There are only two output values on these connections which are 0 or 1. 1 while no
light reflected (on black tape) and 0 when light is received (white area). The Sensor board is also
powered by a 5V supply which also supplies the sensors.

We have connected another sensor; Opto proximity sensor (distance sensor), in order to make the
robotic vehicle do a 180° turn as shown on the criteria. We have mounted the Sensor in the front of
the circuit so when the vehicle reaches an approximate distance of 15 cm to an object, it will stop
and do a turn.

We have connected




In the Picture above the blue circled is the distance sensor mounted at the front of the robotic
vehicle. The output of the sensor is maximum 5 volts depending on the object reflecting the
Infrared. As the sensor approaches the object while on the vehicle, the voltage output changes.
Because this is an analogue output, we modified the program in such way that certain voltage range
will make the vehicle move, stop or turn around.

The output of this sensor was connected to Port A on the PIC board which is also configured as an
input and this input was an analogue voltage signal.

After completion of the component connection, we connected all the equipment with the necessary
power supplies and placed them on top of the robot. Then we plugged in the RJ11 in to the PIC
board and programmed it using a MBLAB ICD3 programmer.




                                                                                         Page | 16
We then wrote the following program and uploaded it to the PIC microcontroller through the ICD3



//*****************************************************************************************
/* Assignment 1      -        Group BTP                                  */
/* Group Members: Divay Khatri, Aleksandr Fedunov, Cagdas Degirmenci     */

//*****************************************************************************************


#pragma config OSC = HS                 // set osc mode to HS high speed clock
#pragma config WDT = OFF                // set watchdog timer off
#pragma config LVP = OFF                // Low voltage Programming off
#pragma config DEBUG = OFF              // compile without extra debug compile code

#include <p18f4520.h>                   // device used is the PICF4520
#include <delays.h>                     // Include the delays routines
#include <adc.h>                        // include the ADC
#include <stdio.h>

// defining the line following sensors; LED1 = right side; LED2 = left side
#define LED1 PORTCbits.RC0                // compliment bit C0 of port C (change from logic 0 to 1 and vice versa
#define LED2 PORTCbits.RC1

// when led 1 and led 2 = 1
unsigned char STEP1 = 0xA9;             // Assign hex value A9 to step 1
unsigned char STEP2 = 0x65;             // Assign hex value 65 to step 2
unsigned char STEP3 = 0x56;             // Assign hex value 56 to step 3
unsigned char STEP4 = 0x9A;             // Assign hex value 9A to step 4

// when led 1 = 0 and led 2 = 1
unsigned char STEP5 = 0xA0;             // Assign hex value A0 to step 5
unsigned char STEP6 = 0x60;             // Assign hex value 60 to step 6
unsigned char STEP7 = 0x50;             // Assign hex value 50 to step 7
unsigned char STEP8 = 0x90;             // Assign hex value 90 to step 8

// when led 1 = 1 and led 2 = 0
unsigned char STEP9 = 0x09;             // Assign hex value 09 to step 9
unsigned char STEP10 = 0x05;            // Assign hex value 05 to step 10
unsigned char STEP11 = 0x06;            // Assign hex value 06 to step 11
unsigned char STEP12 = 0x0A;            // Assign hex value 0A to step 12

int output = 0;

void main (void)

  {
      LATD = 0x00;                      // Initialise Port D
      TRISD = 0x00;                     // 0x00 for output
      TRISC = 0xFF;                     // 0xFF for input
      TRISA = 0xFF;                     // 0xFF for input

                                                                                                  Page | 17
while(1)                                   // runs forever

  {
         // to convert analogue signal to digital, i.e. ADC (analogue to digital conversion)

            OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF &
ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011);

                 SetChanADC(ADC_CH0);        /* Selects the pin used as i/p to the */
                 Delay10TCYx(20);    /* delay for 200 instruction cycles */
                 ConvertADC( );              /* start A/D conversion */


                 while(BusyADC( ));        /* wait for completion */

                 output = ReadADC();               /* reads the converted digital value

                 // main logic

      if(output <= 340 || output >= 390)
      {


             if(LED1 == 1 && LED2 == 1)
         {

                 LATD = STEP1;                     // Send first step value to Port D
                          Delay10KTCYx(12);                // short delay

                           LATD = STEP2;
                     Delay10KTCYx(12);

                          LATD = STEP3;
                           Delay10KTCYx(12);

                 LATD = STEP4;
                  Delay10KTCYx(12);

                 }

                 else if(LED2 == 1 && LED1 == 0)

                 {


                           LATD = STEP5;
                     Delay10KTCYx(12);

                 LATD = STEP6;
                  Delay10KTCYx(12);

                 LATD = STEP7;
                  Delay10KTCYx(12);

                 LATD = STEP8;
                  Delay10KTCYx(12);
                                                                                               Page | 18
                 }
else if (LED1 == 1 && LED2 == 0)
                 {

                LATD = STEP9;
                 Delay10KTCYx(12);

                LATD = STEP10;
                 Delay10KTCYx(12);

                LATD = STEP11;
                 Delay10KTCYx(12);

                LATD = STEP12;
                  Delay10KTCYx(12)
                }
                else if (LED2 == 0 && LED1 == 0)
                {

         while(LED1 != 1 && LED2 != 1) // keep moving one wheel till both the line following sensors are not on
black line
                                 {
                         LATD = STEP5;
                  Delay10KTCYx(12);

                LATD = STEP6;
                 Delay10KTCYx(12);

                LATD = STEP7;
                 Delay10KTCYx(12);

                LATD = STEP8;
                 Delay10KTCYx(12);

                }
}

        }

else
                    if(output > 340 && output < 390)
                {


                          LATD = STEP5;
                    Delay10KTCYx(12);

                LATD = STEP6;
                 Delay10KTCYx(12);

                LATD = STEP7;
                 Delay10KTCYx(12);




                                                                                                Page | 19
LATD = STEP8;
                Delay10KTCYx(12);

                         LATD = STEP5;
                   Delay10KTCYx(12);

               LATD = STEP6;
                Delay10KTCYx(12);

               LATD = STEP7;
                Delay10KTCYx(12);

               LATD = STEP8;
                Delay10KTCYx(12);


while(LED1 != 1 && LED2 != 1)

               {

                         LATD = STEP5;
                   Delay10KTCYx(12);

               LATD = STEP6;
                Delay10KTCYx(12);

               LATD = STEP7;
                Delay10KTCYx(12);

               LATD = STEP8;
                 Delay10KTCYx(12);
               }

       }

}

}




                                         Page | 20
Project Components
The components we used are given below along with their pricing and from where to buy.



   Component                Cost                                   Link
      Name
   1 Proximity              £9.33          http://www.rapidonline.com/Electronic-
     Sensor                                Components/Distance-measuring-sensor-digital-
                                           output-81725/?sid=90f23f20-646b-4706-a66a-
                                           17487f1d1fc5



  1 PIC18f4520              £4.72          http://www.rapidonline.com/Electronic-
 microcontroller                           Components/PIC18Fwxyz-Enhanced-Flash-
                                           microcontroller-64435/?sid=2fbad005-5de5-4e06-
                                           b030-abb943273caf

     2 Photo          2x £4.30 = £8.60     http://uk.mouser.com/search/ProductDetail.aspx?qs=i
Reflective Optical                         blIa22dKKR%2F8%2FPojtStag%3D%3D&cm_mmc=findc
     Sensors                               hips-_-na-_-na-_-
                                           na&extra=index=4%7Cquery=OPB743%7Cqty=0

2 Stepper Motors      2x£8.35 = £16.70     http://www.rapidonline.com/Electrical-Power/2-
                                           Phase-Bipolar-Stepper-Motor-12v-37-
                                           0507/?sid=09feedbc-9699-47dc-9868-df23ccdca7f3

  Copper Wire               £2.83          http://www.rapidonline.com/Education/Gilt-copper-
                                           wire-83192/?sid=369bfaaf-db6a-464f-a38f-
                                           04f214c6ae63

Darlington Driver           £5.09           http://uk.farnell.com/allegro-microsystems/a6841sa-
                                               t/darlington-driver-serial-8bit-5841/dp/1202821

Microchip ICD 3           £124.88              http://uk.farnell.com/microchip/dv164035/kit-
                                                        evaluation-icd3/dp/1664878




In total by spending £172.15 + miscellaneous charges (power supply) we can build this
robotic vehicle and program it as well.




                                                                                         Page | 21
Test Methodology:
This design was not built at once. We did it in parts and noticed how the thing works and then
reversed it and then saw how it worked and we noted down the changes.

First we set the hardware with just one stepper motor and saw the movement.




And programmed PORTD 0-3 bits according to this pattern

                               STEP 1            0x09
                               STEP 2            0x05
                               STEP 3            0x06
                               STEP 4            0x0A

This made the stepper motor move in a full step sequence in a clockwise direction. And revering
these values made the stepper motor move in a full step sequence in an anti-clockwise direction.


                               STEP 1            0x0A
                               STEP 2            0x06
                               STEP 3            0x05
                               STEP 4            0x09

We understood that on reversing the code the movement of the stepper motor changed. Now we
attached another stepper motor to PORTD 4-7 bits and tried making both the motors move at the
same time. Since we knew the concept thus changed the values of steps to:



                                                                                      Page | 22
STEP 1             0xA9
                                 STEP 2             0x65
                                 STEP 3             0x56
                                 STEP 4             0x9A

We kept one value to be ‘9’ and other to be ‘A’ because when a car moves we know that the tires of
the car moves in the same direction but the motor which makes them move actually rotate in
opposite directions. The same concept we applied here and while making changes to the
hexadecimal values of the steps we kept in mind to make one motor rotate in clockwise direction
and the other in anti-clockwise direction.

When we completed the investigation of the stepper motors then we started dealing with the photo
reflective optical sensors and started testing them on the black line and on other surface as well and
found that when they were faced down on some other surface then get the light in the receiver and
thus completes the connection and returns a value of ZERO, but when placed faced down on a black
surface, the receiver receives no light and the connection doesn’t get complete and returns a value
ONE. So we were sure that when placed on a black surface the sensors return a value 1 and when on
other surface it returns a value 0. We then connected sensors to PORTC bits 0 and 1. We defined
right sensor of the vehicle as LED1 and the left one as LED2 on PORTC bit 0 and PORTC bit 1
respectively. Then we did the coding by using if-else conditional statements. Some part of the code
looks like:


if(LED1 == 1 && LED2 == 1)                          else if(LED2 == 1 && LED1 == 0)
        {                                             {

                LATD = STEP1;                                       LATD = STEP5;
                 Delay10KTCYx(12);                                   Delay10KTCYx(12);

                LATD = STEP2;                                       LATD = STEP6;
                 Delay10KTCYx(12);                                   Delay10KTCYx(12);

                LATD = STEP3;                                       LATD = STEP7;
                 Delay10KTCYx(12);                                   Delay10KTCYx(12);

                LATD = STEP4;                                       LATD = STEP8;
                 Delay10KTCYx(12);                                   Delay10KTCYx(12);

                }                                                   }




We compared both the LED1 and LED2 senses to assign them a pattern of stepping sequence. This
was just a bit of the whole code to give an idea how the conditions were made.




                                                                                            Page | 23
Then since we had to make the vehicle turn 180 when it sense an obstacle another condition was
given in the code. Proximity sensor senses the obstacle by checking the voltage. This analogue signal
(voltage) needs to be converted to digital signal to check it through the PIC microprocessor.

This was done by Analogue to Digital conversion code.

OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF &
ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011);

                SetChanADC(ADC_CH0);            /* Selects the pin used as i/p to the */
                Delay10TCYx(20);                /* delay for 200 instruction cycles */
                ConvertADC( );                  /* start A/D conversion */


                while(BusyADC( ));              /* wait for completion */

                output = ReadADC();


Now output contains the converted digital signal which we need to compare with our decimal values
for proximity sensor value of 15 cm or closer which is

Output should be greater than 340 and less than 390 to be considered for an obstacle and to make a
180 turn.

We got these values from the calculation:


   We know that 5 volts = 1024 decimal value. Using a programmer calculator we found out these
   values.

   Analogue voltage        Decimal Value           10-bit binary value              Hexadecimal value

   5 volts         -       1024             -      1111 1111 11             -       0x3FF

   2.5 volts       -       511              -      0111 1111 11             -       0x1FF

   1.9 volts       -       388              -      0110 0001 00             -       0x184



By clubbing the stepping sequence, the photo reflective optical sensors and the proximity sensor
code the main function of the .c file was written. We have already talked about the 180 turn but
once again see at that logic

This was the design process and the testing methodology including the UML activity diagrams for
Hardware and Software design for the robotic vehicle.




                                                                                            Page | 24
Conclusion:
The group assignment we carried out helped us have a wider view on electronics and its integration
with software. We got an idea of ‘The World of Logic and Circuits’ and understood how this
integration works. Now we feel that we stand a step closer to be an engineer and proved to
ourselves that this was the right choice for our professional life. This situation may seem
exaggerating but a ‘Big Success’ has many small steps in the way. This project also made us feel
more confident on practical basis, where we felt as if we were working with this equipment for a
long time.

Working as a group in this project contributed in our success, because we all were not familiar with
every aspect of the requirements. One of us was good with programming, one with the hardware
part as in the circuit part and one with both. Logical thinking is a very important aspect to build any
circuit that has no idea of what environment it is going to deal with, and this aspect was in all three
of us. We always thought a problem logically first, worked that logic out on paper and one of us
decided how we will work this in coding, the other decided how this will work with the hardware
and we started setting up the hardware and writing the code so as not to waste any time. By doing
this project together we ended up getting knowledge and information on the areas we were weak in
through sharing our ideas and thoughts with each other.

During the last three weeks where we carried out several tasks, we came across some problems. For
example at one point the sensor we were using was not working so we couldn’t get the car moving.
It took us a bit of time to find out it was the sensor which wasn’t working, as we had to individually
test every component and wire connections. Other than that we didn’t encounter any major
problems, and carried out the required tasks easily.

After we built the circuit and programmed the PIC we decided to test the robotic vehicle. It would’ve
been amazing if everything went perfect at first stage, but unfortunately this didn’t happen. We had
to modify a lot of little things like, the distance between the sensors and the surface, change the
coding as the vehicle was moving faster than it should and sometimes it got out of its track (black
tape). As mentioned before with a bit of modifying and adjustments these problems were overcome.

Finally when we finished the robotic vehicle and was satisfied with the design and the coding, we
thought we gave our best shot. So we placed a nice and straight black tape on the table with couple
of curves which leaded to a cardboard (acted as an object for the distance sensor). Then we placed
the robot and made it run and this time we were really satisfied as it smoothly went along the black
tape and did a 180° turn in the end. This made us feel good as all the hard work we put in, resulted
in our success.




                                                                                             Page | 25
References:
1
    http://web1.eng.coventry.ac.uk/Panos/Info/Experiments/Micros/202CDE/Opto%20Sensors.pdf



The ADC conversion code:

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/ADC%20Lab%20PIC18.pdf



ASCII Chart

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/ASCII%20Chart.JPG

For the configuration settings of the PIC

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Config%20settings%20PIC
18.pdf

For the delay functions used in the code

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Delay%20Library%20MCC
18.pdf

For the MCC18 C compiler

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Intro%20to%20the%20M
CC18%20C%20compiler.pdf

For the sensors

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Opto%20Sensors.pdf

For the stepper motors

http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Stepper%20Motor%20Exp
eriment%20PIC.pdf




                                                                                     Page | 26

Más contenido relacionado

La actualidad más candente

Line Following Robot
Line Following RobotLine Following Robot
Line Following RobotVikram Jha
 
Line follower Robot using PID algorithm
Line follower Robot using PID algorithmLine follower Robot using PID algorithm
Line follower Robot using PID algorithmIfaz Ahmed Aflan
 
Line Following Robot
Line Following RobotLine Following Robot
Line Following RobotSelf-employed
 
line following robot
line following robotline following robot
line following robotRehnaz Razvi
 
line following robot
line following robotline following robot
line following robotRehnaz Razvi
 
Line follower robot
Line follower robotLine follower robot
Line follower robotANU_110
 
Line follower robot 5th semster
Line follower robot 5th semsterLine follower robot 5th semster
Line follower robot 5th semsteraqeel shoukat
 
Line Following Robot Presentation
Line Following Robot PresentationLine Following Robot Presentation
Line Following Robot PresentationOli ullah
 
Obstacle avoiding Robot
Obstacle avoiding RobotObstacle avoiding Robot
Obstacle avoiding RobotRasheed Khan
 
MARK ROBOTIC ARM.ppt
MARK ROBOTIC ARM.pptMARK ROBOTIC ARM.ppt
MARK ROBOTIC ARM.pptAfstddrrdv
 
Line follower(theory + coding + videos)
Line follower(theory + coding + videos)Line follower(theory + coding + videos)
Line follower(theory + coding + videos)Yash Patel
 
Obstacle Avoidance Robot
Obstacle Avoidance RobotObstacle Avoidance Robot
Obstacle Avoidance RobotYash Sati
 
Industrial robotics pick & place
Industrial robotics pick & placeIndustrial robotics pick & place
Industrial robotics pick & placeRobotics Solutions
 

La actualidad más candente (20)

Line Following Robot
Line Following RobotLine Following Robot
Line Following Robot
 
Line follower Robot using PID algorithm
Line follower Robot using PID algorithmLine follower Robot using PID algorithm
Line follower Robot using PID algorithm
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
 
Line Following Robot
Line Following RobotLine Following Robot
Line Following Robot
 
line following robot
line following robotline following robot
line following robot
 
line following robot
line following robotline following robot
line following robot
 
Line Follower Robot
Line Follower RobotLine Follower Robot
Line Follower Robot
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
 
Path Following Robot
Path Following RobotPath Following Robot
Path Following Robot
 
Line follower robot 5th semster
Line follower robot 5th semsterLine follower robot 5th semster
Line follower robot 5th semster
 
Line Following Robot Presentation
Line Following Robot PresentationLine Following Robot Presentation
Line Following Robot Presentation
 
Obstacle avoiding Robot
Obstacle avoiding RobotObstacle avoiding Robot
Obstacle avoiding Robot
 
MARK ROBOTIC ARM.ppt
MARK ROBOTIC ARM.pptMARK ROBOTIC ARM.ppt
MARK ROBOTIC ARM.ppt
 
Robot arm ppt
Robot arm pptRobot arm ppt
Robot arm ppt
 
Line follower(theory + coding + videos)
Line follower(theory + coding + videos)Line follower(theory + coding + videos)
Line follower(theory + coding + videos)
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
 
Obstacle Avoidance Robot
Obstacle Avoidance RobotObstacle Avoidance Robot
Obstacle Avoidance Robot
 
Pid control for line follwoers
Pid control for line follwoersPid control for line follwoers
Pid control for line follwoers
 
Industrial robotics pick & place
Industrial robotics pick & placeIndustrial robotics pick & place
Industrial robotics pick & place
 

Destacado

Line Following Robot using Arduino UNO
Line Following Robot using Arduino UNOLine Following Robot using Arduino UNO
Line Following Robot using Arduino UNOViswanadh Ivaturi
 
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual)  vatsal shah-ec_4th yearFloor cleaning robot(autonomus mannual)  vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th yearVatsal N Shah
 
Floor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semFloor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semVatsal N Shah
 
Pick and place Line following robot report
Pick and place Line following robot reportPick and place Line following robot report
Pick and place Line following robot reportPradeep Yadav
 
Contoh Dapatan Kajian PBS PA
Contoh Dapatan Kajian PBS PAContoh Dapatan Kajian PBS PA
Contoh Dapatan Kajian PBS PAAthirah Amalina
 

Destacado (8)

Line Following Robot using Arduino UNO
Line Following Robot using Arduino UNOLine Following Robot using Arduino UNO
Line Following Robot using Arduino UNO
 
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual)  vatsal shah-ec_4th yearFloor cleaning robot(autonomus mannual)  vatsal shah-ec_4th year
Floor cleaning robot(autonomus mannual) vatsal shah-ec_4th year
 
Line Following Robot
Line Following RobotLine Following Robot
Line Following Robot
 
Floor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th semFloor cleaning robot report vatsal shah_ec_7th sem
Floor cleaning robot report vatsal shah_ec_7th sem
 
Pick and place Line following robot report
Pick and place Line following robot reportPick and place Line following robot report
Pick and place Line following robot report
 
Bab 4 analisis data
Bab 4 analisis dataBab 4 analisis data
Bab 4 analisis data
 
Contoh Dapatan Kajian PBS PA
Contoh Dapatan Kajian PBS PAContoh Dapatan Kajian PBS PA
Contoh Dapatan Kajian PBS PA
 
8 Tips for an Awesome Powerpoint Presentation
8 Tips for an Awesome Powerpoint Presentation8 Tips for an Awesome Powerpoint Presentation
8 Tips for an Awesome Powerpoint Presentation
 

Similar a Report - Line Following Robot

Robotics Report final.compressed (1)
Robotics Report final.compressed (1)Robotics Report final.compressed (1)
Robotics Report final.compressed (1)Kael Kristjanson
 
IRJET- Self Balancing Robot using Arduino Uno
IRJET-  	  Self Balancing Robot using Arduino UnoIRJET-  	  Self Balancing Robot using Arduino Uno
IRJET- Self Balancing Robot using Arduino UnoIRJET Journal
 
IRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous MonitoringIRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous MonitoringIRJET Journal
 
IRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET-  	  Amphibian Spy Robot for Continuous MonitoringIRJET-  	  Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous MonitoringIRJET Journal
 
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)Jayan Kant Duggal
 
IRJET- Design & Development of Two-Wheeled Self Balancing Robot
IRJET-  	  Design & Development of Two-Wheeled Self Balancing RobotIRJET-  	  Design & Development of Two-Wheeled Self Balancing Robot
IRJET- Design & Development of Two-Wheeled Self Balancing RobotIRJET Journal
 
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...Mohit Kumar
 
Final Presentation Slides.pptx
Final Presentation Slides.pptxFinal Presentation Slides.pptx
Final Presentation Slides.pptxAhmad Mujtaba
 
PC-based mobile robot navigation sytem
PC-based mobile robot navigation sytemPC-based mobile robot navigation sytem
PC-based mobile robot navigation sytemANKIT SURATI
 
Obstacle avoidance robot
Obstacle avoidance robotObstacle avoidance robot
Obstacle avoidance robotRahuldey1991
 
Lecture 1,2 of Motion Control Technologies.pptx
Lecture 1,2 of Motion Control Technologies.pptxLecture 1,2 of Motion Control Technologies.pptx
Lecture 1,2 of Motion Control Technologies.pptxAthar Baig
 
Design and Implementation of Rover for Mars Communication: Review and Idea
Design and Implementation of Rover for Mars Communication: Review and IdeaDesign and Implementation of Rover for Mars Communication: Review and Idea
Design and Implementation of Rover for Mars Communication: Review and IdeaIRJET Journal
 
project_NathanWendt
project_NathanWendtproject_NathanWendt
project_NathanWendtNathan Wendt
 
IRJET-Fuzzy Logic Based Path Navigation for Robot using Matlab
IRJET-Fuzzy Logic Based Path Navigation for Robot using MatlabIRJET-Fuzzy Logic Based Path Navigation for Robot using Matlab
IRJET-Fuzzy Logic Based Path Navigation for Robot using MatlabIRJET Journal
 

Similar a Report - Line Following Robot (20)

Robotics Report final.compressed (1)
Robotics Report final.compressed (1)Robotics Report final.compressed (1)
Robotics Report final.compressed (1)
 
IRJET- Self Balancing Robot using Arduino Uno
IRJET-  	  Self Balancing Robot using Arduino UnoIRJET-  	  Self Balancing Robot using Arduino Uno
IRJET- Self Balancing Robot using Arduino Uno
 
IRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous MonitoringIRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous Monitoring
 
IRJET- Amphibian Spy Robot for Continuous Monitoring
IRJET-  	  Amphibian Spy Robot for Continuous MonitoringIRJET-  	  Amphibian Spy Robot for Continuous Monitoring
IRJET- Amphibian Spy Robot for Continuous Monitoring
 
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)
ROBOTIC ARM WITH VOICE CONTROLLED AND IMAGE PROCESSING (1)
 
G017534144
G017534144G017534144
G017534144
 
IRJET- Design & Development of Two-Wheeled Self Balancing Robot
IRJET-  	  Design & Development of Two-Wheeled Self Balancing RobotIRJET-  	  Design & Development of Two-Wheeled Self Balancing Robot
IRJET- Design & Development of Two-Wheeled Self Balancing Robot
 
Embeded system
Embeded systemEmbeded system
Embeded system
 
Eye directive wheel chair
Eye directive wheel chairEye directive wheel chair
Eye directive wheel chair
 
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...
Deployable low cost outdoor system - NORTHERN INDIA ENGINEERING COLLEGE NEW D...
 
Final Presentation Slides.pptx
Final Presentation Slides.pptxFinal Presentation Slides.pptx
Final Presentation Slides.pptx
 
PC-based mobile robot navigation sytem
PC-based mobile robot navigation sytemPC-based mobile robot navigation sytem
PC-based mobile robot navigation sytem
 
Embeded system
Embeded systemEmbeded system
Embeded system
 
Obstacle avoidance robot
Obstacle avoidance robotObstacle avoidance robot
Obstacle avoidance robot
 
Resume
ResumeResume
Resume
 
Lecture 1,2 of Motion Control Technologies.pptx
Lecture 1,2 of Motion Control Technologies.pptxLecture 1,2 of Motion Control Technologies.pptx
Lecture 1,2 of Motion Control Technologies.pptx
 
Design and Implementation of Rover for Mars Communication: Review and Idea
Design and Implementation of Rover for Mars Communication: Review and IdeaDesign and Implementation of Rover for Mars Communication: Review and Idea
Design and Implementation of Rover for Mars Communication: Review and Idea
 
Obstacle avoiding robot(Lab report)
Obstacle  avoiding  robot(Lab report)Obstacle  avoiding  robot(Lab report)
Obstacle avoiding robot(Lab report)
 
project_NathanWendt
project_NathanWendtproject_NathanWendt
project_NathanWendt
 
IRJET-Fuzzy Logic Based Path Navigation for Robot using Matlab
IRJET-Fuzzy Logic Based Path Navigation for Robot using MatlabIRJET-Fuzzy Logic Based Path Navigation for Robot using Matlab
IRJET-Fuzzy Logic Based Path Navigation for Robot using Matlab
 

Report - Line Following Robot

  • 1. 202CDE Coventry University Assignment 1 GROUP BTP Divay Khatri - 4073084 Aleksandr Fedunov - 3238989 Cagdas Degirmenci - 3052983 [EMBEDDED MICROPROCESSOR GROUP PROJECT] To design a robotic vehicle using a PIC18F4520 microcontroller board, stepper motors, Darlington driver, photo reflective optical sensors and a proximity sensor such that it can follow a black line over a white surface and can perform a 180 degree turn sensing an obstacle from 15 cms away.
  • 2. Index Contents Page No. Introduction 3–4 Design Process - Hardware Design 5–7 - Software Design 8 – 11 Implementation 12 – 16 - The Code 17 – 20 Components used 21 Test Methodology 22 – 24 Conclusion 25 References 26 Page | 2
  • 3. Introduction: To be useful in real world, robots need to move safely in unstructured environments and achieve their given goals despite unexpected changes in their surroundings. The environments of real robots are rarely predictable or perfectly unknown so it does not make sense to make precise plans before moving. The robot is left on a path and it approximates/ follows its path with the help of line following sensors called photo reflective optical sensors and avoids obstacles with the help of distance measuring sensor called the opto proximity sensor. This task is to use a PIC18F4520 microcontroller board to control a robotic vehicle consisting of two stepper motors that control the locomotion aspect of the vehicle via a Darlington driver, two photo reflective optical sensors for a line following task and a single opto proximity sensor for obstacle avoidance tasks. We are given a robotic vehicle which we have to program such that it follows a black line that is placed or drawn on a white background. Also it should perform a 180 turn following the track in the opposite direction when it reaches at an approximate distance of 15 cm from any obstacle. We were given three weeks to complete this project both from the hardware and software aspects. During the first week, we set up the hardware using the stepper motors and the photo reflective optical sensors and studied the movement of the stepper motor and noted down the pattern of the same. The second week, we attached the opto proximity sensors to the hardware using ADC at PORTA of the PIC microcontroller board, assigned the hexadecimal values of 15cms away from the obstacle to the code and tested it along with the previous week’s code. When it worked fine, then we shifted the hardware over the robotic vehicle. Connected the stepper motors accordingly and it worked fine. Now only the 180 turn was left to implement. For the week three, our objective was to make the robot turn 180 if it reaches at an approximate distance of 15 cms from the obstacle. But because someone took away our robotic vehicle also the PC we used to sit on was occupied by someone else so we could not even access the code that we wrote and then setting up the hardware again took most of the time and we could not complete it. So we went to work on this in our free time and completed the task. Objectives that we were trying to achieve and were successfully completed: Stepper motor 1 should rotate in anti-clockwise direction Stepper motor 2 should rotate in clockwise direction at the same time as motor 1 Photo reflective optical sensors should be able to sense the black line and white line separately According to the optical sensors response, stepper motors should make changes to their movements. Page | 3
  • 4. Opto proximity sensor should be able to sense the obstacle from approximately 15cms apart To perform 180 turn when an obstacle approaches. The image below is an overview of what exactly needs to happen. The robotic vehicle should move along with the black line and as it gets out of it, the vehicle should stop one of its motor and move the other accordingly so as to keep the vehicle in control and within the black line. This diagram is not accurate but roughly gives an idea about the concept. We made two videos of our robotic vehicle which can be found on the links below: 1. http://youtu.be/1OGTFqqK8hc 2. http://youtu.be/nTTH_TFyoAw Page | 4
  • 5. Design Process Hardware Design: Below is the figure that shows the set-up of the hardware, all the components together (including the PIC development board, sensors and the motors) Page | 5
  • 6. To understand more about this let us have a look at the UML activity diagram for the hardware design. UML activity diagram for Hardware Design Page | 6
  • 7. From previous classes we figured out that for a full step sequence in a clockwise direction, the values for the steps should be: STEP 1 0x09 STEP 2 0x05 STEP 3 0x06 STEP 4 0x0A And thus for the full step sequence in an anticlockwise direction, the values for the steps should be reversed: STEP 1 0x0A STEP 2 0x06 STEP 3 0x05 STEP 4 0x09 This sequence applies only for one stepper motor but if we have to make two stepper motors move simultaneously then the stepping sequence will be: 1. Make both the motors move in clockwise direction: STEP 1 0x99 STEP 2 0x55 STEP 3 0x66 STEP 4 0xAA 2. Make both the motors move in anti-clockwise direction: STEP 1 0xAA STEP 2 0x66 STEP 3 0x55 STEP 4 0x99 3. Make one motor in anti-clockwise direction and the other in clockwise direction STEP 1 0xA9 STEP 2 0x65 STEP 3 0x56 STEP 4 0x9A This was the general idea of how to make the motors move. In our Project we have connected 4-7 bits of PORTD with Motor 1 and 0-3 bits of PORTD with Motor 2. Now let us have a look at the software design. Page | 7
  • 8. Software Design: After making the connections according to the circuit as shown above, MPLAB was launched and a new project was created so as to program the PIC18f4520 through the ICD 3. We started programming the PIC in C language. 1. a. First we configured the operational parameters of the PIC by setting OSC mode to HS high speed clock. b. Then the watchdog timer was set to OFF. c. Low Voltage Programming was also set to OFF. d. And a state to compile without extra Debug compile code was set. 2. Header files (Include files) were included in the program a. #include <p18f4520.h> - device used is the PICF4520 b. #include <delays.h> - to include the delay routines c. #include <adc.h> - to include the files used in the analogue to digital conversion d. #include <stdio.h> - this describes the interface to the library which contains basic I/O functions 3. The stepping sequence was figured out in the previous classes and according to that stepping sequence where the stepper motors did a clockwise and anti-clockwise turn; the steps were assigned hexadecimal values. We know that 0x00 For the 0-3 bits of the PORT Used to represent hexadecimal values For the 4-7 bits of the PORT Thus to make a robotic vehicle move in the forward direction, we need to make one motor move in anti-clockwise direction (i.e. Motor 1) and the other motor in clockwise direction (i.e. Motor 2) and we have to make changes in the directions of both the motors according to the response from the photo reflective optical sensors and the proximity sensors. For that we have assigned appropriate hexadecimal values to the steps and they are: Page | 8
  • 9. STEP 1 0xA9 STEP 2 0x65 STEP 3 0x56 STEP 4 0x9A STEP 5 0xA0 STEP 6 0x60 STEP 7 0x50 STEP 8 0x90 STEP 9 0x09 STEP 10 0x05 STEP 11 0x06 STEP 12 0x0A 4. Then we initialized all the bits (0-7) of PORTD for outputs and all the bits of PORTC and PORTA for inputs. Also included a while loop (with while = 1) such that the code can run forever. 5. Then we included the code for the Analogue and Digital conversion and transferred that converted digital value to output. 6. Now starts the main logic to control the locomotion aspect of the vehicle using 1 proximity sensor and two photo reflective optical sensors. a. First we check that whether the value from the proximity sensor which is now in output. If it is not within 340 and 390 decimal values then it will sense the photo reflective optical sensors (defined as LED1 and LED2 in the program). According to their values we have given some steps in sequence with appropriate delay. Four combinations arise and they are: i. When LED1 == 1 && LED2 == 1 ii. When LED1 == 1 && LED2 == 0 iii. When LED2 == 1 && LED1 == 0 iv. When LED1 == 0 && LED2 == 0 b. But if this is not the case, as in if the value from the photo reflective optical sensor is within the range of 340 and 390 (15 cm or less) then it will go to the else part of the program where we have given repeated commands with a condition for a 180 degree turn. This 24 number was calculated from the step angle given in the stepper motor documents. Page | 9
  • 10. Step angle (given) = 7.5 degree Thus, And this comes out to be 24. This was a way to do but this was not much efficient so found another way and that was to take the robot out of its way and then keep rotating it by making one motor stop and the other rotate until both the LED’s (photo reflective sensors) get the sense 1. 7. Step 5 and step 6 were repeated as we used a while loop to make the code run forever. All these steps are presented through a UML activity diagram, please see below. Page | 10
  • 11. UML Activity Diagram for Software Design Page | 11
  • 12. Implementation of the Design Implementation of the design wasn’t as challenging as we expected and this is due to all the exercises we have carried out since the start of the module. Because we have been introduced a new component weekly; setting up the connection and understanding how the circuit worked was quiet easy. When we came across a problem; such as unresponsive equipment, it did not take us long to figure out what the problem was because we were familiar with the equipment. Having these advantages we quickly setup the circuit. We have explained below how we setup the circuit step by step and the explained further the reason of these connections. D C1 G A B B C1 D 12V C2 D A C2 D 12V F D F E E Above is our initial connection of the circuit which later on we slightly modified, such as using the Darlington Connector instead of the PIC Port. Page | 12
  • 13. About the hardware set up: a) Firstly we connected the PIC I/O board and the PIC development board with a 10-pin ribbon cable. This connection was made from the PIC I/O board to Port D on the development board. Using this connection we were able to cross-over 8-bit of information. b) Then with an 8-way connected wire, we have connected I/O board with the microcontroller’s input. c) The output of the microcontroller is then connected to the stepper motors. 0-3 bits to one of the stepper motor and 4-7 bits into the other stepper motor. d) After completing the main connections, we moved on and to power supply connections where 5V were connected to most of the boards and 12V was only connected to the stepper motors. e) We then connected the optical sensors to the sensor board which was already powered by 5V. f) We have connected the sensor board to Port C on the PIC board. g) Finally with an RJ11 cable, we connected the PIC board to MBLAB ICD3 (programmer and debugger) device. Page | 13
  • 14. Power Supply Power Supply +5 V 0V 0V +12 V Distance Sensor To be placed in front of the vehicle Port E Port A RJ11 connector to MBLAB ICD 3 PIC 18 Port C Port D Port B Darlington Stepper Connector Motor on the robotic vehicle Sensor Interface Board Stepper Motor on the robotic vehicle Page | 14 Optical Sensors to be placed under the vehicle
  • 15. Implementation (further explained) While connecting the circuit we did encounter simple problems. They are seen simple because we easily found solutions to it. For example when we were planning on how to move the robotic vehicle and how to keep it going constantly, we come across logical difficulties. At first we didn’t know how the keep the vehicle on the black tape when the tape was curved to a different direction. Then we talked and confirmed on mutual decisions which is explained further down in the report. The simple circuit shown above is the complete version which we used on our robotic vehicle. As seen above the so called ‘brain` of this circuit is the PIC18f4520 and it has been programmed with a C language code which we have wrote and it works according to our preferences. Firstly we have connected the Darlington board with the Port D on the PIC. The port D on the PIC is an output interface and we use this output to control the stepper motors. The pins 0-3 are programmed to use the Sensor 2 (mentioned LED 2 in the program) and the pins 4-7 are for Sensor 1 (mentioned LED1). The pins 9 and 10 are for ground connections. A 5V power supply was connected to the PIC Board. The other end of the Darlington driver is used to connect the Stepping motors on the robotic vehicle. The wires coming out windings of the stepping motors had to be individually connected on the Darlington board. At first we connected the wires incorrectly and we got to know this as the components were behaving strange but then after carefully checking them we were able to put them in correctly. The Darlington driver was powered with 12Volts. The stepping motors surely needed power to run so we also connected the two with 12Volts through +Vmotor connection. The next connection we made was connecting the two Optical sensors to the PIC board. We configured our program in such way that each sensor was assigned to a stepping motor. In simplicity each sensor acted as an eye for the motor it was assigned to. We did this connection by using the help of a Sensor Interface board. The output cable from the sensors are connected through the connections shown as ‘Connector S1’ and ‘Connector S2`. The Vcc and the 0V are for the power connections and the sensor output connections 1 and 2 are directed to Port C. Figure 1i – Panos Abatis Page | 15
  • 16. The Sensor output 1 and 2 are connected to the Port C (as they were the input senses for the program) on the PIC Board and these inputs are configured in the program so the motors act on these values. There are only two output values on these connections which are 0 or 1. 1 while no light reflected (on black tape) and 0 when light is received (white area). The Sensor board is also powered by a 5V supply which also supplies the sensors. We have connected another sensor; Opto proximity sensor (distance sensor), in order to make the robotic vehicle do a 180° turn as shown on the criteria. We have mounted the Sensor in the front of the circuit so when the vehicle reaches an approximate distance of 15 cm to an object, it will stop and do a turn. We have connected In the Picture above the blue circled is the distance sensor mounted at the front of the robotic vehicle. The output of the sensor is maximum 5 volts depending on the object reflecting the Infrared. As the sensor approaches the object while on the vehicle, the voltage output changes. Because this is an analogue output, we modified the program in such way that certain voltage range will make the vehicle move, stop or turn around. The output of this sensor was connected to Port A on the PIC board which is also configured as an input and this input was an analogue voltage signal. After completion of the component connection, we connected all the equipment with the necessary power supplies and placed them on top of the robot. Then we plugged in the RJ11 in to the PIC board and programmed it using a MBLAB ICD3 programmer. Page | 16
  • 17. We then wrote the following program and uploaded it to the PIC microcontroller through the ICD3 //***************************************************************************************** /* Assignment 1 - Group BTP */ /* Group Members: Divay Khatri, Aleksandr Fedunov, Cagdas Degirmenci */ //***************************************************************************************** #pragma config OSC = HS // set osc mode to HS high speed clock #pragma config WDT = OFF // set watchdog timer off #pragma config LVP = OFF // Low voltage Programming off #pragma config DEBUG = OFF // compile without extra debug compile code #include <p18f4520.h> // device used is the PICF4520 #include <delays.h> // Include the delays routines #include <adc.h> // include the ADC #include <stdio.h> // defining the line following sensors; LED1 = right side; LED2 = left side #define LED1 PORTCbits.RC0 // compliment bit C0 of port C (change from logic 0 to 1 and vice versa #define LED2 PORTCbits.RC1 // when led 1 and led 2 = 1 unsigned char STEP1 = 0xA9; // Assign hex value A9 to step 1 unsigned char STEP2 = 0x65; // Assign hex value 65 to step 2 unsigned char STEP3 = 0x56; // Assign hex value 56 to step 3 unsigned char STEP4 = 0x9A; // Assign hex value 9A to step 4 // when led 1 = 0 and led 2 = 1 unsigned char STEP5 = 0xA0; // Assign hex value A0 to step 5 unsigned char STEP6 = 0x60; // Assign hex value 60 to step 6 unsigned char STEP7 = 0x50; // Assign hex value 50 to step 7 unsigned char STEP8 = 0x90; // Assign hex value 90 to step 8 // when led 1 = 1 and led 2 = 0 unsigned char STEP9 = 0x09; // Assign hex value 09 to step 9 unsigned char STEP10 = 0x05; // Assign hex value 05 to step 10 unsigned char STEP11 = 0x06; // Assign hex value 06 to step 11 unsigned char STEP12 = 0x0A; // Assign hex value 0A to step 12 int output = 0; void main (void) { LATD = 0x00; // Initialise Port D TRISD = 0x00; // 0x00 for output TRISC = 0xFF; // 0xFF for input TRISA = 0xFF; // 0xFF for input Page | 17
  • 18. while(1) // runs forever { // to convert analogue signal to digital, i.e. ADC (analogue to digital conversion) OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */ Delay10TCYx(20); /* delay for 200 instruction cycles */ ConvertADC( ); /* start A/D conversion */ while(BusyADC( )); /* wait for completion */ output = ReadADC(); /* reads the converted digital value // main logic if(output <= 340 || output >= 390) { if(LED1 == 1 && LED2 == 1) { LATD = STEP1; // Send first step value to Port D Delay10KTCYx(12); // short delay LATD = STEP2; Delay10KTCYx(12); LATD = STEP3; Delay10KTCYx(12); LATD = STEP4; Delay10KTCYx(12); } else if(LED2 == 1 && LED1 == 0) { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); Page | 18 }
  • 19. else if (LED1 == 1 && LED2 == 0) { LATD = STEP9; Delay10KTCYx(12); LATD = STEP10; Delay10KTCYx(12); LATD = STEP11; Delay10KTCYx(12); LATD = STEP12; Delay10KTCYx(12) } else if (LED2 == 0 && LED1 == 0) { while(LED1 != 1 && LED2 != 1) // keep moving one wheel till both the line following sensors are not on black line { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); } } } else if(output > 340 && output < 390) { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); Page | 19
  • 20. LATD = STEP8; Delay10KTCYx(12); LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); while(LED1 != 1 && LED2 != 1) { LATD = STEP5; Delay10KTCYx(12); LATD = STEP6; Delay10KTCYx(12); LATD = STEP7; Delay10KTCYx(12); LATD = STEP8; Delay10KTCYx(12); } } } } Page | 20
  • 21. Project Components The components we used are given below along with their pricing and from where to buy. Component Cost Link Name 1 Proximity £9.33 http://www.rapidonline.com/Electronic- Sensor Components/Distance-measuring-sensor-digital- output-81725/?sid=90f23f20-646b-4706-a66a- 17487f1d1fc5 1 PIC18f4520 £4.72 http://www.rapidonline.com/Electronic- microcontroller Components/PIC18Fwxyz-Enhanced-Flash- microcontroller-64435/?sid=2fbad005-5de5-4e06- b030-abb943273caf 2 Photo 2x £4.30 = £8.60 http://uk.mouser.com/search/ProductDetail.aspx?qs=i Reflective Optical blIa22dKKR%2F8%2FPojtStag%3D%3D&cm_mmc=findc Sensors hips-_-na-_-na-_- na&extra=index=4%7Cquery=OPB743%7Cqty=0 2 Stepper Motors 2x£8.35 = £16.70 http://www.rapidonline.com/Electrical-Power/2- Phase-Bipolar-Stepper-Motor-12v-37- 0507/?sid=09feedbc-9699-47dc-9868-df23ccdca7f3 Copper Wire £2.83 http://www.rapidonline.com/Education/Gilt-copper- wire-83192/?sid=369bfaaf-db6a-464f-a38f- 04f214c6ae63 Darlington Driver £5.09 http://uk.farnell.com/allegro-microsystems/a6841sa- t/darlington-driver-serial-8bit-5841/dp/1202821 Microchip ICD 3 £124.88 http://uk.farnell.com/microchip/dv164035/kit- evaluation-icd3/dp/1664878 In total by spending £172.15 + miscellaneous charges (power supply) we can build this robotic vehicle and program it as well. Page | 21
  • 22. Test Methodology: This design was not built at once. We did it in parts and noticed how the thing works and then reversed it and then saw how it worked and we noted down the changes. First we set the hardware with just one stepper motor and saw the movement. And programmed PORTD 0-3 bits according to this pattern STEP 1 0x09 STEP 2 0x05 STEP 3 0x06 STEP 4 0x0A This made the stepper motor move in a full step sequence in a clockwise direction. And revering these values made the stepper motor move in a full step sequence in an anti-clockwise direction. STEP 1 0x0A STEP 2 0x06 STEP 3 0x05 STEP 4 0x09 We understood that on reversing the code the movement of the stepper motor changed. Now we attached another stepper motor to PORTD 4-7 bits and tried making both the motors move at the same time. Since we knew the concept thus changed the values of steps to: Page | 22
  • 23. STEP 1 0xA9 STEP 2 0x65 STEP 3 0x56 STEP 4 0x9A We kept one value to be ‘9’ and other to be ‘A’ because when a car moves we know that the tires of the car moves in the same direction but the motor which makes them move actually rotate in opposite directions. The same concept we applied here and while making changes to the hexadecimal values of the steps we kept in mind to make one motor rotate in clockwise direction and the other in anti-clockwise direction. When we completed the investigation of the stepper motors then we started dealing with the photo reflective optical sensors and started testing them on the black line and on other surface as well and found that when they were faced down on some other surface then get the light in the receiver and thus completes the connection and returns a value of ZERO, but when placed faced down on a black surface, the receiver receives no light and the connection doesn’t get complete and returns a value ONE. So we were sure that when placed on a black surface the sensors return a value 1 and when on other surface it returns a value 0. We then connected sensors to PORTC bits 0 and 1. We defined right sensor of the vehicle as LED1 and the left one as LED2 on PORTC bit 0 and PORTC bit 1 respectively. Then we did the coding by using if-else conditional statements. Some part of the code looks like: if(LED1 == 1 && LED2 == 1) else if(LED2 == 1 && LED1 == 0) { { LATD = STEP1; LATD = STEP5; Delay10KTCYx(12); Delay10KTCYx(12); LATD = STEP2; LATD = STEP6; Delay10KTCYx(12); Delay10KTCYx(12); LATD = STEP3; LATD = STEP7; Delay10KTCYx(12); Delay10KTCYx(12); LATD = STEP4; LATD = STEP8; Delay10KTCYx(12); Delay10KTCYx(12); } } We compared both the LED1 and LED2 senses to assign them a pattern of stepping sequence. This was just a bit of the whole code to give an idea how the conditions were made. Page | 23
  • 24. Then since we had to make the vehicle turn 180 when it sense an obstacle another condition was given in the code. Proximity sensor senses the obstacle by checking the voltage. This analogue signal (voltage) needs to be converted to digital signal to check it through the PIC microprocessor. This was done by Analogue to Digital conversion code. OpenADC(ADC_FOSC_32 & ADC_LEFT_JUST & ADC_0_TAD,ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); /* Selects the pin used as i/p to the */ Delay10TCYx(20); /* delay for 200 instruction cycles */ ConvertADC( ); /* start A/D conversion */ while(BusyADC( )); /* wait for completion */ output = ReadADC(); Now output contains the converted digital signal which we need to compare with our decimal values for proximity sensor value of 15 cm or closer which is Output should be greater than 340 and less than 390 to be considered for an obstacle and to make a 180 turn. We got these values from the calculation: We know that 5 volts = 1024 decimal value. Using a programmer calculator we found out these values. Analogue voltage Decimal Value 10-bit binary value Hexadecimal value 5 volts - 1024 - 1111 1111 11 - 0x3FF 2.5 volts - 511 - 0111 1111 11 - 0x1FF 1.9 volts - 388 - 0110 0001 00 - 0x184 By clubbing the stepping sequence, the photo reflective optical sensors and the proximity sensor code the main function of the .c file was written. We have already talked about the 180 turn but once again see at that logic This was the design process and the testing methodology including the UML activity diagrams for Hardware and Software design for the robotic vehicle. Page | 24
  • 25. Conclusion: The group assignment we carried out helped us have a wider view on electronics and its integration with software. We got an idea of ‘The World of Logic and Circuits’ and understood how this integration works. Now we feel that we stand a step closer to be an engineer and proved to ourselves that this was the right choice for our professional life. This situation may seem exaggerating but a ‘Big Success’ has many small steps in the way. This project also made us feel more confident on practical basis, where we felt as if we were working with this equipment for a long time. Working as a group in this project contributed in our success, because we all were not familiar with every aspect of the requirements. One of us was good with programming, one with the hardware part as in the circuit part and one with both. Logical thinking is a very important aspect to build any circuit that has no idea of what environment it is going to deal with, and this aspect was in all three of us. We always thought a problem logically first, worked that logic out on paper and one of us decided how we will work this in coding, the other decided how this will work with the hardware and we started setting up the hardware and writing the code so as not to waste any time. By doing this project together we ended up getting knowledge and information on the areas we were weak in through sharing our ideas and thoughts with each other. During the last three weeks where we carried out several tasks, we came across some problems. For example at one point the sensor we were using was not working so we couldn’t get the car moving. It took us a bit of time to find out it was the sensor which wasn’t working, as we had to individually test every component and wire connections. Other than that we didn’t encounter any major problems, and carried out the required tasks easily. After we built the circuit and programmed the PIC we decided to test the robotic vehicle. It would’ve been amazing if everything went perfect at first stage, but unfortunately this didn’t happen. We had to modify a lot of little things like, the distance between the sensors and the surface, change the coding as the vehicle was moving faster than it should and sometimes it got out of its track (black tape). As mentioned before with a bit of modifying and adjustments these problems were overcome. Finally when we finished the robotic vehicle and was satisfied with the design and the coding, we thought we gave our best shot. So we placed a nice and straight black tape on the table with couple of curves which leaded to a cardboard (acted as an object for the distance sensor). Then we placed the robot and made it run and this time we were really satisfied as it smoothly went along the black tape and did a 180° turn in the end. This made us feel good as all the hard work we put in, resulted in our success. Page | 25
  • 26. References: 1 http://web1.eng.coventry.ac.uk/Panos/Info/Experiments/Micros/202CDE/Opto%20Sensors.pdf The ADC conversion code: http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/ADC%20Lab%20PIC18.pdf ASCII Chart http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/ASCII%20Chart.JPG For the configuration settings of the PIC http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Config%20settings%20PIC 18.pdf For the delay functions used in the code http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Delay%20Library%20MCC 18.pdf For the MCC18 C compiler http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Intro%20to%20the%20M CC18%20C%20compiler.pdf For the sensors http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Opto%20Sensors.pdf For the stepper motors http://web1.eng.coventry.ac.uk/panos/info/Experiments/Micros/202CDE/Stepper%20Motor%20Exp eriment%20PIC.pdf Page | 26