working version with calibration done

Fork of Eurobot2013 by Oskar Weigl

Committer:
xiaxia686
Date:
Sun Apr 07 16:30:49 2013 +0000
Revision:
10:2bd9f4e02b74
Parent:
Kalman/Sonar/RFSRF05.h@1:6799c07fe510
Child:
11:5ba926692210
Working version with no serial communication to the main board. The IR sensors uses mode for identification;

Who changed what in which revision?

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