Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
exploringBB::ITG3200 Class Reference

A class to interface with the ITG3200 gyroscope (untested) More...

#include <ITG3200.h>

Public Member Functions

 ITG3200 (BusDevice *device)
 
float getGyroscopeRoll ()
 
float getGyroscopePitch ()
 
float getGyroscopeYaw ()
 
float getOffsetRollOffset ()
 
float getOffsetPitchOffset ()
 
float getOffsetYawOffset ()
 
int getTemperature ()
 
virtual ~ITG3200 ()
 
int readFullSensorState ()
 
int convertGyroscopeValue (int msb_reg_addr, int lsb_reg_addr)
 
int setDigitalLowPassFilter (ITG3200_LPFILTER filterValue)
 
int setSampleRateDivider (char divider)
 
int zeroCalibrate (int numberSamples, int sampleDelayMs)
 

Detailed Description

A class to interface with the ITG3200 gyroscope (untested)

Constructor & Destructor Documentation

exploringBB::ITG3200::ITG3200 ( BusDevice device)
59  {
60  this->device = device;
61  for (int i=0; i<3; i++) {
62  this->gyroscope[i] = 0.0;
63  this->offsets[i] = 0.0;
64  }
65  this->registers = NULL;
66  this->temperature = 0;
67  this->readFullSensorState();
68 }
int readFullSensorState()
Definition: ITG3200.cpp:70
exploringBB::ITG3200::~ITG3200 ( )
virtual
129 {}

Member Function Documentation

int exploringBB::ITG3200::convertGyroscopeValue ( int  msb_reg_addr,
int  lsb_reg_addr 
)
83  {
84  short temp = *(registers+msb_reg_addr);
85  temp = (temp<<8) | *(registers+lsb_reg_addr);
86  temp = ~temp + 1;
87  return temp;
88 }
float exploringBB::ITG3200::getGyroscopePitch ( )
inline
65 { return gyroscope[1]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
float exploringBB::ITG3200::getGyroscopeRoll ( )
inline
64 { return gyroscope[0]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
float exploringBB::ITG3200::getGyroscopeYaw ( )
inline
66 { return gyroscope[2]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
float exploringBB::ITG3200::getOffsetPitchOffset ( )
inline
69 { return offsets[1]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
float exploringBB::ITG3200::getOffsetRollOffset ( )
inline
68 { return offsets[0]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
float exploringBB::ITG3200::getOffsetYawOffset ( )
inline
70 { return offsets[2]/SENSITIVITY; }
#define SENSITIVITY
Definition: ITG3200.h:31
int exploringBB::ITG3200::getTemperature ( )
inline
72 { return temperature; }
int exploringBB::ITG3200::readFullSensorState ( )
70  {
71  this->registers = this->device->readRegisters(BUFFER_SIZE, 0x00);
72  if(*this->registers!=0x69){
73  perror("ITG3200: Failure Condition - Sensor ID not Verified");
74  return -1;
75  }
76  this->gyroscope[0] = convertGyroscopeValue(GYRO_X_MSB, GYRO_X_LSB);
77  this->gyroscope[1] = convertGyroscopeValue(GYRO_Y_MSB, GYRO_Y_LSB);
78  this->gyroscope[2] = convertGyroscopeValue(GYRO_Z_MSB, GYRO_Z_LSB);
79  this->temperature = convertGyroscopeValue(TEMP_MSB, TEMP_LSB);
80  return 0;
81 }
int convertGyroscopeValue(int msb_reg_addr, int lsb_reg_addr)
Definition: ITG3200.cpp:83
#define GYRO_Y_MSB
Definition: ITG3200.cpp:41
#define GYRO_X_MSB
Definition: ITG3200.cpp:39
#define TEMP_LSB
Definition: ITG3200.cpp:46
#define GYRO_Z_MSB
Definition: ITG3200.cpp:43
#define GYRO_X_LSB
Definition: ITG3200.cpp:40
#define BUFFER_SIZE
The ADXL345 has 0x40 registers (0x01 to 0x1C are reserved and should not be accessed) ...
Definition: ADXL345.h:31
#define TEMP_MSB
Definition: ITG3200.cpp:45
#define GYRO_Z_LSB
Definition: ITG3200.cpp:44
virtual unsigned char * readRegisters(unsigned int number, unsigned int fromAddress=0)=0
#define GYRO_Y_LSB
Definition: ITG3200.cpp:42
int exploringBB::ITG3200::setDigitalLowPassFilter ( ITG3200_LPFILTER  filterValue)
90  {
91  //bits 7,6,5 are 0; bits 4,3 are = 03h for proper operation, i.e. +/- 2000 deg/sec full range
92  char temp = 0b00011000;
93  temp = temp | filterValue; // OR with incoming value (between 00 and 06h)
94  if(this->device->writeRegister(DLPF_FS, temp)!=0){
95  cout << "Failure to update ITG3200 DLPF_FS value" << endl;
96  return 1;
97  }
98  return 0;
99 }
#define DLPF_FS
Definition: ITG3200.cpp:52
virtual int writeRegister(unsigned int registerAddress, unsigned char value)=0
int exploringBB::ITG3200::setSampleRateDivider ( char  divider)
117  {
118  //bits 7-0 set the divider which sets the sample rate of the gyro according to the equation
119  // Fsample = Finternal / (divider+1)
120  // Finternal is set according to the low pass filter ITG3200_LPFILTER
121  // which is 1kHz for all values except the highest LPF of DLPF_CFG
122  if(this->device->writeRegister(SMPLRT_DIV, divider)!=0){
123  cout << "Failure to update ITG3200 SMPLRT_DIV value" << endl;
124  return 1;
125  }
126  return 0;
127 }
#define SMPLRT_DIV
Definition: ITG3200.cpp:50
virtual int writeRegister(unsigned int registerAddress, unsigned char value)=0
int exploringBB::ITG3200::zeroCalibrate ( int  numberSamples,
int  sampleDelayMs 
)
101  {
102 
103  double total[3] = {0.0, 0.0, 0.0};
104  for(int i=0; i<numberSamples; i++){
105  this->readFullSensorState();
106  for(int j=0; j<3; j++){
107  total[j] = total[j] + this->gyroscope[j];
108  }
109  usleep(sampleDelayMs*1000);
110  }
111  for(int i=0; i<=2; i++) {
112  this->offsets[i] = total[i]/numberSamples;
113  }
114  return 0;
115 }
int readFullSensorState()
Definition: ITG3200.cpp:70

The documentation for this class was generated from the following files: