ZHAW specific RangeFinder class for ultra sonic range sensor (added offset in class to measure relative from top of board)

Dependencies:   Pulse

Dependents:   Grove-UltrasonicRanger_Example PM2_Libary PM2_Libary PM2_Libary

Committer:
pmic
Date:
Thu Feb 10 12:08:27 2022 +0000
Revision:
7:2865b7aec20c
Parent:
5:600591c78153
Minor adjustments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NickRyder 0:05c9036328ee 1 /* Copyright (c) 2012 Nick Ryder, University of Oxford
NickRyder 0:05c9036328ee 2 * nick.ryder@physics.ox.ac.uk
NickRyder 0:05c9036328ee 3 *
NickRyder 0:05c9036328ee 4 * MIT License
NickRyder 0:05c9036328ee 5 *
NickRyder 0:05c9036328ee 6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
NickRyder 0:05c9036328ee 7 * and associated documentation files (the "Software"), to deal in the Software without restriction,
NickRyder 0:05c9036328ee 8 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
NickRyder 0:05c9036328ee 9 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
NickRyder 0:05c9036328ee 10 * furnished to do so, subject to the following conditions:
NickRyder 0:05c9036328ee 11 *
NickRyder 0:05c9036328ee 12 * The above copyright notice and this permission notice shall be included in all copies or
NickRyder 0:05c9036328ee 13 * substantial portions of the Software.
NickRyder 0:05c9036328ee 14 *
NickRyder 0:05c9036328ee 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
NickRyder 0:05c9036328ee 16 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NickRyder 0:05c9036328ee 17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
NickRyder 0:05c9036328ee 18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
NickRyder 0:05c9036328ee 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
NickRyder 0:05c9036328ee 20 */
NickRyder 0:05c9036328ee 21
NickRyder 0:05c9036328ee 22 #ifndef MBED_RANGEFINDER_H
NickRyder 0:05c9036328ee 23 #define MBED_RANGEFINDER_H
NickRyder 0:05c9036328ee 24
NickRyder 0:05c9036328ee 25 #include "Pulse.h"
NickRyder 0:05c9036328ee 26
NickRyder 0:05c9036328ee 27 /** Range Finder class
NickRyder 0:05c9036328ee 28 */
NickRyder 0:05c9036328ee 29
pmic 3:cbb20cd7905d 30 class RangeFinder
pmic 3:cbb20cd7905d 31 {
NickRyder 0:05c9036328ee 32 public:
NickRyder 0:05c9036328ee 33 /** Create a RangeFinder object
NickRyder 0:05c9036328ee 34 * @param pin Digital I/O pin the range finder is connected to.
NickRyder 0:05c9036328ee 35 * @param pulsetime Time of pulse to send to the rangefinder to trigger a measurement, in microseconds.
pmic 2:89d7dd44ecfd 36 * @param scale Scaling of the range finder's output pulse from microseconds to meters.
pmic 2:89d7dd44ecfd 37 * @param offset Offset of the range finder's output pulse to adjust absolut reference.
NickRyder 0:05c9036328ee 38 * @param timeout Time to wait for a pulse from the range finder before giving up.
pmic 2:89d7dd44ecfd 39 * y = x/scale + offset
NickRyder 0:05c9036328ee 40 */
pmic 2:89d7dd44ecfd 41 RangeFinder(PinName pin, int pulsetime, float scale, float offset, int time);
pmic 5:600591c78153 42 RangeFinder(PinName pin, float scale, float offset, int time);
NickRyder 0:05c9036328ee 43 /** Return the distance to the nearest object, or -1.0 if reading the pulse timed out.
NickRyder 0:05c9036328ee 44 */
pmic 3:cbb20cd7905d 45 float operator()() {
pmic 5:600591c78153 46 return read_cm();
pmic 3:cbb20cd7905d 47 }
pmic 3:cbb20cd7905d 48
pmic 3:cbb20cd7905d 49 virtual ~RangeFinder();
pmic 3:cbb20cd7905d 50
pmic 5:600591c78153 51 float read_cm();
pmic 3:cbb20cd7905d 52
NickRyder 0:05c9036328ee 53 private:
pmic 3:cbb20cd7905d 54
NickRyder 0:05c9036328ee 55 PulseInOut pio;
pmic 3:cbb20cd7905d 56
pmic 2:89d7dd44ecfd 57 float scale, offset;
NickRyder 0:05c9036328ee 58 int pulsetime, timeout;
pmic 3:cbb20cd7905d 59
NickRyder 0:05c9036328ee 60 };
NickRyder 0:05c9036328ee 61
NickRyder 0:05c9036328ee 62 #endif