Ryota Kotani / Mbed 2 deprecated ROS_R2_YONRIN

Dependencies:   mbed URF MD_MDDS30_oit_ ros_lib_melodic

URF.h

Committer:
akihiron
Date:
2022-05-03
Revision:
0:450a7208c682

File content as of revision 0:450a7208c682:

/* mbed URF Library
 * Copyright (c) 2007-2010 rosienej
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef MBED_URF_H
#define MBED_URF_H

#include "mbed.h"
/** URF class, based on an InterruptIn pin, and a timer
 *  works with the UltrasonicRangeFinder sensor (Parallax PING))), HC-SR04, etc...)
 *
 * Example:
 * @code
 * // Continuously send URFs and read the sensor
 * #include "mbed.h"
 * #include "URF.h"
 *
 * URF Ping(p21);
 *
 * int main() {
 *     int range;

 *     while(1) {
 *
 *        Ping.send();
 *        wait_ms(30);
 *        range = Ping.read(mm);
 *     }
 * }
 * @endcode
 */

#define mm 1000
#define cm 100

class URF
{
public:
    /** Create a URF object connected to the specified InterruptIn pin
     *
     * @param URF_PIN InterruptIn pin to connect to
     */
    URF(PinName URF_PIN);

    /** Sends a URF
     *
     * @param none
     */
    void send(void);

    /** Set the meter per second, default 334.0 m/s
     *
     * @param Meter per second in m/s
     */
    void Set_MpS(float SoS_ms);

    /** Read the result in centimeters
      *
      * @param none
      */
    int read(int scale);
    int read(void);

protected:

    InterruptIn     _event;
    DigitalInOut    _cmd;
    Timer           _timer;

//    bool  _Valid;
    bool  _Busy;
    int   _Time;
    float _METER_PER_SECOND; /* in milliseconds */
    float _mm_per_us;

    void  _start(void);
    void  _stop(void);

};

#endif