week14a class notes

31
EngE 1215: Foundations of Engineering 1 Data Acquisition, Analysis, and Representations & Control Systems Week 14A - Line Following Logic November 30, 2015

Upload: swimmerdude1234

Post on 30-Jan-2016

7 views

Category:

Documents


0 download

DESCRIPTION

Notes

TRANSCRIPT

Page 1: Week14A Class Notes

EngE 1215: Foundations of Engineering 1

Data Acquisition, Analysis, and Representations & Control Systems

Week 14A - Line Following Logic

November 30, 2015

Page 2: Week14A Class Notes

ADVISING TIP OF THE WEEK

Spring Drop/Add Details

• Class registration can be categorized into two phases:

– Phase 1: Course Request

– Phase 2: Drop/Add

• Please note that it is typical for students to course request courses and not receive a seat in that respective course. You will use Drop/Add on Hokie Spa under the registration and schedule menu to add any courses you did not receive and finalize your class schedule.

• You may need to rearrange your schedule to accommodate the requirements necessary.

• Monitor the timetable of classes for seats to sporadically open throughout the drop/add period (November 28th – January 25th).

Week 14

If you wish to meet with your academic advisor you may schedule an appointment through the GE Advising Scholar Sign-Up Tool.

Page 3: Week14A Class Notes

Final Test RemindersMATLAB Practical

• Thursday December 3, 2015, 7:00 pm

• Test is 1 hour

• Location: 300 Whittemore

• Closed book, closed notes

• What to bring –pencil, Hokie Passort AND your computer

• Bring your computer fully charged!– testing rooms do not have outlets for all machines, so be sure your machine is ready to go!

Page 4: Week14A Class Notes

Final Test Part 1: MATLAB Practical (60 min)

• Bring your computer.• You will be given a flowchart and will have to write the MATLAB

script file for the algorithm. You will submit your m-file to Canvas.• The algorithm could involve:

– Input, Output, Plots– Repetition (while), Selection (if-else-end, stacked if, elseif)– Vector and scalar quantities

• Good programming practices are expected.• Practice problems are on Canvas.• You will be asked to stay until the proctor has confirmed

submission.• You will be permitted to use MATLAB help (help command), but

you may NOT open any m-files other than the test.

Page 5: Week14A Class Notes

Final Test Part 2

• Tuesday, Dec 15

• Begins at 1:05 pm

• Test will be one hour long

• Location: to be announced

• Multiple Choice (~25-30 questions)

• Bring Hokie passport, pencil, eraser, calculator

• Do NOT bring computer

• A formula sheet will be provided

Page 6: Week14A Class Notes

Topics that will be EXCLUDED from the final exam

• Eastman Presentation• Belbin Team Roles• Graphing and empirical functions, including fitting

empirical functions (by hand and in MATLAB)• Product Archaeology• Evaluating Resources• Sketching• Concept Mapping• Frith Lab introduction

Page 7: Week14A Class Notes

Topics that may be INCLUDED on the final exam• All readings and HWs from Week 5- Week 15• The Heart and the Fist (only required sections for 1215)• Interpreting flowcharts• Gravity experiment• Ethics• All MATLAB covered in the course, except fitting empirical

functions• Robot experiments• Professional Engineering and Accreditation• Energy Project• ‘What You Should Know’ type math problems• Problem solving process• Assertion/Evidence format• Any other material covered in this class not excluded on the

previous slide

Page 8: Week14A Class Notes

Asking Questions – Plan ahead!

• Practice MATLAB problems are on Canvas.

• Sample solutions have been posted on Canvas under the Pages menu in Solutions to Selected Assignments.

• Common Time office hours will end on Wed, Dec 9.

• Homework lounge will end on Wed, Dec 9.

• We are not allowed to hold review sessions during exam week.

• All instructors will be available via email to ask questions or set up appointments. Please contact your instructor directly with questions on course material.

Page 9: Week14A Class Notes

Today we will practice preparation/submission for the MATLAB practical

• Open MATLAB

• Review pretest procedures

• Review test procedures

• Practice submission

Page 10: Week14A Class Notes

Pre-test machine preparationPrior to the exam, when you arrive in your room, you will be asked to complete the following steps:

• Close all tabs across the top of the editor window.

• Type ‘clear’ and ‘clc’ in the command window to erase your command window and workspace.

• You must use the up arrow to open the command history, click on the down arrow and choose ‘Clear Command History’.

• Once completed, leave the blank window up for your machine to be checked prior to beginning the exam.

Complete these tasks now and have your instructor check your machine.

Page 11: Week14A Class Notes

MATLAB Test reminders

• You will not be able to access any old files.

• Follow ALL directions on the test paper.

• Submit an .m file for grading to Canvas under Quizzes.

• You should test your program prior to submission.

• Your program will be run for accuracy as part of the grading process.

• Once you close MATLAB to submit, you will not be allowed to re-open.

• It is an honor code violation to access the code on your computer after the test and prior to the return of test grades.

• Once submitted, your proctor will check to be sure you have successfully submitted.

Page 12: Week14A Class Notes

Let’s practice the submission process

• Go to the Canvas Quizzes page.

• Open the quiz titled “Practice Code Submission”.

• There is only one question, which is a file upload.

• In MATLAB, open ANY .m file you have previously created.

• Be sure your file runs with no errors.

• Be sure the first line is a comment with your name.

• Save and close MATLAB.

• Upload your .m file to the quiz and submit.

• Be sure you receive confirmation that you have properly submitted.

Page 13: Week14A Class Notes

Goal for the rest of today

Develop line following logic

Page 14: Week14A Class Notes

How does this engineering system (the Audi A7) use data acquisition?

Page 15: Week14A Class Notes

Real-World Control Systems

Page 16: Week14A Class Notes

Using Robot_Stub.m as the foundation, add your LineFollowing Logic to create your ROBOT program

Read SensorsDetermine

desired response

Send instructions to motors

Path

Page 17: Week14A Class Notes

Before you can write the program that will cause your robot to follow a line you should test your logic.

• What are the inputs? (sensor readings)

• What is the desired response for various possible inputs? (motor speeds)

Page 18: Week14A Class Notes

What do you want to do in each of the following situations? (Assume the threshold for black/white is 500)

• What do you want to do? Turn Right? Turn Left? Go straight?

• Which motor do you want to turn off/on?

Left

Sensor

Center

Sensor

Right

Sensor

Left Motor Right Motor

51 648 98

720 61 44

54 72 810

44 52 38

50 505 717

57 730 546

620 550 50

Page 19: Week14A Class Notes

Begin developing your line-following logic – Each student should develop their own “LOGIC” program

• Start simple

• Use a repetition structure (while loop) that executes a specific number of times in which you:

• Ask the user to input the three sensor readings

• Use a selection structure to

– compare sensor readings to the threshold for seeing black

– output the desired state of each motor (on or off) based on which sensor “sees black” (i.e., disp(‘leftmotor on’), disp(‘leftmotor off’))

• Addition guidelines/requirements

– start with only two motor states – on and off

– make a single comparison in each decision (no && or ||)

Your LOGIC program will not include any “ROBOT” commands

Page 20: Week14A Class Notes

You will need to write a simple line following algorithm to test your logic

START

INPUT Sensor Readings

STOP

While loop number of

readings times

Initialize number of readings, loop control variable

Increment loop control variable

Decide action based on sesnor readings

OUTPUTInstructions to

motor

T

OUTPUT left motor off , right motor off

F

Replace the dashed decision and output with and appropriate selection structure (stacked ifs or elseif)

Page 21: Week14A Class Notes

Use the values below to test your logic• Let’s check 7 sensor values –

• Have your program ask the user for sensor values 7 times.

• Use a threshold of 500

• For each set of sensor values display the desired motor actions i.e.,

disp(‘leftmotor on’) or disp(‘leftmotor off’)

• What is the desired/expected output?

Left

Sensor

Center

Sensor

Right

Sensor

Left Motor Right Motor

51 648 98

720 61 44

54 72 810

44 52 38

50 505 717

57 730 546

620 550 50

Page 22: Week14A Class Notes

Using an elseif structure to send instructions to the

motors based on a single sensor reading is a simple

but effective structure.

OUTPUT leftmotor ___, rightmotor ___

OUTPUT leftmotor ___, rightmotor ___

OUTPUT leftmotor ___, rightmotor ___

Compare a single sensor to the threshold value in each decision.

INPUT Left, Center, Right

WhileLC<NumReadings

Threshold = 500, NumReadings = 1000, LC = 1,

AllWhite = 0,

LC = LC + 1

If

if

if

F

F

T

T

T

OUTPUT left motor off , right motor off

F

Page 23: Week14A Class Notes

When would this happen?

INPUT Left, Center, Right

WhileAllWhite == 0

Threshold = 500, NumReadings = 1000, LC = 1,

AllWhite = 0,

LC = LC + 1

If ? >Threshold

if ? >Threshold

if ? >Threshold

F

F

T

T

T

OUTPUT left motor off , right motor off

Left motor ?Right motor ?

Left motor ?Right motor ?

Left motor ?Right motor ?

F

Considering our simple algorithm, what happens when all sensor

readings are below the threshold?

Page 24: Week14A Class Notes

How can we add logic to correct for the robot going off course? How many all white readings means the robot is off course?

Remember that a while loop continues as long as a condition is true; “Stop when goes off the line” means continue while “line sensed”

How can you implement the “line sensed” condition?

Path

Page 25: Week14A Class Notes

How can you implement the “line sensed” condition? AllWhite ==0

while AllWhite == 0

end

Maybe while AllWhite <= 15

would be better?

INPUT Left, Center, Right

WhileAllWhite = 0

Threshold = 500, NumReadings = 1000, LC = 1,

AllWhite = 0

LC = LC + 1

If ?>Threshold

if? >Threshold

if ? >Threshold

F

F

AllWhite = AllWhite+1

T

F

T

T

OUTPUT left motor off , right motor off

Left motor ?Right motor ?

Left motor ?Right motor ?

Left motor ?Right motor ?

Page 26: Week14A Class Notes

How can you implement the “line sensed” condition?

• Require N2 consecutive white readings to indicate no line sensed.

• Notice how the AllWhitecounter is re-set when any of the sensors indicates black

INPUT Left, Center, Right

WhileAllWhite < N2

Threshold = 500, NumReadings = 1000, LC = 1,

AllWhite = 0, N2 = 15

LC = LC + 1

If Center>Threshold

ifLeft>Threshold

if Right>Threshold

F

F

AllWhite = AllWhite+1

T

F

T

T

OUTPUT left motor off , right motor off

Left motor onRight motor on

Left motor offRight motor on

Left motor onRight motor off

AllWhite = 0

Page 27: Week14A Class Notes

For next time – Add your line-following logic to ROBOT STUB

Tadpole Robot

Infra-Red Sensors

Path

Page 28: Week14A Class Notes

After developing and testing your line-following logic, write your robot program

START

STOP

Initialize Sensor Parameters

Initialize Motor Parameters

Turn Sensors and Motors Off

Steps for following the line Reading the sensor Powering the motors

1. Begin with Robot_Stub.m which initializes the sensor parameters

2. Add your line-following logica. Add statements to turn the sensors on

just before reading and off just after reading (use a.digitalWrite)

b. Replace input statements with a.analogRead statements to get the sensor readings

c. Replace statement that displayed the desired motors settings to the screen with a.analogWrite statements to send the speeds to the motors.

d. Increase the number of times the loop repeats (7 will not be enough).

Page 29: Week14A Class Notes

Robot_stub.m defines the constants for both the motors and the sensors

% Constants for reading sensors

sensorpin = 13; % sensor control pin (all sensors)

leftsensorpin = 0; % left sensor read on pin 0

centersensorpin = 2;% center sensor read on pin 2

rightsensorpin = 4; % right sensor read on pin 4

a.pinMode(sensorpin,'OUTPUT'); % sets trigger pin to control

sensors

% Constants for motor control

leftmotor = 5; % left motor controlled by pin 5

rightmotor = 6; % right motor controlled by pin 6

lmhigh = 255; % left motor speed, range 0-255

rmhigh = 255; % right motor speed, range 0-255

off = 0; % motor speed of 0, 0 is off

Page 30: Week14A Class Notes

Upcoming Assignments MW Classes• 13b – Programming3 - Individual Submission

Due Wednesday 12/2 at 7:45 am

• 13c – Line Following Program (This is an INDIVIDUAL assignment that will be entered as a grade into the Group category. You should work on it independently.) Due Wednesday 12/2 at 7:45 am

• 13d – End of Semester Survey - Individual Submission –Link to survey will be emailed directly to you on 11/19. Due Wednesday 12/2 at 7:45 am

• In addition, you will have a report about your Wednesday experiment due on Monday 12/7.

Page 31: Week14A Class Notes

Upcoming Assignments TTh Classes• 13b – Programming3 - Individual Submission

Due Thursday 12/3 at 7:45 am

• 13c – Line Following Program (This is an INDIVIDUAL assignment that will be entered as a grade into the Group category. You should work on it independently.) Due Thursday 12/3 at 7:45 am

• 13d – End of Semester Survey - Individual Submission –Link to survey will be emailed directly to you on 11/19. Due Thursday 12/3 at 7:45 am

• In addition, you will have a report about your Thursday experiment due on Tuesday 12/8.