QuadroCopter  0.1.4
L3GD20H.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2017 Michael Brookes
3 
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef SRC_H_L3GD20H_H_
19 #define SRC_H_L3GD20H_H_
20 
21 #include "../../i2cDevice.h"
22 #include <pthread.h>
23 #include <unistd.h>
24 #include <functional>
25 #include <iostream>
26 #include <sys/types.h>
27 #include "../../../Timer/Timer.h"
28 
29 using namespace std;
30 
31 //From Table 17. of the L3GD20H Data sheet ( /lib/docs/L3GD20H.pdf )
32 #define GYRO_ADDRESS 0x6B
33 #define CTRL1 0x20
34 #define OUT_X_L 0x28
35 #define OUT_X_H 0x29
36 #define OUT_Y_L 0x2A
37 #define OUT_Y_H 0x2B
38 #define OUT_Z_L 0x2C
39 #define OUT_Z_H 0x2D
40 
41 #define DT 0.02
42 #define AA 0.97
43 
44 namespace quadro {
45 
46  namespace i2c {
47 
51  class L3GD20H : public i2cDevice {
52 
53  public:
54 
62  L3GD20H( unsigned char _deviceAddress = GYRO_ADDRESS, int _busId = 1 );
63 
71  int start();
72 
76  enum _switch {
77  ON = 0x7F,
78  OFF = 0x00
79  };
80 
84  template<typename T>
85  struct vector {
86  T x, y, z;
87  };
88 
91 
92  pthread_t threadHandle;
93 
94  protected:
95 
101  void setDeviceAddress( unsigned char _deviceAddress ) { this->deviceAddress = _deviceAddress; }
102 
108  void setBusId( int _busId ) { this->busId = _busId; }
109 
111 
118  int setPower( _switch gyroSwitch );
119 
125  void calcX( void );
126 
132  void calcY( void );
133 
139  void calcZ( void );
140 
149  static void* runMainSensorUpdateThread( void* static_inst );
150 
151  int threadRet;
152 
153  };
154 
155  }
156 }
157 
158 #endif /* SRC_H_L3GD20H_H_ */
void setDeviceAddress(unsigned char _deviceAddress)
Definition: L3GD20H.h:101
vector< int > rad
Gyroscope Radian vector (X, Y, Z)
Definition: L3GD20H.h:89
vector< float > angle
Gyroscope Angle Vector (X, Y, Z)
Definition: L3GD20H.h:90
Definition: i2cDevice.h:34
_switch gyroSwitch
enum value for the Gyroscope power status.
Definition: L3GD20H.h:110
void setBusId(int _busId)
Definition: L3GD20H.h:108
Definition: L3GD20H.h:51
Definition: L3GD20H.h:85
T z
Definition: L3GD20H.h:86
#define GYRO_ADDRESS
Definition: L3GD20H.h:32
Definition: aeronautics.h:23
_switch
Definition: L3GD20H.h:76