Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ITG3200.h
Go to the documentation of this file.
1 /*
2  * ITG3200Gyroscope.h Created on: 2 Jul 2014
3  * Copyright (c) 2014 Derek Molloy (www.derekmolloy.ie)
4  * Made available for the book "Exploring BeagleBone"
5  * See: www.exploringbeaglebone.com
6  * Licensed under the EUPL V.1.1
7  *
8  * This Software is provided to You under the terms of the European
9  * Union Public License (the "EUPL") version 1.1 as published by the
10  * European Union. Any use of this Software, other than as authorized
11  * under this License is strictly prohibited (to the extent such use
12  * is covered by a right of the copyright holder of this Software).
13  *
14  * This Software is provided under the License on an "AS IS" basis and
15  * without warranties of any kind concerning the Software, including
16  * without limitation merchantability, fitness for a particular purpose,
17  * absence of defects or errors, accuracy, and non-infringement of
18  * intellectual property rights other than copyright. This disclaimer
19  * of warranty is an essential part of the License and a condition for
20  * the grant of any rights to this Software.
21  *
22  * For more details, see http://www.derekmolloy.ie/
23  */
24 
25 #ifndef ITG3200GYROSCOPE_H_
26 #define ITG3200GYROSCOPE_H_
27 
28 #include "../bus/BusDevice.h"
29 
30 #define BUFFER_SIZE 0x3E
31 #define SENSITIVITY 14.375 //LSBs per degree
32 
33 namespace exploringBB {
34 
39 class ITG3200 {
40 
41  // This is required for the DLPF_CFG value - Digital low-pass filter configuration
42  enum ITG3200_LPFILTER {
43  LP_256HZ = 0, // sets internal sampling rate Fs to be 8kHz
44  LP_188HZ = 1, // sets internal sampling rate Fs to be 1kHz
45  LP_98HZ = 2, // sets internal sampling rate Fs to be 1kHz
46  LP_42HZ = 3, // sets internal sampling rate Fs to be 1kHz
47  LP_20HZ = 4, // sets internal sampling rate Fs to be 1kHz
48  LP_10HZ = 5, // sets internal sampling rate Fs to be 1kHz
49  LP_5HZ = 6 // sets internal sampling rate Fs to be 1kHz
50  // 7 is a reserved value
51  };
52 
53 private:
54  BusDevice *device;
55  unsigned char *registers;
56  float gyroscope[3];
57  float offsets[3];
58  int temperature;
59 
60 public:
61 
62  ITG3200(BusDevice *device);
63 
64  float getGyroscopeRoll() { return gyroscope[0]/SENSITIVITY; }
65  float getGyroscopePitch() { return gyroscope[1]/SENSITIVITY; }
66  float getGyroscopeYaw() { return gyroscope[2]/SENSITIVITY; }
67 
68  float getOffsetRollOffset() { return offsets[0]/SENSITIVITY; }
69  float getOffsetPitchOffset() { return offsets[1]/SENSITIVITY; }
70  float getOffsetYawOffset() { return offsets[2]/SENSITIVITY; }
71 
72  int getTemperature() { return temperature; }
73 
74  virtual ~ITG3200();
75 
76 public:
77  int readFullSensorState();
78  int convertGyroscopeValue(int msb_reg_addr, int lsb_reg_addr);
79  int setDigitalLowPassFilter(ITG3200_LPFILTER filterValue);
80  int setSampleRateDivider(char divider);
81  int zeroCalibrate(int numberSamples, int sampleDelayMs);
82 };
83 
84 } /* namespace exploringBB */
85 
86 #endif /* ITG3200GYROSCOPE_H_ */
float getGyroscopeYaw()
Definition: ITG3200.h:66
float getGyroscopePitch()
Definition: ITG3200.h:65
ITG3200(BusDevice *device)
Definition: ITG3200.cpp:59
virtual ~ITG3200()
Definition: ITG3200.cpp:129
float getOffsetRollOffset()
Definition: ITG3200.h:68
int zeroCalibrate(int numberSamples, int sampleDelayMs)
Definition: ITG3200.cpp:101
A class to interface with the ITG3200 gyroscope (untested)
Definition: ITG3200.h:39
float getGyroscopeRoll()
Definition: ITG3200.h:64
int convertGyroscopeValue(int msb_reg_addr, int lsb_reg_addr)
Definition: ITG3200.cpp:83
int getTemperature()
Definition: ITG3200.h:72
int setDigitalLowPassFilter(ITG3200_LPFILTER filterValue)
Definition: ITG3200.cpp:90
int setSampleRateDivider(char divider)
Definition: ITG3200.cpp:117
Definition: BusDevice.cpp:27
#define SENSITIVITY
Definition: ITG3200.h:31
This class is the parent of I2C and SPI devices, so that devices that use both SPI and I2C interfaces...
Definition: BusDevice.h:37
float getOffsetYawOffset()
Definition: ITG3200.h:70
float getOffsetPitchOffset()
Definition: ITG3200.h:69
int readFullSensorState()
Definition: ITG3200.cpp:70