Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef BMA180_H_
00051 #define BMA180_H_
00052
00053 #include <cmath>
00054 #include <unistd.h>
00055
00056 #include <bosch_drivers_sensor_driver.hpp>
00057 #include <bosch_drivers_hardware_interface.hpp>
00058
00059 #include "bma180_parameters.hpp"
00060
00061 using namespace bosch_drivers_common;
00062
00071 class BMA180: public sensor_driver, public BMA180Parameters
00072 {
00073 public:
00074
00075 BMA180( bosch_hardware_interface* hw );
00076
00077 ~BMA180();
00078
00079
00080 bool initialize();
00081
00082
00083 bool takeMeasurement();
00084 bool getAccelData();
00085 double getAccelX();
00086 double getAccelY();
00087 double getAccelZ();
00088 double getStaticPitch();
00089 double getStaticRoll();
00090
00091 double getTemperature();
00092
00093
00094 bool EnableWriting();
00095 bool Calibrate();
00096 bool CoarseCalibrate();
00097 bool TwoStepCoarseCalibrate();
00098 bool FullCalibration();
00099 bool softReset();
00100 bool DisableI2C();
00101 bool changeAccelRange();
00102 bool changeBandwidth();
00103
00104 bool setEnOffsetBit( uint8_t bit );
00105
00106
00107 uint8_t getDeviceAddress();
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 double AccelX_;
00126 double AccelY_;
00127 double AccelZ_;
00128 double Temperature_;
00129 double StaticPitch_;
00130 double StaticRoll_;
00131
00132 double TempSlope_;
00133
00134
00135 protected:
00136
00137
00142 static const uint8_t SLAVE_ADDRESS0 = 0x40;
00143
00148 static const uint8_t SLAVE_ADDRESS1 = 0x41;
00149
00150
00151 static const uint8_t ADDRESS_ACCLXYZ = 0x02;
00152 static const uint8_t ADDRESS_ACCLX_MSB = 0x03;
00153 static const uint8_t ADDRESS_ACCLY_LSB = 0x04;
00154 static const uint8_t ADDRESS_ACCLY_MSB = 0x05;
00155 static const uint8_t ADDRESS_ACCLZ_LSB = 0x06;
00156 static const uint8_t ADDRESS_ACCLZ_MSB = 0x07;
00157 static const uint8_t ADDRESS_TEMPERATURE = 0x08;
00158
00159
00160 static const uint8_t ADDRESS_EE_CD1 = 0x4C;
00161 static const uint8_t ADDRESS_EE_CD2 = 0x4D;
00162 static const uint8_t ADDRESS_CD1 = 0x2C;
00163 static const uint8_t ADDRESS_CD2 = 0x2D;
00164
00165 static const uint8_t ADDRESS_VER = 0x00;
00166 static const uint8_t ADDRESS_STATUS_REG1 = 0x09;
00167 static const uint8_t ADDRESS_STATUS_REG2 = 0x0A;
00168 static const uint8_t ADDRESS_STATUS_REG3 = 0x0B;
00169 static const uint8_t ADDRESS_STATUS_REG4 = 0x0C;
00170 static const uint8_t ADDRESS_CTRLREG0 = 0x0D;
00171 static const uint8_t ADDRESS_CTRLREG1 = 0x0E;
00172 static const uint8_t ADDRESS_CTRLREG2 = 0x0F;
00173 static const uint8_t ADDRESS_CTRL_REG4 = 0x22;
00174
00176 static const uint8_t ADDRESS_EE_OFFSET_Z = 0x5A;
00177 static const uint8_t ADDRESS_EE_OFFSET_Y = 0x59;
00178 static const uint8_t ADDRESS_EE_OFFSET_X = 0x58;
00179 static const uint8_t ADDRESS_EE_OFFSET_T = 0x57;
00180 static const uint8_t ADDRESS_EE_OFFSET_LSB2 = 0x56;
00181 static const uint8_t ADDRESS_EE_OFFSET_LSB1 = 0x55;
00182 static const uint8_t ADDRESS_EE_GAIN_Z = 0x54;
00183 static const uint8_t ADDRESS_EE_GAIN_Y = 0x53;
00184 static const uint8_t ADDRESS_EE_GAIN_X = 0x52;
00185 static const uint8_t ADDRESS_EE_GAIN_T = 0x51;
00186
00188 static const uint8_t ADDRESS_OFFSET_Z = 0x3A;
00189 static const uint8_t ADDRESS_OFFSET_Y = 0x39;
00190 static const uint8_t ADDRESS_OFFSET_X = 0x38;
00191 static const uint8_t ADDRESS_OFFSET_T = 0x37;
00192 static const uint8_t ADDRESS_OFFSET_LSB2 = 0x36;
00193 static const uint8_t ADDRESS_OFFSET_LSB1 = 0x35;
00194 static const uint8_t ADDRESS_GAIN_Z = 0x34;
00195 static const uint8_t ADDRESS_GAIN_Y = 0x33;
00196 static const uint8_t ADDRESS_GAIN_X = 0x32;
00197 static const uint8_t ADDRESS_GAIN_T = 0x31;
00198
00200 static const uint8_t ADDRESS_BW_TCS = 0x20;
00201
00203 static const uint8_t ADDRESS_SOFTRESET = 0x10;
00204 static const uint8_t CMD_SOFTRESET = 0xB6;
00205
00207 static const uint8_t ADDRESS_HIGH_DUR = 0x27;
00208 static const uint8_t CMD_DISABLE_I2C = 0x01;
00209
00211
00212
00213
00214 static const uint8_t ee_w = 4;
00215
00216
00217
00218 static const uint8_t range = 1;
00219
00220
00221
00222 static const uint8_t bw = 4;
00223
00224
00225
00226 static const uint8_t en_offset_x = 7;
00227 static const uint8_t en_offset_y = 6;
00228 static const uint8_t en_offset_z = 5;
00229
00230
00231
00232 static const uint8_t offset_st_s = 1;
00233
00234
00235
00236 static const uint8_t offset_finetuning = 0;
00237
00238
00239 bool readReg( uint8_t reg, uint8_t* value );
00240 bool writeToReg( uint8_t reg, uint8_t value );
00241 bool writeToRegAndVerify( uint8_t reg, uint8_t value, uint8_t expected_value );
00242 bool readSensorData( uint8_t reg, uint8_t* value, uint8_t num_bytes );
00243 };
00244
00245 #endif // BMA180_H_