![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
working version with calibration done
Fork of Eurobot2013 by
Sonar/RFSRF05.h@3:8c78c15a92e3, 2012-11-14 (annotated)
- Committer:
- xiaxia686
- Date:
- Wed Nov 14 15:48:20 2012 +0000
- Revision:
- 3:8c78c15a92e3
Merged with Sonar;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xiaxia686 | 3:8c78c15a92e3 | 1 | |
xiaxia686 | 3:8c78c15a92e3 | 2 | #ifndef MBED_RFSRF05_H |
xiaxia686 | 3:8c78c15a92e3 | 3 | #define MBED_RFSRF05_H |
xiaxia686 | 3:8c78c15a92e3 | 4 | |
xiaxia686 | 3:8c78c15a92e3 | 5 | |
xiaxia686 | 3:8c78c15a92e3 | 6 | |
xiaxia686 | 3:8c78c15a92e3 | 7 | #include "mbed.h" |
xiaxia686 | 3:8c78c15a92e3 | 8 | #include "RF12B.h" |
xiaxia686 | 3:8c78c15a92e3 | 9 | #include "globals.h" |
xiaxia686 | 3:8c78c15a92e3 | 10 | |
xiaxia686 | 3:8c78c15a92e3 | 11 | |
xiaxia686 | 3:8c78c15a92e3 | 12 | #define CODE0 0x22 |
xiaxia686 | 3:8c78c15a92e3 | 13 | #define CODE1 0x44 |
xiaxia686 | 3:8c78c15a92e3 | 14 | #define CODE2 0x88 |
xiaxia686 | 3:8c78c15a92e3 | 15 | |
xiaxia686 | 3:8c78c15a92e3 | 16 | /* SAMPLE IMPLEMENTATION! |
xiaxia686 | 3:8c78c15a92e3 | 17 | RFSRF05 my_srf(p13,p21,p22,p23,p24,p25,p26,p5,p6,p7,p8,p9); |
xiaxia686 | 3:8c78c15a92e3 | 18 | |
xiaxia686 | 3:8c78c15a92e3 | 19 | |
xiaxia686 | 3:8c78c15a92e3 | 20 | void callbinmain(int num, float dist) { |
xiaxia686 | 3:8c78c15a92e3 | 21 | //Here is where you deal with your brand new reading ;D |
xiaxia686 | 3:8c78c15a92e3 | 22 | } |
xiaxia686 | 3:8c78c15a92e3 | 23 | |
xiaxia686 | 3:8c78c15a92e3 | 24 | int main() { |
xiaxia686 | 3:8c78c15a92e3 | 25 | pc.printf("Hello World of RobotSonar!\r\n"); |
xiaxia686 | 3:8c78c15a92e3 | 26 | my_srf.callbackfunc = callbinmain; |
xiaxia686 | 3:8c78c15a92e3 | 27 | |
xiaxia686 | 3:8c78c15a92e3 | 28 | while (1); |
xiaxia686 | 3:8c78c15a92e3 | 29 | } |
xiaxia686 | 3:8c78c15a92e3 | 30 | |
xiaxia686 | 3:8c78c15a92e3 | 31 | */ |
xiaxia686 | 3:8c78c15a92e3 | 32 | |
xiaxia686 | 3:8c78c15a92e3 | 33 | class DummyCT; |
xiaxia686 | 3:8c78c15a92e3 | 34 | |
xiaxia686 | 3:8c78c15a92e3 | 35 | class RFSRF05 { |
xiaxia686 | 3:8c78c15a92e3 | 36 | public: |
xiaxia686 | 3:8c78c15a92e3 | 37 | |
xiaxia686 | 3:8c78c15a92e3 | 38 | RFSRF05( |
xiaxia686 | 3:8c78c15a92e3 | 39 | PinName trigger, |
xiaxia686 | 3:8c78c15a92e3 | 40 | PinName echo0, |
xiaxia686 | 3:8c78c15a92e3 | 41 | PinName echo1, |
xiaxia686 | 3:8c78c15a92e3 | 42 | PinName echo2, |
xiaxia686 | 3:8c78c15a92e3 | 43 | PinName echo3, |
xiaxia686 | 3:8c78c15a92e3 | 44 | PinName echo4, |
xiaxia686 | 3:8c78c15a92e3 | 45 | PinName echo5, |
xiaxia686 | 3:8c78c15a92e3 | 46 | PinName SDI, |
xiaxia686 | 3:8c78c15a92e3 | 47 | PinName SDO, |
xiaxia686 | 3:8c78c15a92e3 | 48 | PinName SCK, |
xiaxia686 | 3:8c78c15a92e3 | 49 | PinName NCS, |
xiaxia686 | 3:8c78c15a92e3 | 50 | PinName NIRQ); |
xiaxia686 | 3:8c78c15a92e3 | 51 | |
xiaxia686 | 3:8c78c15a92e3 | 52 | /** A non-blocking function that will return the last measurement |
xiaxia686 | 3:8c78c15a92e3 | 53 | * |
xiaxia686 | 3:8c78c15a92e3 | 54 | * @returns floating point representation of distance in mm |
xiaxia686 | 3:8c78c15a92e3 | 55 | */ |
xiaxia686 | 3:8c78c15a92e3 | 56 | float read0(); |
xiaxia686 | 3:8c78c15a92e3 | 57 | float read1(); |
xiaxia686 | 3:8c78c15a92e3 | 58 | float read2(); |
xiaxia686 | 3:8c78c15a92e3 | 59 | float read(unsigned int beaconnum); |
xiaxia686 | 3:8c78c15a92e3 | 60 | |
xiaxia686 | 3:8c78c15a92e3 | 61 | |
xiaxia686 | 3:8c78c15a92e3 | 62 | /** A assigns a callback function when a new reading is available **/ |
xiaxia686 | 3:8c78c15a92e3 | 63 | void (*callbackfunc)(int beaconnum, float distance); |
xiaxia686 | 3:8c78c15a92e3 | 64 | DummyCT* callbackobj; |
xiaxia686 | 3:8c78c15a92e3 | 65 | void (DummyCT::*mcallbackfunc)(int beaconnum, float distance); |
xiaxia686 | 3:8c78c15a92e3 | 66 | |
xiaxia686 | 3:8c78c15a92e3 | 67 | //triggers a read |
xiaxia686 | 3:8c78c15a92e3 | 68 | #ifndef ROBOT_PRIMARY |
xiaxia686 | 3:8c78c15a92e3 | 69 | void startRange(unsigned char rx_code); |
xiaxia686 | 3:8c78c15a92e3 | 70 | #endif |
xiaxia686 | 3:8c78c15a92e3 | 71 | |
xiaxia686 | 3:8c78c15a92e3 | 72 | //set codes |
xiaxia686 | 3:8c78c15a92e3 | 73 | void setCode(int code_index, unsigned char code); |
xiaxia686 | 3:8c78c15a92e3 | 74 | unsigned char codes[3]; |
xiaxia686 | 3:8c78c15a92e3 | 75 | |
xiaxia686 | 3:8c78c15a92e3 | 76 | /** A short hand way of using the read function */ |
xiaxia686 | 3:8c78c15a92e3 | 77 | //operator float(); |
xiaxia686 | 3:8c78c15a92e3 | 78 | |
xiaxia686 | 3:8c78c15a92e3 | 79 | private : |
xiaxia686 | 3:8c78c15a92e3 | 80 | RF12B _rf; |
xiaxia686 | 3:8c78c15a92e3 | 81 | DigitalOut _trigger; |
xiaxia686 | 3:8c78c15a92e3 | 82 | InterruptIn _echo0; |
xiaxia686 | 3:8c78c15a92e3 | 83 | InterruptIn _echo1; |
xiaxia686 | 3:8c78c15a92e3 | 84 | InterruptIn _echo2; |
xiaxia686 | 3:8c78c15a92e3 | 85 | InterruptIn _echo3; |
xiaxia686 | 3:8c78c15a92e3 | 86 | InterruptIn _echo4; |
xiaxia686 | 3:8c78c15a92e3 | 87 | InterruptIn _echo5; |
xiaxia686 | 3:8c78c15a92e3 | 88 | Timer _timer; |
xiaxia686 | 3:8c78c15a92e3 | 89 | Ticker _ticker; |
xiaxia686 | 3:8c78c15a92e3 | 90 | #ifdef ROBOT_PRIMARY |
xiaxia686 | 3:8c78c15a92e3 | 91 | void _startRange(void); |
xiaxia686 | 3:8c78c15a92e3 | 92 | #endif |
xiaxia686 | 3:8c78c15a92e3 | 93 | void _rising (void); |
xiaxia686 | 3:8c78c15a92e3 | 94 | void _falling (void); |
xiaxia686 | 3:8c78c15a92e3 | 95 | float _dist[3]; |
xiaxia686 | 3:8c78c15a92e3 | 96 | int _beacon_counter; |
xiaxia686 | 3:8c78c15a92e3 | 97 | bool ValidPulse; |
xiaxia686 | 3:8c78c15a92e3 | 98 | bool expValidPulse; |
xiaxia686 | 3:8c78c15a92e3 | 99 | |
xiaxia686 | 3:8c78c15a92e3 | 100 | }; |
xiaxia686 | 3:8c78c15a92e3 | 101 | |
xiaxia686 | 3:8c78c15a92e3 | 102 | #endif |