ROBOSTEP_5期 / Mbed 2 deprecated George_Master_Param

Dependencies:   mbed robot

Committer:
shimizuta
Date:
Mon May 27 04:50:42 2019 +0000
Revision:
58:dc0faefeba39
Parent:
22:0ed9de464f40
NHK finish

Who changed what in which revision?

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