Sie sind auf Seite 1von 31

EngE 1215: Foundations of Engineering 1

Data Acquisition, Analysis, and Representations & Control


Systems

Week 14A - Line Following Logic

November 30, 2015

Week 14

ADVISING TIP OF THE WEEK

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

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).

Final Test Reminders


MATLAB 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!

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.

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

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

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

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.

Today we will practice preparation/submission


for the MATLAB practical

Open MATLAB
Review pretest procedures
Review test procedures
Practice submission

Pre-test machine preparation


Prior 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.

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.

Lets 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.

Goal for the rest of today


Develop line following logic

How does this engineering system (the Audi A7)


use data acquisition?

Real-World Control Systems

Using Robot_Stub.m as the foundation, add your


LineFollowing Logic to create your ROBOT program

Read Sensors

Determine
desired
response

Send instructions
to motors
Path

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)

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
51

Center
Sensor
648

Right
Sensor
98

720

61

44

54

72

810

44

52

38

50

505

717

57

730

546

620

550

50

Left Motor Right Motor

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

You will need to write a simple line following


algorithm to test your logic
START

Initialize number of readings, loop


control variable
While loop
number of
readings times

OUTPUT
left motor off ,
right motor off

INPUT
Sensor Readings

STOP

Decide action based


on sesnor readings

Increment loop
control variable

OUTPUT
Instructions to
motor

Replace the dashed


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

Use the values below to test your logic


Lets 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
51

Center
Sensor
648

Right
Sensor
98

720

61

44

54

72

810

44

52

38

50

505

717

57

730

546

620

550

50

Left Motor Right Motor

Threshold = 500,
NumReadings = 1000, LC = 1,
AllWhite = 0,
OUTPUT
left motor off ,
right motor off

While
LC<NumReadings

Using an elseif structure to


send instructions to the
motors based on a single
sensor reading is a simple
but effective structure.

INPUT
Left, Center, Right

If
LC = LC + 1

OUTPUT
leftmotor ___,
rightmotor ___

if

OUTPUT
leftmotor ___,
rightmotor ___

if

OUTPUT
leftmotor ___,
rightmotor ___

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

Considering our simple algorithm,


what happens when all sensor
readings are below the threshold?

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

OUTPUT
left motor off ,
right motor off

While
AllWhite == 0
INPUT
Left, Center, Right

If
? >Threshold
LC = LC + 1

Left motor ?
Right motor ?

if
? >Threshold

Left motor ?
Right motor ?

if
? >Threshold

Left motor ?
Right motor ?

When would this


happen?

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

How can you implement the line sensed


condition? AllWhite ==0
Threshold = 500,
NumReadings = 1000, LC = 1,
AllWhite = 0

while AllWhite == 0
OUTPUT
left motor off ,
right motor off

While
AllWhite = 0

end

INPUT
Left, Center, Right

If
?>Threshold
LC = LC + 1

Left motor ?
Right motor ?

if
? >Threshold

Left motor ?
Right motor ?

if
? >Threshold
F

AllWhite = AllWhite+1

Left motor ?
Right motor ?

Maybe
while AllWhite <= 15
would be better?

How can you implement the


line sensed condition?
Threshold = 500,
NumReadings = 1000, LC = 1,
AllWhite = 0, N2 = 15

Require N2 consecutive
white readings to
indicate no line sensed.

OUTPUT
left motor off ,
right motor off

While
AllWhite < N2

INPUT
Left, Center, Right

Notice how the AllWhite


counter is re-set when
any of the sensors
indicates black

If
Center>Threshold
LC = LC + 1

Left motor on
Right motor on

if
Left>Threshold

Left motor off


Right motor on

if
Right>Threshold

Left motor on
Right motor off

AllWhite = AllWhite+1
AllWhite = 0

For next time Add your line-following logic to


ROBOT STUB

Infra-Red Sensors

Tadpole Robot

Path

After developing and testing your line-following


logic, write your robot program
START

Initialize Sensor Parameters


Initialize Motor Parameters

Steps for following the line


Reading the sensor
Powering the motors
Turn Sensors and Motors Off
STOP

1. Begin with Robot_Stub.m which initializes the


sensor parameters
2. Add your line-following logic
a. 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).

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

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.

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.

Das könnte Ihnen auch gefallen