the george washington university electrical & computer engineering department ece 002 dr. s....

20
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Lab 1

Upload: blaise-young

Post on 17-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

The George Washington University Electrical & Computer Engineering Department

ECE 002

Dr. S. Ahmadi

Lab 1

Class Agenda

• Digital Sensors

• Analog Sensors– Light Sensors.– Optical Rangefinder Sensors.– Ultrasonic Sensors (Sonar).

• Analog Sensor Characterization

Two Distinct Categories of Sensors

• Digital and Analog• Digital sensors have two states: 0 or 1• Analog sensors have a range of states depending

on their input• Example:

– A door can be open or closed• What type of representation of the condition of the door is this?

– How far the door is open (0 to 180 degrees!)• What type of representation of the condition of the door is this?

Hook up DIGITAL SensorsTo these ports: 7-15

Hook up ANALOG sensorsTo these ports: (2-6)

Hook up additional Analog sensorsTo these ports (20-23)

Hooking up Sensors to the Handyboard

Digital Sensor: The Bumper Sensor

• Digital sensor:– Returns either a 0 or 1.

• Connect to DIGITAL ports 7-15• Access with function digital(port#);• ‘0’ indicates switch is open (nothing

has happened). Normally, switch will be ‘0’.

• ‘1’ indicates switch is closed (Switch has been hit).

• For more information on different digital sensors available to you, refer to the Botball Kit Documentation, slides 42, 43, 51.

Bumper Sensor Procedure and Test Code/* Program to beep if a bumper on port 13 has been hit. */

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

while(stop_button()==0) // Keep program running until press stop button{

printf(“Switch on port 13 is open!\n”);

// Bumper connected to port // 13. If it is hit, sends if (digital(13)= =1) // 1 to handyboard. {

printf(“Switch on port 13 has been closed!\n”);beep();

}}

}

Analog Sensors

• Output a range of values, depending on the input read.

• The main analog ports are ports 2 – 6, and ports 20 – 23.

• Actual ports that should be used will depend on the sensor being used.

• The three main analog sensors that we will be using are the Light Sensor, the Optical Rangefinder Sensor and the Ultrasonic Sensor, also known as the Sonar.

Light Sensors

• Access with function analog(port#)• Connected to ports 2-6 or 20-23

• Analog values range from 0 - 255.

• A low value indicates bright light, and vice versa.

Optical Rangefinder Sensors

• Access with function analog(port#)• Connected to ports 16-19

• Analog values range from 0 - 255.

• Low values indicate far distance from an obstacle

• High values indicate close proximity to an obstacle ~4 inches

Ultrasonic Sensors (Sonar)

• Connect red to upper deck board - port #0• Connect gray to Digital #7• Access with function sonar()• Returned value is distance in mm to closest

object in field of view• Range is approximately 30-2000 mm• When objects are too close or too far,

gives value of 32767

Sonar Sample Code/% Program that measures the sonar reading at different input

values.%/

void main(){ int range=0; printf(“\n Sensor Sample Program"); while(!start_button()); // Press Start Button

while(1) // Continue infinitely{

sleep(0.5);range = sonar(); printf(“\nOutput is %d”, range);

} }

Analog Sensor Characterization

• The purpose of this exercise is to tabulate the readings from the three different analog sensors mentioned, when different inputs are sensed:– Light Sensor: Using the attached color scale, move

the light sensor along the sheet, and record the values read at different intervals.

– Optical Rangefinder: Using the provided boards, at different distances record the outputs read from the sensor.

– Ultrasonic Sensor: Similar to the Optical Rangefinder, record the output from the sensor at different input distances.

Light Sensor Color Scale

50% 0%100%

½”

½” ½”

½” ½”

Lab Requirements

• Collect Data for at least one sensor. (Data to be handed in at end of lab, and you’ll need it for your HW.)

• FOR LIGHT SENSOR: Take 10 equally spaced readings.

• FOR SONAR SENSOR: Take enough readings to characterize sensor (more when measurements are non-linear, less when data is predictable)

• Insert the data into an Excel spreadsheet• Plot the data (X-axis for distance, Y-axis for sensor

readings).• Email the spreadsheet to all group members to complete

HW

Sensor Range

• Sensors have an established operating range. Determine what this is for your sensor.

• Choose your ten points so that they span the complete operating range of the sensor.

Example Plot of Sensor Characterization – RANGE

FINDER SENSORRange Finder Characterization

0

20

40

60

80

100

120

140

160

180

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42

Inches From Wall

Sen

sor

Rea

din

g

Due in Lab Today

• After tabulating the results, plot the graph for each sensor type, to see if the relationship turns out linear or not. Draw the curve to fit the graph.

• Note: To simplify your work, write a short program that can continually print out the reading of the sensor on the Handyboards display.

• Take a look at HW#1(Comprehensive Report on the Characterization of Robot’s Sensors), save your data/graphs for HW#1.