Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed URF MD_MDDS30_oit_ ros_lib_melodic
URF.h@0:450a7208c682, 2022-05-03 (annotated)
- Committer:
- akihiron
- Date:
- Tue May 03 08:02:58 2022 +0000
- Revision:
- 0:450a7208c682
05/03
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| akihiron | 0:450a7208c682 | 1 | /* mbed URF Library |
| akihiron | 0:450a7208c682 | 2 | * Copyright (c) 2007-2010 rosienej |
| akihiron | 0:450a7208c682 | 3 | * |
| akihiron | 0:450a7208c682 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| akihiron | 0:450a7208c682 | 5 | * of this software and associated documentation files (the "Software"), to deal |
| akihiron | 0:450a7208c682 | 6 | * in the Software without restriction, including without limitation the rights |
| akihiron | 0:450a7208c682 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| akihiron | 0:450a7208c682 | 8 | * copies of the Software, and to permit persons to whom the Software is |
| akihiron | 0:450a7208c682 | 9 | * furnished to do so, subject to the following conditions: |
| akihiron | 0:450a7208c682 | 10 | * |
| akihiron | 0:450a7208c682 | 11 | * The above copyright notice and this permission notice shall be included in |
| akihiron | 0:450a7208c682 | 12 | * all copies or substantial portions of the Software. |
| akihiron | 0:450a7208c682 | 13 | * |
| akihiron | 0:450a7208c682 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| akihiron | 0:450a7208c682 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| akihiron | 0:450a7208c682 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| akihiron | 0:450a7208c682 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| akihiron | 0:450a7208c682 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| akihiron | 0:450a7208c682 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| akihiron | 0:450a7208c682 | 20 | * THE SOFTWARE. |
| akihiron | 0:450a7208c682 | 21 | */ |
| akihiron | 0:450a7208c682 | 22 | |
| akihiron | 0:450a7208c682 | 23 | #ifndef MBED_URF_H |
| akihiron | 0:450a7208c682 | 24 | #define MBED_URF_H |
| akihiron | 0:450a7208c682 | 25 | |
| akihiron | 0:450a7208c682 | 26 | #include "mbed.h" |
| akihiron | 0:450a7208c682 | 27 | /** URF class, based on an InterruptIn pin, and a timer |
| akihiron | 0:450a7208c682 | 28 | * works with the UltrasonicRangeFinder sensor (Parallax PING))), HC-SR04, etc...) |
| akihiron | 0:450a7208c682 | 29 | * |
| akihiron | 0:450a7208c682 | 30 | * Example: |
| akihiron | 0:450a7208c682 | 31 | * @code |
| akihiron | 0:450a7208c682 | 32 | * // Continuously send URFs and read the sensor |
| akihiron | 0:450a7208c682 | 33 | * #include "mbed.h" |
| akihiron | 0:450a7208c682 | 34 | * #include "URF.h" |
| akihiron | 0:450a7208c682 | 35 | * |
| akihiron | 0:450a7208c682 | 36 | * URF Ping(p21); |
| akihiron | 0:450a7208c682 | 37 | * |
| akihiron | 0:450a7208c682 | 38 | * int main() { |
| akihiron | 0:450a7208c682 | 39 | * int range; |
| akihiron | 0:450a7208c682 | 40 | |
| akihiron | 0:450a7208c682 | 41 | * while(1) { |
| akihiron | 0:450a7208c682 | 42 | * |
| akihiron | 0:450a7208c682 | 43 | * Ping.send(); |
| akihiron | 0:450a7208c682 | 44 | * wait_ms(30); |
| akihiron | 0:450a7208c682 | 45 | * range = Ping.read(mm); |
| akihiron | 0:450a7208c682 | 46 | * } |
| akihiron | 0:450a7208c682 | 47 | * } |
| akihiron | 0:450a7208c682 | 48 | * @endcode |
| akihiron | 0:450a7208c682 | 49 | */ |
| akihiron | 0:450a7208c682 | 50 | |
| akihiron | 0:450a7208c682 | 51 | #define mm 1000 |
| akihiron | 0:450a7208c682 | 52 | #define cm 100 |
| akihiron | 0:450a7208c682 | 53 | |
| akihiron | 0:450a7208c682 | 54 | class URF |
| akihiron | 0:450a7208c682 | 55 | { |
| akihiron | 0:450a7208c682 | 56 | public: |
| akihiron | 0:450a7208c682 | 57 | /** Create a URF object connected to the specified InterruptIn pin |
| akihiron | 0:450a7208c682 | 58 | * |
| akihiron | 0:450a7208c682 | 59 | * @param URF_PIN InterruptIn pin to connect to |
| akihiron | 0:450a7208c682 | 60 | */ |
| akihiron | 0:450a7208c682 | 61 | URF(PinName URF_PIN); |
| akihiron | 0:450a7208c682 | 62 | |
| akihiron | 0:450a7208c682 | 63 | /** Sends a URF |
| akihiron | 0:450a7208c682 | 64 | * |
| akihiron | 0:450a7208c682 | 65 | * @param none |
| akihiron | 0:450a7208c682 | 66 | */ |
| akihiron | 0:450a7208c682 | 67 | void send(void); |
| akihiron | 0:450a7208c682 | 68 | |
| akihiron | 0:450a7208c682 | 69 | /** Set the meter per second, default 334.0 m/s |
| akihiron | 0:450a7208c682 | 70 | * |
| akihiron | 0:450a7208c682 | 71 | * @param Meter per second in m/s |
| akihiron | 0:450a7208c682 | 72 | */ |
| akihiron | 0:450a7208c682 | 73 | void Set_MpS(float SoS_ms); |
| akihiron | 0:450a7208c682 | 74 | |
| akihiron | 0:450a7208c682 | 75 | /** Read the result in centimeters |
| akihiron | 0:450a7208c682 | 76 | * |
| akihiron | 0:450a7208c682 | 77 | * @param none |
| akihiron | 0:450a7208c682 | 78 | */ |
| akihiron | 0:450a7208c682 | 79 | int read(int scale); |
| akihiron | 0:450a7208c682 | 80 | int read(void); |
| akihiron | 0:450a7208c682 | 81 | |
| akihiron | 0:450a7208c682 | 82 | protected: |
| akihiron | 0:450a7208c682 | 83 | |
| akihiron | 0:450a7208c682 | 84 | InterruptIn _event; |
| akihiron | 0:450a7208c682 | 85 | DigitalInOut _cmd; |
| akihiron | 0:450a7208c682 | 86 | Timer _timer; |
| akihiron | 0:450a7208c682 | 87 | |
| akihiron | 0:450a7208c682 | 88 | // bool _Valid; |
| akihiron | 0:450a7208c682 | 89 | bool _Busy; |
| akihiron | 0:450a7208c682 | 90 | int _Time; |
| akihiron | 0:450a7208c682 | 91 | float _METER_PER_SECOND; /* in milliseconds */ |
| akihiron | 0:450a7208c682 | 92 | float _mm_per_us; |
| akihiron | 0:450a7208c682 | 93 | |
| akihiron | 0:450a7208c682 | 94 | void _start(void); |
| akihiron | 0:450a7208c682 | 95 | void _stop(void); |
| akihiron | 0:450a7208c682 | 96 | |
| akihiron | 0:450a7208c682 | 97 | }; |
| akihiron | 0:450a7208c682 | 98 | |
| akihiron | 0:450a7208c682 | 99 | #endif |