![](/media/cache/profiles/8ad6635f33710af6a535e8fb8486975e.50x50_q85.jpg)
NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.
Sensors/I2C_Sensor.h@34:3aa1cbcde59d, 2013-06-10 (annotated)
- Committer:
- maetugr
- Date:
- Mon Jun 10 13:22:46 2013 +0000
- Revision:
- 34:3aa1cbcde59d
- Child:
- 36:128c55793728
First version with new ESCs (they are working with the KK Board); some strange kicks in the behaviour of balancing, next step a logger
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 34:3aa1cbcde59d | 1 | // by MaEtUgR |
maetugr | 34:3aa1cbcde59d | 2 | |
maetugr | 34:3aa1cbcde59d | 3 | #ifndef I2C_Sensor_H |
maetugr | 34:3aa1cbcde59d | 4 | #define I2C_Sensor_H |
maetugr | 34:3aa1cbcde59d | 5 | |
maetugr | 34:3aa1cbcde59d | 6 | #include "mbed.h" |
maetugr | 34:3aa1cbcde59d | 7 | |
maetugr | 34:3aa1cbcde59d | 8 | class I2C_Sensor |
maetugr | 34:3aa1cbcde59d | 9 | { |
maetugr | 34:3aa1cbcde59d | 10 | public: |
maetugr | 34:3aa1cbcde59d | 11 | I2C_Sensor(PinName sda, PinName scl, char address); |
maetugr | 34:3aa1cbcde59d | 12 | |
maetugr | 34:3aa1cbcde59d | 13 | float data[3]; // where the measured data is saved |
maetugr | 34:3aa1cbcde59d | 14 | virtual void read() = 0; // read all axis from register to array data |
maetugr | 34:3aa1cbcde59d | 15 | //TODO: virtual void calibrate() = 0; // calibrate the sensor and if desired write calibration values to a file |
maetugr | 34:3aa1cbcde59d | 16 | |
maetugr | 34:3aa1cbcde59d | 17 | protected: |
maetugr | 34:3aa1cbcde59d | 18 | // Calibration |
maetugr | 34:3aa1cbcde59d | 19 | void saveCalibrationValues(float values[], int size, char * filename); |
maetugr | 34:3aa1cbcde59d | 20 | void loadCalibrationValues(float values[], int size, char * filename); |
maetugr | 34:3aa1cbcde59d | 21 | |
maetugr | 34:3aa1cbcde59d | 22 | // I2C functions |
maetugr | 34:3aa1cbcde59d | 23 | char readRegister(char reg); |
maetugr | 34:3aa1cbcde59d | 24 | void writeRegister(char reg, char data); |
maetugr | 34:3aa1cbcde59d | 25 | void readMultiRegister(char reg, char* output, int size); |
maetugr | 34:3aa1cbcde59d | 26 | |
maetugr | 34:3aa1cbcde59d | 27 | // raw data and function to measure it |
maetugr | 34:3aa1cbcde59d | 28 | int raw[3]; |
maetugr | 34:3aa1cbcde59d | 29 | virtual void readraw() = 0; |
maetugr | 34:3aa1cbcde59d | 30 | |
maetugr | 34:3aa1cbcde59d | 31 | private: |
maetugr | 34:3aa1cbcde59d | 32 | I2C i2c; // I2C-Bus |
maetugr | 34:3aa1cbcde59d | 33 | char i2c_address; // address |
maetugr | 34:3aa1cbcde59d | 34 | |
maetugr | 34:3aa1cbcde59d | 35 | LocalFileSystem local; // file access to save calibration values |
maetugr | 34:3aa1cbcde59d | 36 | }; |
maetugr | 34:3aa1cbcde59d | 37 | |
maetugr | 34:3aa1cbcde59d | 38 | #endif |