branch for tests with T265
Dependencies: Lib_Cntrl AHRS Lib_Misc
Xtra_Sensors/RangeFinder.h@4:dc844fde64d7, 2019-11-22 (annotated)
- Committer:
- Kiwicjam
- Date:
- Fri Nov 22 08:40:26 2019 +0000
- Revision:
- 4:dc844fde64d7
- Parent:
- 2:e7874762cc25
Workin set, not running,
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 2:e7874762cc25 | 1 | /* Copyright (c) 2012 Nick Ryder, University of Oxford |
altb2 | 2:e7874762cc25 | 2 | * nick.ryder@physics.ox.ac.uk |
altb2 | 2:e7874762cc25 | 3 | * |
altb2 | 2:e7874762cc25 | 4 | * MIT License |
altb2 | 2:e7874762cc25 | 5 | * |
altb2 | 2:e7874762cc25 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
altb2 | 2:e7874762cc25 | 7 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
altb2 | 2:e7874762cc25 | 8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
altb2 | 2:e7874762cc25 | 9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
altb2 | 2:e7874762cc25 | 10 | * furnished to do so, subject to the following conditions: |
altb2 | 2:e7874762cc25 | 11 | * |
altb2 | 2:e7874762cc25 | 12 | * The above copyright notice and this permission notice shall be included in all copies or |
altb2 | 2:e7874762cc25 | 13 | * substantial portions of the Software. |
altb2 | 2:e7874762cc25 | 14 | * |
altb2 | 2:e7874762cc25 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
altb2 | 2:e7874762cc25 | 16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
altb2 | 2:e7874762cc25 | 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
altb2 | 2:e7874762cc25 | 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
altb2 | 2:e7874762cc25 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
altb2 | 2:e7874762cc25 | 20 | */ |
altb2 | 2:e7874762cc25 | 21 | |
altb2 | 2:e7874762cc25 | 22 | #ifndef MBED_RANGEFINDER_H |
altb2 | 2:e7874762cc25 | 23 | #define MBED_RANGEFINDER_H |
altb2 | 2:e7874762cc25 | 24 | |
altb2 | 2:e7874762cc25 | 25 | #include "Pulse.h" |
altb2 | 2:e7874762cc25 | 26 | |
altb2 | 2:e7874762cc25 | 27 | /** Range Finder class |
altb2 | 2:e7874762cc25 | 28 | */ |
altb2 | 2:e7874762cc25 | 29 | |
altb2 | 2:e7874762cc25 | 30 | class RangeFinder { |
altb2 | 2:e7874762cc25 | 31 | public: |
altb2 | 2:e7874762cc25 | 32 | /** Create a RangeFinder object |
altb2 | 2:e7874762cc25 | 33 | * @param pin Digital I/O pin the range finder is connected to. |
altb2 | 2:e7874762cc25 | 34 | * @param pulsetime Time of pulse to send to the rangefinder to trigger a measurement, in microseconds. |
altb2 | 2:e7874762cc25 | 35 | * @param scale Scaling of the range finder's output pulse from microseconds to meters. |
altb2 | 2:e7874762cc25 | 36 | * @param offset Offset of the range finder's output pulse to adjust absolut reference. |
altb2 | 2:e7874762cc25 | 37 | * @param timeout Time to wait for a pulse from the range finder before giving up. |
altb2 | 2:e7874762cc25 | 38 | * y = x/scale + offset |
altb2 | 2:e7874762cc25 | 39 | */ |
altb2 | 2:e7874762cc25 | 40 | RangeFinder(PinName pin0, int pulsetime, float scale, float offset, int time); // 1 Sensor |
altb2 | 2:e7874762cc25 | 41 | RangeFinder(PinName pin0,PinName pin1, int pulsetime, float scale, float offset, int time); // 2 Sensors |
altb2 | 2:e7874762cc25 | 42 | RangeFinder(PinName pin0,PinName pin1,PinName pin2, int pulsetime, float scale, float offset, int time); // 3 Sensors |
altb2 | 2:e7874762cc25 | 43 | RangeFinder(PinName pin0,PinName pin1,PinName pin2,PinName pin3, int pulsetime, float scale, float offset, int time); // 4 Sensors |
altb2 | 2:e7874762cc25 | 44 | ~RangeFinder(); |
altb2 | 2:e7874762cc25 | 45 | /** Return the distance to the nearest object, or -1.0 if reading the pulse timed out. |
altb2 | 2:e7874762cc25 | 46 | */ |
altb2 | 2:e7874762cc25 | 47 | float read_m(uint8_t); |
altb2 | 2:e7874762cc25 | 48 | void read_and_filter(uint8_t); |
altb2 | 2:e7874762cc25 | 49 | float operator()(uint8_t i) { |
altb2 | 2:e7874762cc25 | 50 | return read_m(i); |
altb2 | 2:e7874762cc25 | 51 | } |
altb2 | 2:e7874762cc25 | 52 | float old_val[5]; |
altb2 | 2:e7874762cc25 | 53 | float val[5]; |
altb2 | 2:e7874762cc25 | 54 | uint8_t current_sensor; |
altb2 | 2:e7874762cc25 | 55 | uint8_t n_sensors; |
altb2 | 2:e7874762cc25 | 56 | private: |
altb2 | 2:e7874762cc25 | 57 | PulseInOut pio0; |
altb2 | 2:e7874762cc25 | 58 | PulseInOut pio1; |
altb2 | 2:e7874762cc25 | 59 | PulseInOut pio2; |
altb2 | 2:e7874762cc25 | 60 | PulseInOut pio3; |
altb2 | 2:e7874762cc25 | 61 | float scale, offset; |
altb2 | 2:e7874762cc25 | 62 | int pulsetime, timeout; |
altb2 | 2:e7874762cc25 | 63 | |
altb2 | 2:e7874762cc25 | 64 | }; |
altb2 | 2:e7874762cc25 | 65 | |
altb2 | 2:e7874762cc25 | 66 | #endif |