PAW_Sensor: This library control the PAW sensor. This library get sensor values from the PAW sensor, and send these values to PC through serial-communication. And you need to convert these values to delta h using some module on PC. I create sample python module for this library. If you want to get this module, please access below page, https://github.com/HiroakiMatsuda/PAW-Sensor The PAW Sensor is developed by RT. If you need to get information about this sensors, please access below page. http://www.rt-shop.jp/index.php?main_page=product_info&cPath=42&products_id=1303
Dependents: PAW_Sensor_HelloWorld
paw.h@0:ebd7c54059ae, 2014-11-09 (annotated)
- Committer:
- matsu
- Date:
- Sun Nov 09 08:13:22 2014 +0000
- Revision:
- 0:ebd7c54059ae
- Child:
- 1:6ec3794072de
Fist upload.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matsu | 0:ebd7c54059ae | 1 | /* mbed PAW_Sensor Library |
matsu | 0:ebd7c54059ae | 2 | * |
matsu | 0:ebd7c54059ae | 3 | * paw.h |
matsu | 0:ebd7c54059ae | 4 | * |
matsu | 0:ebd7c54059ae | 5 | * Copyright (c) 2014 Hiroaki Matsuda |
matsu | 0:ebd7c54059ae | 6 | * |
matsu | 0:ebd7c54059ae | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
matsu | 0:ebd7c54059ae | 8 | * of this software and associated documentation files (the "Software"), to deal |
matsu | 0:ebd7c54059ae | 9 | * in the Software without restriction, including without limitation the rights |
matsu | 0:ebd7c54059ae | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
matsu | 0:ebd7c54059ae | 11 | * copies of the Software, and to permit persons to whom the Software is |
matsu | 0:ebd7c54059ae | 12 | * furnished to do so, subject to the following conditions: |
matsu | 0:ebd7c54059ae | 13 | * |
matsu | 0:ebd7c54059ae | 14 | * The above copyright notice and this permission notice shall be included in |
matsu | 0:ebd7c54059ae | 15 | * all copies or substantial portions of the Software. |
matsu | 0:ebd7c54059ae | 16 | * |
matsu | 0:ebd7c54059ae | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
matsu | 0:ebd7c54059ae | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
matsu | 0:ebd7c54059ae | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
matsu | 0:ebd7c54059ae | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
matsu | 0:ebd7c54059ae | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
matsu | 0:ebd7c54059ae | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
matsu | 0:ebd7c54059ae | 23 | * THE SOFTWARE. |
matsu | 0:ebd7c54059ae | 24 | */ |
matsu | 0:ebd7c54059ae | 25 | |
matsu | 0:ebd7c54059ae | 26 | #ifndef PAW_H |
matsu | 0:ebd7c54059ae | 27 | #define PAW_H |
matsu | 0:ebd7c54059ae | 28 | |
matsu | 0:ebd7c54059ae | 29 | #include "mbed.h" |
matsu | 0:ebd7c54059ae | 30 | |
matsu | 0:ebd7c54059ae | 31 | #define STATE_1 0 |
matsu | 0:ebd7c54059ae | 32 | #define STATE_2 1 |
matsu | 0:ebd7c54059ae | 33 | #define STATE_3 2 |
matsu | 0:ebd7c54059ae | 34 | #define STATE_4 3 |
matsu | 0:ebd7c54059ae | 35 | |
matsu | 0:ebd7c54059ae | 36 | |
matsu | 0:ebd7c54059ae | 37 | /** PAW_Sensor Library |
matsu | 0:ebd7c54059ae | 38 | * |
matsu | 0:ebd7c54059ae | 39 | * Example: |
matsu | 0:ebd7c54059ae | 40 | * @code |
matsu | 0:ebd7c54059ae | 41 | * |
matsu | 0:ebd7c54059ae | 42 | #include "mbed.h" |
matsu | 0:ebd7c54059ae | 43 | #include "paw.h" |
matsu | 0:ebd7c54059ae | 44 | |
matsu | 0:ebd7c54059ae | 45 | Serial pc( USBTX, USBRX ); |
matsu | 0:ebd7c54059ae | 46 | const unsigned long baudrate = 115200; |
matsu | 0:ebd7c54059ae | 47 | |
matsu | 0:ebd7c54059ae | 48 | // paw( LED1, LED2, PHOTO1, PHOTO2 ) |
matsu | 0:ebd7c54059ae | 49 | PAW paw( p8, p9, p16, p17 ); |
matsu | 0:ebd7c54059ae | 50 | paw_value g_value; |
matsu | 0:ebd7c54059ae | 51 | |
matsu | 0:ebd7c54059ae | 52 | PAW paw_2( p10, p11, p18, p19 ); |
matsu | 0:ebd7c54059ae | 53 | paw_value g_value_2; |
matsu | 0:ebd7c54059ae | 54 | |
matsu | 0:ebd7c54059ae | 55 | Ticker run; |
matsu | 0:ebd7c54059ae | 56 | |
matsu | 0:ebd7c54059ae | 57 | |
matsu | 0:ebd7c54059ae | 58 | void run_paw_sensor() |
matsu | 0:ebd7c54059ae | 59 | { |
matsu | 0:ebd7c54059ae | 60 | if( paw.process_paw() == STATE_1 ) |
matsu | 0:ebd7c54059ae | 61 | { |
matsu | 0:ebd7c54059ae | 62 | paw.print( &pc ); |
matsu | 0:ebd7c54059ae | 63 | } |
matsu | 0:ebd7c54059ae | 64 | } |
matsu | 0:ebd7c54059ae | 65 | |
matsu | 0:ebd7c54059ae | 66 | int main() |
matsu | 0:ebd7c54059ae | 67 | { |
matsu | 0:ebd7c54059ae | 68 | // Initializing Serial Communication |
matsu | 0:ebd7c54059ae | 69 | pc.baud( baudrate ); |
matsu | 0:ebd7c54059ae | 70 | pc.format( 8, Serial::None, 1 ); |
matsu | 0:ebd7c54059ae | 71 | |
matsu | 0:ebd7c54059ae | 72 | run.attach_us(&run_paw_sensor, 500); |
matsu | 0:ebd7c54059ae | 73 | |
matsu | 0:ebd7c54059ae | 74 | while(1); |
matsu | 0:ebd7c54059ae | 75 | } |
matsu | 0:ebd7c54059ae | 76 | |
matsu | 0:ebd7c54059ae | 77 | * @endcode |
matsu | 0:ebd7c54059ae | 78 | */ |
matsu | 0:ebd7c54059ae | 79 | |
matsu | 0:ebd7c54059ae | 80 | struct paw_value |
matsu | 0:ebd7c54059ae | 81 | { |
matsu | 0:ebd7c54059ae | 82 | public: |
matsu | 0:ebd7c54059ae | 83 | short ch_1; |
matsu | 0:ebd7c54059ae | 84 | short ch_2; |
matsu | 0:ebd7c54059ae | 85 | short ch_3; |
matsu | 0:ebd7c54059ae | 86 | short ch_4; |
matsu | 0:ebd7c54059ae | 87 | short initial_photo_1; |
matsu | 0:ebd7c54059ae | 88 | short initial_photo_2; |
matsu | 0:ebd7c54059ae | 89 | |
matsu | 0:ebd7c54059ae | 90 | paw_value() |
matsu | 0:ebd7c54059ae | 91 | { |
matsu | 0:ebd7c54059ae | 92 | ch_1 = 0; |
matsu | 0:ebd7c54059ae | 93 | ch_2 = 0; |
matsu | 0:ebd7c54059ae | 94 | ch_3 = 0; |
matsu | 0:ebd7c54059ae | 95 | ch_4 = 0; |
matsu | 0:ebd7c54059ae | 96 | initial_photo_1 = 0; |
matsu | 0:ebd7c54059ae | 97 | initial_photo_2 = 0; |
matsu | 0:ebd7c54059ae | 98 | } |
matsu | 0:ebd7c54059ae | 99 | }; |
matsu | 0:ebd7c54059ae | 100 | |
matsu | 0:ebd7c54059ae | 101 | class PAW { |
matsu | 0:ebd7c54059ae | 102 | |
matsu | 0:ebd7c54059ae | 103 | public: |
matsu | 0:ebd7c54059ae | 104 | |
matsu | 0:ebd7c54059ae | 105 | /** Create a PAW Sensor instance |
matsu | 0:ebd7c54059ae | 106 | * |
matsu | 0:ebd7c54059ae | 107 | * @param led_1 PAW Sensor's Pin 5 |
matsu | 0:ebd7c54059ae | 108 | * @param led_2 PAW Sensor's Pin 4 |
matsu | 0:ebd7c54059ae | 109 | * @param photo_1 PAW Sensor's Pin 3 |
matsu | 0:ebd7c54059ae | 110 | * @param photo_2 PAW Sensor's Pin 2 |
matsu | 0:ebd7c54059ae | 111 | */ |
matsu | 0:ebd7c54059ae | 112 | PAW( PinName led_1, PinName led_2, PinName photo_1, PinName photo_2 ); |
matsu | 0:ebd7c54059ae | 113 | |
matsu | 0:ebd7c54059ae | 114 | /** Get values of PAW Sensor |
matsu | 0:ebd7c54059ae | 115 | * |
matsu | 0:ebd7c54059ae | 116 | * @return Return values of photosensor's voltage. |
matsu | 0:ebd7c54059ae | 117 | */ |
matsu | 0:ebd7c54059ae | 118 | paw_value get_value(); |
matsu | 0:ebd7c54059ae | 119 | |
matsu | 0:ebd7c54059ae | 120 | /** Processing of Paw sensor. This fucntion must be performed periodically. |
matsu | 0:ebd7c54059ae | 121 | * |
matsu | 0:ebd7c54059ae | 122 | * @return Return current processing-state. |
matsu | 0:ebd7c54059ae | 123 | */ |
matsu | 0:ebd7c54059ae | 124 | unsigned char process_paw(); |
matsu | 0:ebd7c54059ae | 125 | |
matsu | 0:ebd7c54059ae | 126 | /** Get current processing-state. |
matsu | 0:ebd7c54059ae | 127 | * |
matsu | 0:ebd7c54059ae | 128 | * @return Return current processing-state. |
matsu | 0:ebd7c54059ae | 129 | */ |
matsu | 0:ebd7c54059ae | 130 | bool get_state(); |
matsu | 0:ebd7c54059ae | 131 | |
matsu | 0:ebd7c54059ae | 132 | /** Send values of PAW Sensor through serial-communication. |
matsu | 0:ebd7c54059ae | 133 | * |
matsu | 0:ebd7c54059ae | 134 | * @param Reference to serial object. |
matsu | 0:ebd7c54059ae | 135 | */ |
matsu | 0:ebd7c54059ae | 136 | void print( Serial* ); |
matsu | 0:ebd7c54059ae | 137 | |
matsu | 0:ebd7c54059ae | 138 | protected: |
matsu | 0:ebd7c54059ae | 139 | DigitalOut _led_1; |
matsu | 0:ebd7c54059ae | 140 | DigitalOut _led_2; |
matsu | 0:ebd7c54059ae | 141 | AnalogIn _photo_1; |
matsu | 0:ebd7c54059ae | 142 | AnalogIn _photo_2; |
matsu | 0:ebd7c54059ae | 143 | |
matsu | 0:ebd7c54059ae | 144 | unsigned char _state; |
matsu | 0:ebd7c54059ae | 145 | |
matsu | 0:ebd7c54059ae | 146 | paw_value _value; |
matsu | 0:ebd7c54059ae | 147 | }; |
matsu | 0:ebd7c54059ae | 148 | |
matsu | 0:ebd7c54059ae | 149 | #endif /*** PAW_H ***/ |