[ee478] 09es group2 final report

22
Line Follower Robot  1 Final Report ECE 478  Line Follower Rob ot  Lecturer: Nathaniel McVical Lab instructor: Pham Xuan Trung  Nguyen Th e Nghia 09ES Tr n Vi t Tun Lê Chí Công Lê Hoàng Nht

Upload: le-hoang-nhat

Post on 09-Mar-2016

221 views

Category:

Documents


0 download

DESCRIPTION

project

TRANSCRIPT

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 1/22

Line Follower Robot  

1

Final Report ECE 478

 Line Follower Robot  

Lecturer: Nathaniel McVical

Lab instructor: Pham Xuan Trung Nguyen The Nghia

09ES

Tr ần Việt TuấnLê Chí Công

Lê Hoàng Nhật

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 2/22

Line Follower Robot  

2

Table of contents

1. Abstract………………………………………………………………………. 3 

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

3. Discussion…………………………………………………………………….3 

3.1. Design………………………………………………………………..3 

3.2. Implementation……………………………………………………..9 

3.2.1 Sensor Working Principle…………………………………………9 

3.2.2 Navigate Principle………………………………………………..10 

3.2.3 Motor controller module L298N…………………………………11 

3.2.4 Schematic…………………………………………………………12 

3.2.5 Hardware Implement…………………………………………….13 

3.2.6 Programming…………………………………………………….14 

4. Testing and Results…………………………………………………………19 

4.1 Testing………………………………………………………………19 

4.2 Result………………………………………………………………..19 

5. Summary and Conclusion………………………………………....……...20

6. Work Assignment………………………………………………………......21

7. Referrence..................................................................................................22

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 3/22

Line Follower Robot  

3

1. Abstract

The line follower robot is one of the self operating mobile machines that follow a line

drawn on the floor. The path can be a visible black line on a white surface (reverse). Capturing

the line position with LDR mounted at the front end of the robot. Most are using ir sensors to

detect the line but in this project LDR is used in place of optical sensors. This kind of robot can

 be used for military purposes, delivery services, transportation systems, blind assistive

applications. Line-following robots are very popular with technical university and high-school

students. These projects are quite helpful in motivating students to learn actively the

implementation skills for intelligent mobile robots. The line-following robot devised in this

 project includes accurate line detection algorithms with analog outputs of reflective optical

sensors.

2. Introduction

In the previous version, we did build a design and implementation of line followerrobot. In this project we show that how our design works in pratical. Futhermore, we focus on

the components operation by performing many test cases. The main target is that our circuit go

well and robot can follow line. In the final version we keep the same design as midterm report.

3. Discussion 

3.1 Design

Discussion design:

 

Requirement definition

Robot must go in line correctly

Low- cost

 Not too large in size

 

System Specification

- Microcontroller will control motor go in line correctly with two LDR sensor takes

value from ground (Black or white).

- Material to do robot is easy to buy in shop with low cost such as: geared motor,

resistors, Light dependent resistor (LDR), some ICs...

- Size of robot about with CDs disk in diameter.

  Function

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 4/22

Line Follower Robot  

4

ADC Function

Signal from LDR will be analog signal and it will be converted to digital signal. The

signal will depend on value of LDR.

Function PWM

Pulse width modulation will give voltage out from some ports of IC. This voltage will

determine speed of motor.

Turn left

When left LDR meet black line, the right motor will rotate faster than left motor.

Turn right

When right LDR meet black line, the left motor will rotate faster than right motor.

Cross intersection

If robot go to intersection, two LDR meet black line. We can improve that by the way is

to ignore two LDR sensors and also two motor go straight.

T junctionThe problem here is to have both sensors detect the line at the same time !. However,

the msp430 will know the line has made a turn and we can program it to ignore the

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 5/22

Line Follower Robot  

5

second sensor warning until after the turn is complete. Acute turn angles are treated in

the same way.

Search mode

However at the higher speeds our robot could lose the line or skid off the track so it is

normal to include a sub routine in program to help the robot find the line again. In its

simplest form, one simply makes the robot move in a circle until it picks up the line

again. If the robot cannot find the line within a reasonable time then the msp430 can

 power down the whole robot to conserve the batteries.

  Architectural design

  Prototyping

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 6/22

Line Follower Robot  

6

  Detailed Design

- We must create voltage about 3.3V that supply for msp430. According to following figure:

using IC LM1117.

Figure 1: Design circuit of 3.3V using LM1117

- 2 light dependent resistors.

- 2 LEDs.

- 1 board for all components attached on it.

- 1 IC MSP430G2231.

- 2 motors with wheels.

  Debugging

Hardware:

- Use voltmeter to check all voltages needed .

- Connect ports on MSP430G2231 to motor corresponding.

- Connect input from signal of LDR to IC MSP430.

Software:

- Using Texas Instruments Code Composer Studio Core Edition version 4.2.1.00004 MSP430

to write and debug code.

- Use oscilloscope to check signal PWM.

- Use Laboratory power supply

Testing

- We check the left or right motor and consider if it move when the left or right sensor meet

 black line. This is to guarantee that the signal of sensor being active.

- Checking speed of motor when we change the color of ground.

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 7/22

Line Follower Robot  

7

Use Case:

Block Diagram:

Microcontroller MSP430

ADC PWMSensor

Battery

Left motor

Right motor

Motor

driver

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 8/22

Line Follower Robot  

8

Parts list:

1. Resistors: 220 (2), 470 (1), 100 (4), 22K (2)

2. Light Dependent Resistor (2) 

3. Capacitors 0.1uF (3), 1uF (1)

4. Diodes: 1N4004

5. IC: LM1117 3.3 volt voltage regulator

6. Texas Instruments MSP430 Value Line LaunchPad Development Board

7. Texas Instruments MSP430G2231 microcontroller.

8. DC Motor: DC geared motor with Wheel

9. Motor control module L298N

10. One reset push button switch

11. Perforated PCB

12. 4 x AA Battery holder

13. CD/DVD ROM

14. Bolt, Nuts, Double Tape and Standard Electrical Tape for the black line

3.2. Implementation

3.2.1 Sensor Working Principle

 This Line Follower Robot design used the photocell sensor known as a Light Dependent

Resistor (LDR) made from Cadmium Sulphide (CdS) to detect the black track line, when

the LDR is above the black track line it will give a high resistance value while above the

white background and it will give a low resistance value. Together with the 22K resistor,

they will form what’s known as the voltage divider circuit. This voltage divider circuit

sensor will provide the varying voltage according to the amount of the light intensity

reflected back to the LDR. The blue Light Emitting Diode (LED) will provide a constantlight source for the sensors.

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 9/22

Line Follower Robot  

9

Figure 2: The Line Follower Robot Photocall (LDR) Sensor Working Principle

 Pulse Width Modulation (PWM) is a technique widely used in modernswitching circuit to control the amount of power given to the electrical

device. By varying the ON period i.e. longer or shorter than the OFF period,

we could control the DC motor rotation speed.

Figure 3: PWM Timing Diagram

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 10/22

Line Follower Robot  

10

3.2.2 Navigate Principle

The MSP430G2231 microconttroller will translate this varying voltage using its analog

to digital conversion (ADC) peripheral into the DC motor rotation speed using what known as

the Pulse Width Modulation (PWM) signal. Because this LFR used the “differential steering ”

(used two independent DC motor for steering) method, therefore by varying the left and the

right DC motor rotation speed proportionally to the light intensity received by both of the left

and right LDR, we could easily make the robot to navigate the black track line successfully.

Figure 4: Line Follower Robot Differential Drive Steering 

3.2.3 Motor controller module L298N

The motor driver is built on a L298N H-Bridge using a tri-state switch to control the

directions and PWM input to control speed of the motors. It's supposed to drive two motors

using up to 2A.

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 11/22

Line Follower Robot  

11

Figure 5: Motor control module L298N

Figure 6: Block Diagram of Motor controller module L298N 

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 12/22

Line Follower Robot  

12

3.2.4 Schematic

Figure 7: The Line Follower Robot with Texas Instruments MSP430G2231

Microcontroller Schematic 

3.2.5 Hardware Implement

Figure 8: DC geared motor with Wheel

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 13/22

Line Follower Robot  

13

Figure 10: Texas Instruments MSP430G2231 microcontroller

Figure 9: Texas Instruments MSP430 Value Line LaunchPad Development Board

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 14/22

Line Follower Robot  

14

3.2.6 Programming

#include<msp430g2231.h>

#define L_MOTOR BIT0 // Left Motor

#define R_MOTOR BIT6 // Right Motor

#define L_LDR BIT4 // left light dependent resistor

#define R_LDR BIT5 // Right light dependent resistor

#define led_sensor BIT7 // sensor led

#define MAX_COUNT 100

// Sensor Calibration

#define CAL_SAMPLES 5

#define calibration_speed1 75

#define calibration_speed2 40

#define CAL_MOVE_DELAY 320

// PWM Duty Cycle Threshold

#define MAX_THRESHOLD 75

Figure 11: Line Follower Robot

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 15/22

Line Follower Robot  

15

#define MIN_THRESHOLD 60

// Sensor Status

#define LEFT_SENSOR 0

#define RIGHT_SENSOR 1

Unsigned int pwm_count=0;Unsigned int PWM_MOTOR1=0;

Unsigned int PWM_MOTOR2=0;

Unsigned int min_Left_LDR=0;

Unsigned int max_Left_LDR=0;

Unsigned int min_right_LDR=0;

Unsigned int max_right_LDR=0;

Unsigned int ADCfunction(unsignedint adc, unsignedint in_min, unsignedint in_max)

{

unsignedint adc_index;

// Calculate the result and put it within 0 to 100% PWM Duty Cycle value

adc_index = 100 - ((adc - in_min) * 100 / (in_max - in_min));

if (adc_index <= MIN_THRESHOLD)

adc_index=0;

if (adc_index >= MAX_THRESHOLD)

adc_index=MAX_THRESHOLD;

return(adc_index);

}

void DelayMs(unsignedint ms)

{

while(ms--) {

delay_sys(1000); // 1 ms delay for 1 MHz Internal Clock

}

}

// TimerA Channel 0 interrupt service routine

#pragma vector=TIMER0_A0_VECTOR

 __interrupt void Timer_A (void)

{

// The PWM Period is about: 101 x 0.1 ms = 10.1 ms

 pwm_count++;

if (pwm_count >= MAX_COUNT) {

 pwm_count=0;

P1OUT |= L_MOTOR; // Turn On Left Motor

P1OUT |= R_MOTOR; // Turn On Right Motor

}if (pwm_count == PWM_MOTOR1) {

P1OUT &= ~L_MOTOR; // Turn Off Left Motor

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 16/22

Line Follower Robot  

16

}

if (pwm_count == PWM_MOTOR2) {

P1OUT &= ~R_MOTOR; // Turn Off Right Motor

}}

unsigned int ReadSensorFunction(unsignedchar state)

{

ADC10CTL0 &= ~ENC; // Disable ADC10

if (state) {

ADC10CTL1 &= ~INCH_4; // Deselect ADC Channel 4

ADC10CTL1 |= INCH_5; // Select ADC Channel 5 (A5), Right LDR

} else {

ADC10CTL1 &= ~INCH_5; // Deselect ADC Channel 5

ADC10CTL1 = INCH_4; // Select ADC Channel 4 (A4), Left LDR

}

ADC10CTL0 |= ENC + ADC10SC; // Enable ADC10 and Conversion start

while (ADC10CTL1 & ADC10BUSY); // Wait for ADC Conversion

return(ADC10MEM); // Return ADC Value

}

void Cal_Sensor()

{

Unsigned char i;

Unsigned int signal_left,signal_right;

// Get the Maximum Value Sensor Value (over black line)

P1OUT |= led_sensor; // Turn On the Sensor LED

DelayMs(1000); // Give enough time to light the LDR

signal_left=0;

signal_right=0;

for(i=0; i < CAL_SAMPLES; i++) {

signal_left += ReadSensorFunction(LEFT_SENSOR); // Read The Left LDR (A4)

delay_sys(50);

signal_right += ReadSensorFunction(RIGHT_SENSOR); // Read The Right LDR (A5)

delay_sys(50);

}

max_Left_LDR = signal_left / CAL_SAMPLES; // Get the Max Left Average Value

max_right_LDR = signal_right / CAL_SAMPLES; // Get the Max Right Average Value

// Now move the robot to the next calibration stage

PWM_MOTOR1=calibration_speed1;

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 17/22

Line Follower Robot  

17

PWM_MOTOR2=calibration_speed2;

DelayMs(CAL_MOVE_DELAY);

// Turn off the Motor (Duty Cycle 0)

PWM_MOTOR1=0;PWM_MOTOR2=0;

// Get the Minimum Value Sensor Value (over white line)

signal_left=0;

signal_right=0;

for(i=0; i < CAL_SAMPLES; i++) {

signal_left += ReadSensorFunction(LEFT_SENSOR); // Read The Left LDR (A4)

delay_sys(50);

signal_right += ReadSensorFunction(RIGHT_SENSOR); // Read The Right LDR (A5)

delay_sys(50);

}

min_Left_LDR = signal_left / CAL_SAMPLES; // Get the Min Left Average Value

min_right_LDR = signal_right / CAL_SAMPLES; // Get the Min Right Average Value

// Blink the Sensor LED after calibrating

for(i=0; i < CAL_SAMPLES; i++) {

P1OUT &= ~led_sensor; // Turn Off LED

DelayMs(500);

P1OUT |= led_sensor; // Turn On LED

DelayMs(30);

}

}

void main(void)

{

unsigned int Value_Sensor;

WDTCTL = WDTPW + WDTHOLD; // Stop WDT

// P1.0,P1.6 and P1.7 output, Other as Input

P1DIR = L_MOTOR + R_MOTOR + led_sensor;

// Enable the pull-down resistor on the unused input ports

P1REN = BIT1 + BIT2 + BIT3;

P2REN = BIT6 + BIT7;

// Reset all the Output

P1OUT = 0x00;

// TIMER A channel 0 will interrupt every 100 cycles

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 18/22

Line Follower Robot  

18

// Interrupt time counter period: 100 / 1.000.000 = 0.1 ms

TACCTL0 = CCIE; // CCR0 interrupt enabled

TACCR0 = 99;

TACTL = TASSEL_2 + MC_1; // Start Timer, SMCLK, Up Mode

// Start the ADC10 Peripheral

// Vref = Vcc, 16 ADC Clock, Enable ADC10

ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON;

// Sample-and-hold ADC10SC bit, ADC10 Clock /1, ADC10 Source Clock, Single Channel Conversion

ADC10CTL1 = SHS_0 + ADC10DIV_0 + ADC10SSEL_0 + CONSEQ_0;

ADC10AE0 = L_LDR + R_LDR; // Enable A4 and A5 as ADC Input

DelayMs(1); // Wait for ADC Ref to settle

// Initial the PWM Duty Cycle and Enable the MSP430 Interrupts

 pwm_count=0;

PWM_MOTOR1=0;

PWM_MOTOR2=0;

 __enable_interrupt();

// Now we Calibrate the LDR Sensors

Cal_Sensor();

DelayMs(1000); // Delay 1000 ms before start

// Loop Forever

for(;;)

{

// Read the Left LDR Sensor and make sure is within the range

Value_Sensor=ReadSensorFunction(LEFT_SENSOR);

if (Value_Sensor > max_Left_LDR)

Value_Sensor=max_Left_LDR;

if (Value_Sensor < min_Left_LDR)

Value_Sensor=min_Left_LDR;

// Assigned the Left PWM Duty Cycle

PWM_MOTOR1=ADCfunction(Value_Sensor,min_Left_LDR,max_Left_LDR);

delay_sys(20);

// Read the Right LDR Sensor and make sure is within the range

Value_Sensor=ReadSensorFunction(RIGHT_SENSOR);if (Value_Sensor > max_right_LDR)

Value_Sensor=max_right_LDR;

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 19/22

Line Follower Robot  

19

if (Value_Sensor < min_right_LDR)

Value_Sensor=min_right_LDR;

// Assigned the Right PWM Duty Cycle

PWM_MOTOR2=ADCfunction(Value_Sensor,min_right_LDR,max_right_LDR);delay_sys(20);

}

}

4. Testing and Results

4.1 Testing

After the selection of ranges for components of the line follower robot,the circuits areconstructed and all the components are assembled on the test base. We perform testing:

1.  Test Led:

Objective: Make sure that Led light stable and operate as programming.

2.  Test Photo Resistor: This is the important components.

Objective: Photo resistor change the resistor value when receive light source.

Technique: Use white light source such as flash light to change the amount of

light coming to photo resistor surface. After that we measure the changing of

voltage in particular cases. When the LDR receive less amount of light, it will

give a high resistance value. on the contrary, while LDR receive more amount

of light,it will give a low resistance value.

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 20/22

Line Follower Robot  

20

3.  Test PWM: Link on youtube about our Test

https: //www.youtube.com/watch?v=tyOA1EiQoh Q& list=UU7bvWShi- 

RGDWS1TGiZF M 3Q& index=1

Objective: To confirm that the pulse signal from port 2 and port 8 is working.Technique: Use Led1 and Led 2 attached in launchpad to test after sending code

to microcontroller. Moreover, after completing the real circuit, we connect with

osciloscope to measure pulse signal.

4.  Test source supply 3.3 V for the circuit:

Objective: To make sure the Msp controller run stable with the 3.3 V source.

5.  Test Reset circuit

Objective: To navigate the operation of system when we push reset button.

Finally, we finish the test with our desire.

4.2 Result

In general, we completed our robot as we designed. However, we have a big problem

with power supply for circuit. The pwm signal as well as photo resistor run well but the

unstable voltage make our circuit fail (The MSP430G2231 microcontroller can not work with a

unproperly voltage). We will describe more about the problem in summary section.

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 21/22

Line Follower Robot  

21

5. Summary and Conclusion 

The final version of our robot can not work. We really disapointed about that. Anything

work well with the test plan however it's impossible to solve the prolem. When we supply 9Vsource for the circuit, the voltage decrease immediately (2.8V) resulting in the msp430

controller cannot work with the unstable voltage. We try many times and spend much time to

test and check the problem. But it still happens. We try to test the H-bridge but there is nothing.

The weird thing is that the robot can run well two times when we testing. It means, at that time,

the voltage is stable and of course other part such as microcontroller and photo resister work.

In summary, the fact is that our robot can not work. We have made a demo clip to show that

 pwm and photo resistor are running. Because all members worked very hard on the project, 

we hope that we can find the problem why the voltage is unstable. After doing this project, we

have learned that:

- Decide the topic of project is the most important step.

- Spend proper time to test a problem. If it's still wrong, we have better find another ways.

6. Work Assignment:

There are 3 members in our group.

1. Le Hoang Nhat: (60 hours) -Design UML diagram

-Work on circuit

-Implement components

-Testing

-Write Report

- Presend demo

2. Tran Viet Tuan: (60 hours) -Design UML diagram

- Work on circuit

- Implement components

- Testing- Present demo

-Write report

3. Le Chi Cong (60 hours) -Design UML diagram

-Draw circuit schematic

-Implement components

-Work on circuit

-Testing

-Present demo

-Write Report

7/21/2019 [EE478] 09ES Group2 Final Report

http://slidepdf.com/reader/full/ee478-09es-group2-final-report 22/22

Line Follower Robot  

7. References

[1] Embedded Systems: A Contemporary Design Tool by James K. Peckol

[2] Nor Maniha Abdul Ghani, Faradila Naim, Tan Piow Yon , “Two Wheels Balancing Robot

with Line Following Capability,” World Academy of Science, Engineering and Technology, pp-634-638, 2011.

[3] http://www.ti.com/lit/ds/symlink/msp430g2231.pdf

[4] http://www.datasheetcatalog.org/datasheet/nationalsemiconductor/LM1117.pdf

[5] Build Your Own Transistor Based Mobile Line Follower Robot (LFR)-emicro.com