test

Dependencies:   mbed ros_lib_kinetic nhk19mr2_can_info splitData SerialHalfDuplex_HM

Committer:
shimizuta
Date:
Mon Mar 11 10:38:07 2019 +0000
Revision:
50:36741e8ab197
a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimizuta 50:36741e8ab197 1 /* Copyright (c) 2013 Prabhu Desai
shimizuta 50:36741e8ab197 2 * pdtechworld@gmail.com
shimizuta 50:36741e8ab197 3 *
shimizuta 50:36741e8ab197 4 *
shimizuta 50:36741e8ab197 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
shimizuta 50:36741e8ab197 6 * and associated documentation files (the "Software"), to deal in the Software without restriction,
shimizuta 50:36741e8ab197 7 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
shimizuta 50:36741e8ab197 8 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
shimizuta 50:36741e8ab197 9 * furnished to do so, subject to the following conditions:
shimizuta 50:36741e8ab197 10 *
shimizuta 50:36741e8ab197 11 * The above copyright notice and this permission notice shall be included in all copies or
shimizuta 50:36741e8ab197 12 * substantial portions of the Software.
shimizuta 50:36741e8ab197 13 *
shimizuta 50:36741e8ab197 14 * For more details on the sensor :
shimizuta 50:36741e8ab197 15 * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3
shimizuta 50:36741e8ab197 16 *
shimizuta 50:36741e8ab197 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
shimizuta 50:36741e8ab197 18 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
shimizuta 50:36741e8ab197 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
shimizuta 50:36741e8ab197 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
shimizuta 50:36741e8ab197 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
shimizuta 50:36741e8ab197 22 */
shimizuta 50:36741e8ab197 23
shimizuta 50:36741e8ab197 24 #ifndef MBED_HCSR04_H
shimizuta 50:36741e8ab197 25 #define MBED_HCSR04_H
shimizuta 50:36741e8ab197 26
shimizuta 50:36741e8ab197 27 #include "mbed.h"
shimizuta 50:36741e8ab197 28
shimizuta 50:36741e8ab197 29 /** HCSR04 Class(es)
shimizuta 50:36741e8ab197 30 */
shimizuta 50:36741e8ab197 31
shimizuta 50:36741e8ab197 32 class HCSR04
shimizuta 50:36741e8ab197 33 {
shimizuta 50:36741e8ab197 34 public:
shimizuta 50:36741e8ab197 35 /** Create a HCSR04 object connected to the specified pin
shimizuta 50:36741e8ab197 36 * @param pin i/o pin to connect to
shimizuta 50:36741e8ab197 37 */
shimizuta 50:36741e8ab197 38 HCSR04(PinName TrigPin,PinName EchoPin);
shimizuta 50:36741e8ab197 39 ~HCSR04();
shimizuta 50:36741e8ab197 40
shimizuta 50:36741e8ab197 41 /** Return the distance from obstacle in cm
shimizuta 50:36741e8ab197 42 * @param distance in cms and returns -1, in case of failure
shimizuta 50:36741e8ab197 43 */
shimizuta 50:36741e8ab197 44 float get_dist_cm(void);
shimizuta 50:36741e8ab197 45 /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver.
shimizuta 50:36741e8ab197 46 * @param pulse duration in microseconds.
shimizuta 50:36741e8ab197 47 */
shimizuta 50:36741e8ab197 48 float get_pulse_us(void);
shimizuta 50:36741e8ab197 49 /** Generates the trigger pulse of 10us on the trigger PIN.
shimizuta 50:36741e8ab197 50 */
shimizuta 50:36741e8ab197 51 void start(void );
shimizuta 50:36741e8ab197 52 void isr_rise(void);
shimizuta 50:36741e8ab197 53 void isr_fall(void);
shimizuta 50:36741e8ab197 54 void fall (void (*fptr)(void));
shimizuta 50:36741e8ab197 55 void rise (void (*fptr)(void));
shimizuta 50:36741e8ab197 56
shimizuta 50:36741e8ab197 57
shimizuta 50:36741e8ab197 58
shimizuta 50:36741e8ab197 59 private:
shimizuta 50:36741e8ab197 60
shimizuta 50:36741e8ab197 61 Timer pulsetime;
shimizuta 50:36741e8ab197 62 DigitalOut trigger;
shimizuta 50:36741e8ab197 63 InterruptIn echo;
shimizuta 50:36741e8ab197 64 float pulsedur;
shimizuta 50:36741e8ab197 65 float distance;
shimizuta 50:36741e8ab197 66 };
shimizuta 50:36741e8ab197 67
shimizuta 50:36741e8ab197 68 #endif