Raspberry Pi with Java: Programming the Internet of Things (IoT) by Chin Stephen & Weaver James
Author:Chin, Stephen & Weaver, James [Chin, Stephen]
Language: eng
Format: epub
Publisher: McGraw-Hill Education
Published: 2015-10-23T04:00:00+00:00
FIGURE 5-16. Line runner in action (photo credit Bruno Borges)
Obstacle Detection
The last trick for our line runner is to teach it how to stop and wait for obstacles that obstruct the track. To accomplish this, we are going to use the Makeblock Me Ultrasonic Sensor. This sensor uses high-pitched sounds to detect the presence of and distance to a solid object in front of the sensor. It is accurate from 3cm to 4m, although the effective range of the sensor is limited by the speed and precision with which we can read and write to the digital pins on the Raspberry Pi.
The protocol for the Makeblock Me Ultrasonic Sensor is as follows. First, initialize the sensor by performing these steps:
1. Write a low value to the GPIO pin.
2. Wait 2 microseconds.
3. Write a high value to the GPIO pin.
4. Wait 10 microseconds.
5. Write a low value to the GPIO pin.
Read the sensor as follows:
1. Wait for it to go high.
2. Start a timer.
3. Wait for it go low.
4. Capture the pulse width in microseconds.
Once we have the pulse width of the sensor, we can use this to calculate the distance of the object. The distance in centimeters is calculated by dividing the pulse width by 58 as shown in the following formula:
Distance (cm) = Pulse Width (uS) / 58
At the minimum distance of 3cm for the sensor, this would require timings as precise as 174μs or .174ms. Unfortunately, the Raspberry Pi GPIO libraries cannot handle this resolution, so at this distance you will miss the pulse entirely. Using the fastest GPIO interface available, Pi4J raw mode, we can measure distances starting at around 20cm and up, which gives us an effective range of 20cm to 4m for the sensor. This is reasonable for obstacle avoidance, and is the range we will focus on.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Automotive | Engineering |
Transportation |
Whiskies Galore by Ian Buxton(41488)
Introduction to Aircraft Design (Cambridge Aerospace Series) by John P. Fielding(32850)
Small Unmanned Fixed-wing Aircraft Design by Andrew J. Keane Andras Sobester James P. Scanlan & András Sóbester & James P. Scanlan(32530)
Craft Beer for the Homebrewer by Michael Agnew(17902)
Turbulence by E. J. Noyes(7654)
The Complete Stick Figure Physics Tutorials by Allen Sarah(7090)
Kaplan MCAT General Chemistry Review by Kaplan(6545)
The Thirst by Nesbo Jo(6404)
Bad Blood by John Carreyrou(6244)
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6199)
Learning SQL by Alan Beaulieu(5988)
Weapons of Math Destruction by Cathy O'Neil(5775)
Man-made Catastrophes and Risk Information Concealment by Dmitry Chernov & Didier Sornette(5580)
Digital Minimalism by Cal Newport;(5319)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5140)
iGen by Jean M. Twenge(5125)
Secrets of Antigravity Propulsion: Tesla, UFOs, and Classified Aerospace Technology by Ph.D. Paul A. Laviolette(4857)
Design of Trajectory Optimization Approach for Space Maneuver Vehicle Skip Entry Problems by Runqi Chai & Al Savvaris & Antonios Tsourdos & Senchun Chai(4803)
Electronic Devices & Circuits by Jacob Millman & Christos C. Halkias(4695)
