Class to handle triggering and reading the distance measured by a range finder.
Dependents: SeeedUltrasoundRangeFinder Ultrasonic_sensor_circle_ui riversensor Labo_TRSE_Drone ... more
RangeFinder.h
00001 /* Copyright (c) 2012 Nick Ryder, University of Oxford 00002 * nick.ryder@physics.ox.ac.uk 00003 * 00004 * MIT License 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00007 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00008 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00009 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in all copies or 00013 * substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00016 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00017 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00018 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00020 */ 00021 00022 #ifndef MBED_RANGEFINDER_H 00023 #define MBED_RANGEFINDER_H 00024 00025 #include "Pulse.h" 00026 00027 /** Range Finder class 00028 */ 00029 00030 class RangeFinder { 00031 public: 00032 /** Create a RangeFinder object 00033 * @param pin Digital I/O pin the range finder is connected to. 00034 * @param pulsetime Time of pulse to send to the rangefinder to trigger a measurement, in microseconds. 00035 * @param scale Scaling of the range finder's output pulse from microseconds to metres. 00036 * @param timeout Time to wait for a pulse from the range finder before giving up. 00037 */ 00038 RangeFinder(PinName pin, int pulsetime, float scale, int timeout); 00039 ~RangeFinder(); 00040 /** Return the distance to the nearest object, or -1.0 if reading the pulse timed out. 00041 */ 00042 float read_m(); 00043 private: 00044 PulseInOut pio; 00045 float scale; 00046 int pulsetime, timeout; 00047 }; 00048 00049 #endif
Generated on Tue Jul 12 2022 12:27:23 by 1.7.2