Dependencies:   mbed PID

Committer:
narshu
Date:
Wed Feb 29 17:50:49 2012 +0000
Revision:
0:c8c04928d025
Primary Robot with Sonar function - needs PID tuning for motor control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
narshu 0:c8c04928d025 1 /* mbed SRF05 Ultrasonic Rangefiner Library
narshu 0:c8c04928d025 2 * Copyright (c) 2007-2010, cstyles, sford
narshu 0:c8c04928d025 3 *
narshu 0:c8c04928d025 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
narshu 0:c8c04928d025 5 * of this software and associated documentation files (the "Software"), to deal
narshu 0:c8c04928d025 6 * in the Software without restriction, including without limitation the rights
narshu 0:c8c04928d025 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
narshu 0:c8c04928d025 8 * copies of the Software, and to permit persons to whom the Software is
narshu 0:c8c04928d025 9 * furnished to do so, subject to the following conditions:
narshu 0:c8c04928d025 10 *
narshu 0:c8c04928d025 11 * The above copyright notice and this permission notice shall be included in
narshu 0:c8c04928d025 12 * all copies or substantial portions of the Software.
narshu 0:c8c04928d025 13 *
narshu 0:c8c04928d025 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
narshu 0:c8c04928d025 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
narshu 0:c8c04928d025 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
narshu 0:c8c04928d025 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
narshu 0:c8c04928d025 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
narshu 0:c8c04928d025 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
narshu 0:c8c04928d025 20 * THE SOFTWARE.
narshu 0:c8c04928d025 21 */
narshu 0:c8c04928d025 22
narshu 0:c8c04928d025 23 #ifndef MBED_SRF05_H
narshu 0:c8c04928d025 24 #define MBED_SRF05_H
narshu 0:c8c04928d025 25
narshu 0:c8c04928d025 26 #include "mbed.h"
narshu 0:c8c04928d025 27
narshu 0:c8c04928d025 28 extern volatile char SendByte;
narshu 0:c8c04928d025 29
narshu 0:c8c04928d025 30 /** Library for the SRF05 Ultrasonic range finder
narshu 0:c8c04928d025 31 *
narshu 0:c8c04928d025 32 * Example:
narshu 0:c8c04928d025 33 * @code
narshu 0:c8c04928d025 34 * // Print measured distance
narshu 0:c8c04928d025 35 *
narshu 0:c8c04928d025 36 * #include "mbed.h"
narshu 0:c8c04928d025 37 * #include "SRF05.h"
narshu 0:c8c04928d025 38 *
narshu 0:c8c04928d025 39 * SRF05 srf(p9,p10);
narshu 0:c8c04928d025 40 *
narshu 0:c8c04928d025 41 * int main() {
narshu 0:c8c04928d025 42 * while(1) {
narshu 0:c8c04928d025 43 * printf("Measured : %.1f\n", srf.read());
narshu 0:c8c04928d025 44 * wait(0.2);
narshu 0:c8c04928d025 45 * }
narshu 0:c8c04928d025 46 * }
narshu 0:c8c04928d025 47 * @endcode
narshu 0:c8c04928d025 48 */
narshu 0:c8c04928d025 49 class SRF05 {
narshu 0:c8c04928d025 50 public:
narshu 0:c8c04928d025 51
narshu 0:c8c04928d025 52 /** Create a SRF05 object, connected to the specified pins
narshu 0:c8c04928d025 53 *
narshu 0:c8c04928d025 54 * @param trigger DigitalOut to the SRF05 trigger
narshu 0:c8c04928d025 55 * @param echo InterruptIn to measure the return pulse
narshu 0:c8c04928d025 56 */
narshu 0:c8c04928d025 57 SRF05(PinName trigger, PinName echo);
narshu 0:c8c04928d025 58
narshu 0:c8c04928d025 59 /** A non-blocking function that will return the last measurement
narshu 0:c8c04928d025 60 *
narshu 0:c8c04928d025 61 * @returns floating point representation of distance in cm
narshu 0:c8c04928d025 62 */
narshu 0:c8c04928d025 63 float read();
narshu 0:c8c04928d025 64
narshu 0:c8c04928d025 65 // Trigs the ranger
narshu 0:c8c04928d025 66 void trig();
narshu 0:c8c04928d025 67
narshu 0:c8c04928d025 68 /** A short hand way of using the read function */
narshu 0:c8c04928d025 69 operator float();
narshu 0:c8c04928d025 70
narshu 0:c8c04928d025 71 private :
narshu 0:c8c04928d025 72 DigitalOut _trigger;
narshu 0:c8c04928d025 73 InterruptIn _echo;
narshu 0:c8c04928d025 74 Timer _timer;
narshu 0:c8c04928d025 75 Ticker _ticker;
narshu 0:c8c04928d025 76 void _rising (void);
narshu 0:c8c04928d025 77 void _falling (void);
narshu 0:c8c04928d025 78 // void _startRange (void);
narshu 0:c8c04928d025 79 float _dist;
narshu 0:c8c04928d025 80 };
narshu 0:c8c04928d025 81
narshu 0:c8c04928d025 82 #endif