28
16-17 Birmingham City University Presented to Dr Tony Wilcox By Zeeshan Mustafa Latif Ansari (Id: s09466807) [DESIGN AND BUILD OF AN IET TRIATHLON ROBOT] The IET Robot-Triathlon Line Follower.

Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

16-17

Birmingham City University Presented to Dr Tony Wilcox By Zeeshan Mustafa Latif Ansari (Id: s09466807)

[DESIGN AND BUILD OF AN IET TRIATHLON ROBOT] The IET Robot-Triathlon Line Follower.

Page 2: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

1

Contents

Part 1: Design of a Sensor Array.…………………………………………………….…2

Introduction………………………………………………………………..………………2

Problem Statement……………………………………………………………………….2

Individual Sensor Selection…………………………………………………..………….4

Sensor Array Configuration…………………………………………………...…………7

Schematic and PCB design……………………………………………………………11

Part 2: Implementation of an embedded controller………………………...………13

Introduction………………………………………………………………………..……..13

Block diagram of system hardware…………………………………………….……..14

Algorithm for system software…………………………………………………………15

Hardware Construction…………………………………………………………………16

Software Implementation…………………………………………………………….…24

Conclusion………………………………………………………………………….……26

Reference………………………………………………………………………………..27

Page 3: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

2

Part 1: Design of a Sensor Array

Introduction

Line follower robot can be thought of one of the basic and most useful embedded

systems project for beginners as it makes one learn how to design and build a

fundamental Labrat robot. This report starts with the explanation of the problem

statement and physical requirements according to the contest rules to build a sensor

and microcontroller boards for a wheeled robot so that a fully functional robot can

participate in the IET Triathlon competition.

An individual sensor selection is made out of two sensors based on their different

parameters and characteristics. Most suitable and useful sensor is chosen so that it

can be implemented along with other components; especially the processor, being

used is 18F2520 - a 28 pin memory scalar of the PIC18F4520. Controller Board

circuit design is then chosen and built which is used to interface with the sensor

board especially the sensors as they send and receive information to and from the

microcontroller to operate the robot.

Report discusses different positions of the sensors and a best position is chosen in

order to get the best behaviour of the robot to follow the line and in case if the robot

is going off the track (line) and staying in best position on the line while moving as

fast as possible. Schematic is drawn and Printed Circuit Board is designed while

keeping in mind the track widths, hole sizes, layout considerations etc.

Problem Statement

The Purpose of the line follower robot is to acquire knowledge and develop skills to

design, build and implement a basic embedded system so that it can finally

participate in the IET Triathlon competition. The main purpose of the robot is to

follow the line as fast as possible around a circuit consisting of a white line on a

black baseboard for a smooth drive to the end of the track, the robot must stay on

line. Some of the practical applications include automated cars on road and

guidance robots for industries moving on shop floor etc.

For example when a 5 volts DC is applied to the LED the sensor catches the

reflection of the LED and sensor then sends the signal to the microcontroller which is

loaded with a program to start the motor and to further give robot speed, stability and

accuracy.

It a complete Electronic project investigating an engineering design problem relating

to electronic circuits and systems using theory, simulation, practical construction, use

of laboratory test equipment, ECAD packages and applications of device data

sheets, implementation of system concepts, testing and hardware debugging and

finally delivering information by written technical report an oral demonstration. Whole

Page 4: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

3

project actually relates to the real world problems’ solving of embedded systems.

Contest Rules

Institute of Engineering and Technology (IET) arrange regular competitions

especially this IET Triathlon competition for those interested in designing embedded

systems. However, to join this competition there is registration process and

mandatory contest rules and failing to comply with could result in participant being

disqualified. Competition is divided in three events given below:

1. Line Follower event.

2. Drag Race event.

3. Time Trials event.

The aim of Line follower has already been explained above. The drag race aims

robot to race as fast as possible with other robots over a straight course and finally

come to a standstill before reaching the end wall. The time trails aims robot to test

the speed, acceleration, cornering and directional control on a known course in

fastest possible time.

Scoring is given below; all events’ points will be totalled to decide the overall winner

with most points.

1st place: 10 points

2nd place: 7 points

3rd place: 5 points

4th place: 3 points

5th place: 2 points

Completion: 1 point

Summary of the physical requirements from the contest rules is given below:

1. Line follower must be self-contained, not externally operated.

2. With exception of battery pack and minor repairs, no addition, removal,

replacement or change to the hardware is allowed during the contest.

3. It must not exceed 25cm in length, 25cm in width and 20cm in height.

4. Only 5 attempts are allowed.

5. If performance time limit reaches, the lap time will be valid if line follower

successfully completes its run.

6. The line following robot’s batteries and program can be changed within the

given performance time.

Page 5: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

4

7. After crossing the finishing line the Line follower must automatically stop and

stay in stationary position for at least two seconds, failing which the lap will be

void.

8. When robot completely goes off the track it will invalidate the run.

9. No request to adjust the indoor lighting shall be entertained.

Individual Sensor Selection In this modern world Sensors are being used almost everywhere, most common type of sensors are light, heat, water, smoke, object, speed sensors etc. Number of sensors can be used for this Project but here, for line follower, a sensor is being chosen with consideration of environment lightening, sensitivity reaction and power use etc. A photo transistor emitter detector pair has been chosen based on their parameters and characteristic, most suitable for this project are given below. Comparison includes two sensors which are:

1. Photo transistor emitter detector pair 2. Photo diode emitter detector pair

Photo transistor emitter detector pair Applications of photo transistors include electric controls, computer logic circuitry, punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent on exposure of light for its operation. It detects light pulses and converts them to digital electric signals. It is operated by light rather than electric current. It can produce both current and voltage, their base terminal is exposed so instead of sending current into the base, the photon from light activates the transistor. Because phototransistor is made of bipolar semiconductor it focuses the energy that is passed through it.

Fig. 1. Taken from Phototransistors Related Keywords & Suggestions.

A photo transistor has a base and collector and is made using diffusion or ion implantation. It’s an ordinary bi-polar transistor, available in both the PNP and NPN

Page 6: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

5

types, in which the base (made of lead) is exposed to light which activates the transistor. The collector is the positive lead and the larger electrical supply. The emitter is the negative lead and the outlet for the larger electrical supply. A small amount of current flow can be observed in a photo transistor in the absence of light, this is because of the small number of carriers that are inserted into the emitter.

Fig. 2. Taken from Types of Photodetectors.

Photo transistor is 50 to 100 times more sensitive than the photodiode with a lower level of noise. These sensors are known for their economic value and characteristic of providing a high level gain from 100 to over 1500. It moderately has fast response time. Circuit diagram of a simple phototransistor is given below:

Fig. 3. Taken from How the Phototransistors Circuits Works.

Photo Diode emitter detector pair It is basically a diode, used in reverse bias and is only turned ON when the light intensity above the threshold strikes on it. Its gives only two outputs; either ON or OFF because of which it is only capable of differentiating between two different intensities of light. It can mostly be used where detecting a single light threshold is necessary such as making a Shadow Counter Circuit. Photo diodes are low cost, temperature sensitive, digital in nature and unidirectional.

Page 7: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

6

Fig. 4. Taken from GaAsp photodiode.

Fig. 5. Circuit Diagram of Photodiode. Taken from A real World Situation. Comparison Advantages and disadvantages of Phototransistor Advantages:

Can produce higher amount of current than photodiodes

Able to produce voltage.

Operate very well with different types of lights and colours.

Relatively small, simple and easy to use/connect.

Fast enough to produce nearly instantaneous output.

Can produce voltage, that photo-resistors cannot do so.

Makes less noise when compared with other devices

Page 8: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

7

Disadvantages:

Silicon made phototransistors are not capable of handling voltages over 1,000 volts

They are more vulnerable to surges and spikes of electricity as well as to electromagnetic energy.

Can easily get damaged when connected to an unstable circuit

Resist the flow of electrons while other devices don’t.

Do not have high level frequency response. Advantages and disadvantages of Photodiode Advantages:

Can be used as variable resistors.

More sensitive to light compared to phototransistors.

Relatively small, simple, and easy to use/connect.

Operate very fast in terms of switching of current and the resistance.

Economical to buy. Disadvantages:

Bad temperature stability due to it being temperature dependant.

Gives change of current in uA which could not be sufficient to drive other circuit so it makes amplification necessary

All the information above including the comparison has shown that both have advantages and disadvantages while phototransistor is better as it has more positive characteristics to be used for the line follower. The photodiode is known to be very fast in reaction which could be more suitable for the Time Trial event as the robot would need to be controlled at very high speed.

Sensor Array Configuration Sensor positioning is one of the most fundamental parts in building this line follower robot. If the sensors are not positioned properly they can cause a major problem in its operation even if the rest of the hardware is efficiently built and the software is perfectly programmed. Correct design of the robot, choosing most appropriate sensors and their accurate positioning plays significant parts towards the required operation of the line follower robot. Robot must have at least two sensors that should have capability of detecting white line on a black surface. They detects whether the line underneath them is shifting towards their left or right as they moves over them. How its operates is when the robot turn aside of the white line towards the left, the sensors sends signal to the microcontroller, which is programmed to increase or decrease the speed of motors, microcontroller then reduces the speed of the right motor to move it back towards

Page 9: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

8

right side so robot maintains its steady centre and vice versa in case if robot turn aside of the white line towards the right. This operation above also suggest that robot must have at least two sensors so both side swerving could be control and a steady centre could be maintained. As now there are two emitter detector pairs one on each side. Robot must operate as if it’s in centre position the speed of the motors will be increased making robot run fast and when it turns to one side the sensor should send signal to the microcontroller and microcontroller should decrease the motor speed of the other side to bring it back to steady central position and vice versa if robot turns to opposite side away from the line. Figure below helps to understand how the robot runs.

Fig. 6. Taken from LEGO robot: Line follower.

Lab Results Lab below gives great deal of information on the sensors and discusses that how to obtain an output that is proportional to how far the sensors are from the line. Further it analysis the type of error signal that can be obtained by subtracting the readings from two sensors separated by various distance which consequently helps to determine how far apart the sensors need to be for an optimum response. The procedure adopted for this task is by keep on widening the height and the x-axis to get the best position for the sensor, so two sides will be subtracted from each other because a-b gives a more convenient response. If the graph is on positive axis the robot must turn left because it indicates its position is too far right and vice versa if the graph is on the negative.

Page 10: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

9

Fig. 7. Captured from Excel. Graph above shows that the blue and red line is saturating and the top bit is clipping while its looks smoother at 30mm and 40mm.

Fig. 8. Captured from Excel. The above graph shows the shifting to the left side by 10mm spacing from peak to peak. It does not indicate in which side the robot is on because the dead zone is quite small so it cannot be said good enough as there are still errors occurring form the readings of the sensor.

0

50

100

150

200

250

300

-60 -40 -20 0 20 40 60

Sensitivity of the Area

Y = 10mm Y=20mm Y=30mm Y=40mm

Page 11: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

10

Fig. 9. Captured from Excel. In the graph above the x-axis are changed to 15mm spacing; its shows that the dead zone is not very big or very small and robot can also make corrections of the errors.

Fig. 10. Captured from Excel. Now the graph is redrawn with shifting by 20mm which seems quite right and most suitable for the sensor positioning as it can be seen that the dead zone is not too big or too small and it has range of corrections equal to zero. It also indicates the position of the robot either on right side or on left side which further makes corrections of the errors.

Page 12: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

11

It proves that now the robot will be able to follow the line accurately and it will be sensitive enough to bring the robot back to white line in case if it goes off the track. According to the experiment and its results the final position of the sensors is chosen 40mm peak to peak because its more accurate and efficient in helping robot stay on line in all cases e.g. when its takes turns or run fast. So the distance between the two pairs of the sensors will be 20mm. Two sensors are used to avoid instability as one sensor can easily make robot unstable and go off the track as discussed earlier. Sensors will be placed at the front of the chassis that’s the only most suitable place for line follower from where it will have more time to send signal to the microcontroller in case of deviation and in results to take action.

Schematic and PCB design Schematic

Fig. 11. Sensor board schematic design, screenshot taken from eagle. Schematic and PCB design was initiated after sensors selection and sensor array

configuration. The sensor board schematic was designed in Eagle software which is

used to design the schematics for the Printed Circuit Board (PCB) and then the

Page 13: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

12

schematic is converted into Board layout which can further be modified according to

the requirements.

Schematic shows three Phototransistors as T1, T2, T3, and three LEDs as LED1,

LED2, LED3, seven resistors as R1, R2, R3, R6, R7, R8, R9, one Mosfet, two

Capacitors as C1, C2 and a 14-pin IDC box header which allows a ribbon cable

connector to the controller board.

Emitter legs of T1, T2, and T3 were connected with three resistors each of 10kΩ

value which are R1, R6, and R2 respectively and then these resistors were grounded

on their alternative terminals. Cathode legs of the LED1, LED2, and LED3 were

connected with three resistors each of 180Ω value which R7, R9, and R3

respectively and these resistors were connected to drain of the mosfet from their

alternative terminals. 2N7000-E52 which is an N-channel enhancement-mode

MOSFET’s. It is being used as a low-power switch to provide moderate current to the

LEDs. C1 of 0.1uF is connected collector terminals of the phototransistors and C2 of

100uF value is connected with anode terminal of the LEDs, both capacitors are

grounded from negative sides. (FairChild semiconductors, November 1995)

PCB layout

Fig. 12. Sensor board PCB layout, screenshot taken from eagle.

Page 14: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

13

Schematic was then switched to PCB layout which is further modified and designed

as shown above. Dimensions of the board were chosen as 55mm by 60mm so that it

could easily fit on the robot chassis according to the physical requirements of the

robot. To mount the sensor board on the chassis distance between the holes was

chosen to be 30mm. According to the width of the white line which was 20mm the

distance between the left and right sensor was chosen as 28mm. Both sensors were

placed 4mm away from the white line on both sides for greater sensitivity. Height of

the sensors was decided as 20mm from the board which was approximately 1.5mm

above the black surface.

Width of the track was chosen as 0.8128mm, this was the most suitable width to

choose for the board of dimensions of 55 by 60mm with number of components

mentioned above. It would have been harder to solder components on tracks if the

track width was chosen less than 0.8128mm. And if it was chosen greater than

0.8128mm tracks would have been very close to each other which would have

resulted in short circuits and messy board. Hole size was chosen as 8.22mm. Blue

tracks are not crossing any other track. Two red tracks are crossing which were then

connected using two wire which were soldered on the opposite side of the sensor

board. Once this schematic and PCB layout design was finalised it was sent for

construction.

Part 2: Implementation of an embedded controller

Introduction This part of the report is concerned with hardware construction and test, then software design and implementation to create a robot capable of taking part in IET Robot Triathlon contest. As mentioned in the start of the report there are three events and this report is focused on Line follower. Firstly the controller board is built and tested using multi meters etc. Sensor board is made based on the schematic and PCB design which is then tested using the MPLAB IDE software. Controller Board circuit design is then chosen and built which is used to interface with the sensor board especially the sensors as they send and receive information to and from the microcontroller to operate the robot. Controller Board has a 14-pin IDC box header, J1, which allows a ribbon-cable connector to a sensor board. The processor used is 18F2520 - a 28 pin memory scalar of the PIC18F4520 supported by a non-volatile memory (RS232) and an on-board voltage regulator (LM2940 LDO). This parts further describes the overall operation of the robot software, gives

captured data demonstrating the operation of the robot i.e. PWM outputs for tracking,

readings and plots of line sensors. Also explains the method to successfully navigate

the robot.

Page 15: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

14

Block Diagram of system hardware

The block diagram above shows the key information needed for writing programs for the line follower system. It shows two circuits that are connected together which are the controller and sensor board. The controller board has a 14-pin IDC box header, J1, which allows a ribbon-cable connector to a sensor board. A 9V battery is connected to a voltage regulator and then it supplies voltage to microcontroller. An H-bridge motor driver consisting of left and right motors is also connected to the microcontroller. Microcontroller is also connected to “led user switch”, which controls the led, and to “reset switch” which resets it. ICD port is also connected with “reset switch” for connection to the PICKIT 2 device. On the sensor board side, microcontroller is connected with J1 which sends received signal to J2. J2 is connected with left, right and the side sensor. J2 is further connected to mosfet which is connected with Left and right led.

9V PSU HEADER

BOX

VOLTAGE

REGULATOR

H BRIDGE MOTOR

DRIVER

L293D

JP1 I/O VOLTAGE

MICROCONTROLLER

(18F2520)

LEFT

MOTOR

RIGHT

MOTOR

RESET

SWITCH

LED USER

SWITCH

LED &

SENSOR

PAIR 1

LED &

SENSOR

PAIR 2

SIDE

SENSOR J2 J1

RC1-RC2, RB5-RA6

RA5

0/P

VOLTAGE

RA0-RA4

RB0-RB3

RA7-RC0

ICD

PORT PICKIT 2

RB6-RB7

MOSFET

LEFT

LED

RIGHT

LED

Page 16: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

15

Algorithm for System Software

Start

Initialise/Read: Sensors, LED

driver, 8MHz, Int Clock,

Pushbutton, Motors, Duty, PWM.

Is Pushbutton

pressed?

No

Turn LED and Sensors ON

Set Duty = 10 on Motors

Set KP to 0.3 (Constant)

Reset

LDuty = LPWM + Error

Are the Sensors

reading?

Calculate

Error = (Rightline - Leftline) KP

Delay 1ms

Yes

Yes

No

Is Left

Sensor

reading

white line?

Is Left

Sensor

reading

white line? No

RDuty = RPWM - Error

Yes Yes

Delay 1ms

No

End

Page 17: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

16

Hardware Construction

Hardware construction started after thoroughly studying and understanding the

schematic of the Labrat Controller board which is given below. All the components

were individually soldered and tested side by side using a multimetre. Multimetre

helped find out exact values for the required resistors and any short circuits. Then

the controller board, Sensor board and H-bridge motors were tested by using

MPLAB IDE’s software with the help of five different tests explained below as Test

Plans.

Controller Board

The controller board schematic was already designed in Eagle software. After

thoroughly reading and understanding the controller board provided soldering

process was started. The main components that were soldered on this board are

Microcontroller PIC18F2520, Voltage regulator, motor driver IC L293D, IDC

connector, switch buttons, decoupling capacitors, resistors, LED etc.

The Microcontroller was connected with voltage regulator that was used to generate

a fixed output voltage of a pre-set magnitude which remains constant regardless of

changes to its input voltage or load conditions. Microcontroller is also connected with

motor driver IC which is a dual H-bridge motor IC. It can amplify a current signal and

can operate both the motors simultaneously in either forward or backward direction.

Controller Board schematic is given below:

Fig. 13. Controller Board Schematic captured from Eagle.

Page 18: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

17

PCB design for controller board is given below and the tests used to check the

functionality of this board will be Test 1 and Test 2.

Fig. 14. Controller Board PCB design captured from Eagle.

Page 19: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

18

Test plan for the Controller Board

Test 1

Fig. 15. Code for Test 1, screenshot taken from MPLAB IDE.

The first test was conducted to confirm if the LED flashes or not. As per the code

above, firstly the internal clock frequency was set at 8 (Hz) megahertz. Secondly the

LED and the Pushbutton and the LED were declared. Lastly “While” statement was

used to toggle the LED and a delay of 10ms was set. Running the program proved

that the LED was flashing as required.

Page 20: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

19

Test 2

Fig. 16. Code for Test 2, screenshot taken from MPLAB IDE.

The second test is no different than the first test except that it needed the user to first

press the “Pushbutton” to turn the LED ON. “Wait4Pb();” command was used for this

purpose. After running the program, the pushbutton was pressed and LED started

flashing.

Sensor Board

The process to design and build this sensor board is exactly similar to Controller

Board process. Firstly the schematic is designed and secondly it is converted into

the PCB layout. Figure 11 and 12 shows Sensor board schematic design and PCB

design respectively.

After the sensor board was constructed all the components were soldered on exact

places with right direction of their polarities as shown on the PCB layout. Board is

soldered with three resistances of 180Ω (R3, R7, R9) for LEDs, three resistances of

10KΩ (R1, R2, R6) for phototransistors and one resistance of 100KΩ for the mosfet.

Two capacitors are also soldered which are 0.1Uf (C1) and 100uF (C2). All

Page 21: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

20

components were made sure that they are soldered with their right direction of

polarities i.e. LEDs’ short legs are connected to resistors and sensors’ long legs are

connected to resistors. Two sensors were soldered in front of the board with an

approximate distance of 30mm in between them and with a height of approximately

20mm for all the sensors. J1 and J2 IDC box headers were connected by using a

ribbon cable connector to finally start testing the sensor board. Test 3 and test 4

were conducted to check this board.

Test plan for the Sensor Board

Test 3

Fig. 17. Code for Test 3, screenshot taken from MPLAB IDE.

The third test first started with initialising the internal clock, LED, Pushbutton and the

Sensor LED driver. Then wait for pushbutton to be pressed. Finally a “While” loop

was added which first Turned the LED ON then wait for 10ms and then turn the LED

OFF and then another delay of 10ms was added. Actually it checked that after

pressing the pushbutton either the LED was blinking or not with given intervals of

delays.

Page 22: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

21

Test 4

Fig. 18. Code for Test 4, screenshot taken from MPLAB IDE.

The fourth test had very similar code to the third test except it also initialises Analogue to digital converter by using “IntADC()” command and it uses “While” loop to make sure that both the sensors read the white line with a delay of 10ms in between. While loop used commands “right = ReadSensorAC(LR);” to read the right sensor and “left= ReadSensorAC(LL);” to read the left sensor.

Fig. 19. Sensor readings captured from MPLAB IDE.

Page 23: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

22

The screenshot above was obtained by using the “Watch” function of software

MPLAB IDE’s. It shows the decimal values of left sensor and right sensor at -20mm

and the right hand side marker sensor. Values can be seen above as 363,425 and

470 respectively.

Fig. 20. Sensor readings and graph captured from Excel.

Further the readings above are obtained using a cardboard that had a ruler of

100mm distance on one side and on other side it had black surface with white line in

the middle so that sensor can read the line. Values above were obtained by placing

the sensors on the white line. Readings were started from 0mm distance and were

taken 7 more reading in both directions with an interval of 5mm after each reading.

Sensors being very sensitive, special attention was paid while taking the readings.

H-bridge motor and Chassis

After testing and making sure that both the Controller board and Sensor board work

they were mounted on the chassis which comes with the H-bridge motors. After both

the boards are connected with each other and mounted on the chassis the robot is

complete. Now the power supply is used which is set to 9V DC with it taking

approximately 90mA current supply when the motors started running.

Page 24: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

23

Test plan for H-Bridge Motor Driver

Test 5

Fig. 21. Code for Test 5, screenshot taken from MPLAB IDE.

The fifth test initialised everything as in test four with an addition of initialisation of

Pulse width Modulation by using the command “IntPWM();”. Then it waited for the

pushbutton to be pressed. Further the speed on both motors was set to 10. Finally a

“While(TRUE):” statement was used that turned both motors ON which then moved

the chassis.

Page 25: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

24

Software Implementation

Fig. 22. Program code for the entire robot, screenshot taken from MPLAB IDE.

Firstly the program was written in MPLAB software, secondly it was modified

accordingly so that it can complied with the stated rules of the contest and finally it

was uploaded to the microcontroller using the pickit2 debugger.

Include: Code was started with “include” functions where it included the type of

microcontroller “#include <pic18f2520.h> that is used as per the requirements, then it

included “#include <delays.h>” that were necessary for programs operations and

finally it included “libraries” which were “#include “labrat.h”” and “#include

Page 26: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

25

“ratlib02.h”” that are used to save the space of the program and make it look neater

and easily understandable.

Define constants: This functions was used to make three declarations which are

“#define KP 0.3” the constant and the “#define LPWM 10” and “#define RPWM 10”

which are the left and right pulse width modulation respectively. KP was used to

minimize the error to bring back the robot on the line for smooth run, it was set to 0.3

as it was found to be most suitable for the robot after couple of tests. The LPWM and

RPWM are speeds of the left and right motors respectively which were set to 10 after

couple of tests where it could successfully follow the line and run smoothly.

Variables: Main program starts with three signed integers which are “signed int

Error”, “signed int Leftline” and “signed int Rightline”.

Initialisation: Couple of things are then initialised and set which are given below:

“InitIntClk8MHz();” Internal clock was initialised and set to 8MHz because

there was no external oscillator under use.

“InitLedPb();” Pushbutton is initialised so that pressing it can turn the LEDs

on.

“LEDCTRL_DDR = 0;” This sets the value of driver to 0.

“InitADC();” This was initialised for analogue to digital conversion as sensors

could only read analogue data which is then converted to digital and sent to

microcontroller, which only read digital date, for it to perform operation.

“InitPWM();” Pulse width modulation is the number of pulses that are used to

drive the motor, greater the pulses faster the motor runs and vice versa.

Maximum value that it can be set to is 100.

Push button: After initialising and setting the required functions above, program

now waits for the pushbutton to be pressed, command used to implement this is

“Wait4PB ( );” After the pushbutton is pressed continuous loop starts as follows:

Set Duties: Left duty and right duties are set to 10 using the commands

“SetDutyLeft (10);” and “SetDutyRight (10);” respectively.

Read Sensors: Then the command “LeftLine = ReadSensorAC (LL);” is used to

make left sensor to read value from the white line and assign it to the signed integer

“Leftline” after which a delay of 1ms is added for it to complete the function. Same

happens for the “RighttLine = ReadSensorAC (LR);” as it makes the right sensor to

read and assign value to the assigned variable.

Calculate Errors: Then the command “Error = (RightLine – LeftLine) / KP;” is used

to calculate the error by taking away the left line value from the right line value and

dividing it by constant value, KP = 0.3. Error generated defines whether the robot is

on the line or out of the line. If the error is zero or approximately zero that means the

robot is following the line smoothly so the motors can keep the same speed

Page 27: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

26

otherwise in case of high error motors speeds are changed. Therefore by using

these errors the speed of left and right motors are controlled so that robot can

smoothly follow white line. Then another delay of 1ms is added.

Controlling Motors’ speed: Finally the commands “SetDutyLeft(LPWM+Error);” and

“SetDutyRight(RPWM-Error);” are used to control the PWM duty, the motors’

speeds. First command controls the left motor speed by adding the already

calculated error and second command controls the right motor speed by subtracting

the already calculated error. These two are very fundamental commands for smooth

running of robot on the white line i.e. when the error is positive the robot turns to right

so the speed of left motor is increased and the speed of right motor is decreased for

robot to bring it back on the white line. Opposite happens when the error is negative.

Conclusion

Line follower robot is developed that smoothly follows the line and meets rest of the

contest rules. Some difficulties were faced especially while programming the

microcontroller the motor speed was set too high which made the robot run too fast

consequently not following the line. Then the KP constant and motors’ speed was

adjusted after couple of runs so that sensors could sense the white line efficiently

and robot cold follow it smoothly. Project was provided with sufficient details and

instructions to follow and guidance to start every part of it. All this was a great help

towards acquiring knowledge and developing skills to design, build and implement a

basic embedded system which can later be modified to participate in even more

advance competitions. Whole project actually investigated an engineering design

problem related to electronics circuits using theory, simulation, practical construction,

laboratory equipments, ECAD packeges, device data sheets, implementation of

system concepts, testing, hardware debugging, practical demonstration and finally

delivered information in written report. It was first ever, great experience of

embedded world.

Page 28: Birmingham City University Presented to Dr Tony Wilcox By ... · punch card readers, counting systems etc. It is an electronic switching and current amplification component dependent

Design and Build of an IET Triathlon robot

27

References Keyword suggestion (2015). Phototransistors Related Keywords & Suggestions. Available at: http://www.keyword-suggestions.com/cGhvdG90cmFuc2lzdG9y/ [Accessed 15 May 2016] Tarun Agarwal (2016). Types of Photodetectors. Available at: https://www.elprocus.com/phototransistor-basics-and-advantages/ [Accessed 15 May 2016] Andy Lindsay (2012). How the Phototransistors Circuits Works. Available at: http://learn.parallax.com/tutorials/robot/shield-bot/robotics-board-education-shield-arduino/chapter-6-light-sensitive-11 [Accessed 16 May 2016] Hamamatsu (2016). GaAsP photodiode. Available at:

http://www.hamamatsu.com/jp/en/G1115.html [Accessed 18 May 2016]

Real World (2016). A real world situation. Available at: http://archive.cnx.org/contents/28af42a0-2770-46ab-8411-ca00335d6cdc@1/using-c-and-the-adc-for-real-world-applications-with-the-msp430 [Accessed 18 May 2016] Fernando Serrano (2015). LEGO robot: Line follower. Available at: http://fernandojsg.com/project/lego-robot-line-follower/ [Accessed 28 May 2016] Fairchild Semiconductors (1995). FairChild semiconductors, November 1995.

Available at:

https://www.fairchildsemi.com/datasheets/2N/2N7000.pdf [Accessed 29 May 2016]