20
PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Embed Size (px)

Citation preview

Page 1: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

PHY 235 Robotics Workshop

Day 5

Distance SensingUsing The Ultrasonic Ping Sensor

Page 2: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Distance Detecting

• In a previous class session we used an Infrared light source, along with an infrared detector, to determine if an object was blocking the Boe-bot. The infrared detector could be thought of as a crude measurer of distance.

• In this class session we will look at another (more accurate) way of determining distance – by using high frequency sound waves (ultrasound).

Page 3: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

The Ping Sensor

• The Ping))) sensor measures distance. • Range: 3 cms to 3.3 m.• Highly Accurate (to within 1 or 2 cm)

Page 4: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

How does it work?

1. The ZX-24a sends out a short pulse to the Ping to tell it to start execution.

2. Ping waits a short time, (so ZX-24a can generate a pulseIn command).

3. Ping sends a HIGH (1) signal to ZX-24a, then sounds a short burst of 40Khz sound towards an object.

Page 5: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

How does it work?

4. When Ping receives an echo, sends a LOW to ZX-24a.

5. ZX-24a stores the time between HIGH and LOW signals as a measure of distance.

Page 6: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Ultrasound

Page 7: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1

• Locate the Ping Ultrasound sensor. (Your instructor will distribute)

• Find three Jumper wires. • Build this circuit

Page 8: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1 - Code

• The Ping))) sensor needs a start pulse from the ZX-24a to start its measurement.

• A pulse to P15 that lasts 10 μs and goes from 0->1 is given by

pulseOut (15, 5, 1)

Page 9: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1 - Code

• After the start pulse is sent, we change pin15 to an input pin and use a pulseIn command to store the duration of the Ping))) sensor's echo pulse. pulseIn(p15, 1, time)

•The pulseIn command stores in the variable time the round trip time for the Ping))) sensor's chirp to get to the object, reflect, and return.

Page 10: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

PulseIn

• PulseIn(pin, level, var) • From the help page: “This routine waits for the input pin to be in the idle state (the opposite of that specified by the level parameter), waits for it to change to the specified logic level and then measures the time that it stays at that level. The pulse width is stored in the specified variable and has units of seconds with a default resolution of approximately 1.085µs”

Page 11: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1

• Here is code for testing the Ping sensor:

const p15 as byte = 20dim time as single

Sub Main() do

call putpin(p15, 0) ' set p15 as output pin, output = 0call pulseout(p15, 5, 1) ' send a 10 microsec start pulse on p15 call putpin(p15, 2) ' set p15 as input pincall pulsein(p15, 1, time) 'record time to transition from 0->1->0debug.print "time="; time

loopEnd Sub

Page 12: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1

Recall how the PING sends its return pulse. The pulseIn command allows us to capture this return pulse.

Page 13: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1

• Test this program by measuring the timing values of a few close-up objects. • For close-up measurements, the Ping))) sensor only needs to be 8 to 10 cm above a flat surface. • However, if you are measuring objects that aremore than a half a meter away, you may need to elevate your Ping))) sensor to preventechoes from the floor (or table) registering as detected objects.

Page 14: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1 – Calibrating Ping

• How does the number recorded in the time variable related to actual distance? • pulseIn measures time in units of seconds • Thus, the time taken for the sound wave to go from the ping to an object and back again is = time • However, we need to divide this value by 2, to find the time it takes for the sound wave to reach the object.

Page 15: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1 – Calibrating Ping

• Now, Sound travels 1 cm in about 29.034 μs .• So, the distance to the object should be about

Distance = time/(2*.000029)

Use your Boe-bot and a ruler to verify that this formula is approximately correct.

Page 16: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 1 – Metric Pingconst p15 as byte = 20dim time as singledim cm as single

Sub Main()do

call putpin(p15, 0) ' set p15 as output pin, output = 0call pulseout(p15, 5, 1) ' send a 10 microsec pulse on p15 call putpin(p15, 2) ' set p15 as input pincall pulsein(p15, 1, time) 'record time to transition from 1->0cm = time / (2.0*0.000029)debug.print "cm ="; cm

loopEnd Sub

Page 17: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Ping Restrictions

• The Ping sensor cannot reliably detect objects that are:

•Too close•Too far•Too small•At too great an angle

Page 18: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 2

• You are to create a 3-prong wire harness for the Ping sensor so that it can be mobile with respect to the Boe-bot. You will need to do some soldering for this task. Your instructor will demonstrate.• Next you are to create a platform for the Ping sensor that is made from a small PC board and attach this to the side of the Boe-bot with screws and nuts. Again, your instructor will demonstrate.

Page 19: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 2

• Next, use your new Ping sensor board to create a program that will allow the Boe-bot to follow along a wall, at a specified distance from the wall (+- a small error amount) .• For example, the Boe-bot should be able to move parallel to a wall at a distance of 10cm (+- 2 cm) from the wall at all times. (See next slide) • If you finish early, modify your program so that the Boe-bot can navigate corners. That is, it should be able to reach a corner, turn, and continue wall following. (You may need to add other sensors to do this).

Page 20: PHY 235 Robotics Workshop Day 5 Distance Sensing Using The Ultrasonic Ping Sensor

Activity 2

10cm 8cm 12cm