the george washington university department of ece ece 002 - intro: electrical & computer...

18
The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Upload: garry-morgan

Post on 19-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

The George Washington University Department of ECE

ECE 002 - Intro: Electrical & Computer Engineering

Dr. S. Ahmadi

Class 4/Lab3

Page 2: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

ECE 001

Class 4

• Agenda– Practicing 90 degree turns.– More Robot Building!– Exercise on Using Bumpers

– BONUS: Using analog sensors

Page 3: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Maze Specs

Start point

1.5’

1.5’

4’

4’

End Point

1.5’

1.5’1.5’

Page 4: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Project Description • The dashed green line defines the route of the robot.• The robot should run through the obstacle course from

the start point till the end point. • After it hits each obstacle, it backs up and takes a turn

in the direction of the route. • Project will be judged on smoothness of motion,

accuracy of route (turns and final stop are very important), time of travel, and of course a strong robot

• It is the student responsibility to make sure that the Handy Board is fully charged

• Each group will have one chance to demonstrate their project to the judges. Therefore, fully test your project before demonstration.

Page 5: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

General Flowchart

Start Button?

Go Straight

Sensor hit?

Backup Count < 2?

Turn Left

Backup

Turn Right

Count=0

Yes

Yes

Yes No

No

No

Page 6: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Bumper Implementation - Touch Sensors

• Refer to the slides 39-52 in the documentation file.• Is a type of digital sensor:

– Return a 0 or a 1– Switches or bumpers are an example(open: 0, or closed: 1)

Page 7: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3
Page 8: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Touch Sensor

• Digital sensor• Connect to ports 7-15• Access with function digital(port#)

• 1 indicates switch is closed• 0 indicates switch is open

Page 9: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Sample code To Use Bumpers// Program to make a robot go forward.// If hit detected, go backwards for 4 seconds.

void main(){ while(start_button()==0){ }; // Waits for use press start button.

while(1){

motor (1,80); // Turn on motor 1, @ 80% of speed.motor (3,80); // Turn on motor 3, @ 80% of speed.

if (digital(13)= =1) // Check sensor connected to port{

motor (1, -80); // Turn on motor 1, @ 3% of speed in opposite direction. motor (3, -80); // Turn on motor 1, @ 3% of speed in opposite

direction. sleep(4.0); off(4); sleep (5.0); } }

Page 10: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Project Requirement

• Making your robot escape from the maze Successfully (90 Points)

• Optional (10 points for implementing either 1 or 2)1.Using analog sensors, i.e. sonar or optical range

finder, program your robot so that it is able to find its own path out of the maze.

2.Adjusting your robot to make a perfect 90 degree turn with the reference of the black paper strip

GOOD LUCK!

Page 11: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Optional Requirement #1Implementation Example

Install your sonar/ranger finder on one side of your robot

While the front digital sensor is zeroGo forward

If the robot is closer to the right wallturn left;

Elseturn right;

Page 12: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

Optional Requirement #2Implementation Example

- Install light sensors on the bottom of your robotWhile the front digital sensor is zero Go forward

If the robot is closer to the right wall turn left;Else start to turn right;

If the left ground sensor detects the strip

then turn off the left motor until the right

ground sensor detects the strip

If the right ground sensor detects the strip

then turn off the right motor until the left

ground sensor detects the strip

Page 13: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3

while(analog(SENSOR_LB) > TURN_BTH && analog(SENSOR_RB) > TURN_BTH) { printf("\n going straight, looking for the line"); }

//Left sensor hit the line first, so stop the left motor

if (analog(SENSOR_LB) < TURN_BTH) { off(LEFT_MOTOR); while(analog(SENSOR_RB) > TURN_BTH) { printf("\nCorrecting for turn inaccuracy-Sharp Left"); } MoveStraight(); } else { off(RIGHT_MOTOR); while(analog(SENSOR_LB) > TURN_BTH) { printf("\nCorrectin for turn inaccuracy-Sharp Right"); } MoveStraight(); }

Page 14: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3
Page 15: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3
Page 16: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3
Page 17: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3
Page 18: The George Washington University Department of ECE ECE 002 - Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3