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 BMC050_H_
00051 #define BMC050_H_
00052
00053 #include <cmath>
00054 #include <unistd.h>
00055 #include <iostream>
00056
00057
00058 #include <ros/console.h>
00059
00060 #include <bosch_drivers_sensor_driver.hpp>
00061 #include <bosch_drivers_hardware_interface.hpp>
00062
00063 #include "bmc050_parameters.hpp"
00064
00065 using namespace bosch_drivers_common;
00066
00083 class BMC050: public sensor_driver, public BMC050Parameters
00084 {
00085
00086 public:
00087
00088
00089
00099 uint8_t modechange_accel_;
00100 uint8_t softreset_;
00101 uint8_t rate_compass_;
00102 uint8_t set_filter_;
00103
00104
00105 static const uint8_t SUSPEND = 0x07;
00106 static const uint8_t LOWPOWER_EN = 0x06;
00107 static const uint8_t SLEEP_DUR = 0x01;
00108
00109
00110 static const uint8_t SET_OPMODE_SLEEP = 0x03;
00111 static const uint8_t SET_OPMODE_FORCED = 0x01;
00112 static const uint8_t OPMODE = 0x01;
00113 static const uint8_t POWER_CONTROL_BIT = 0x00;
00114
00115
00116 static const uint8_t SOFTRESET_COMPASS_CMD = 0x82;
00117 static const uint8_t SOFTRESET_ACCEL_CMD = 0xB6;
00118 static const uint8_t FLAG_R = 0x80;
00119
00120
00121 static const uint8_t DATA_HIGH_BW = 7;
00122
00123 static const uint8_t Data_Rate = 3;
00124
00125
00126 static const uint8_t hp_z_en = 2;
00127 static const uint8_t hp_y_en = 1;
00128 static const uint8_t hp_x_en = 0;
00129
00130
00131 static const uint8_t offset_target_x = 1;
00132 static const uint8_t offset_target_y = 3;
00133 static const uint8_t offset_target_z = 5;
00134
00135 enum compass_mode
00136 {
00137 compass_suspend_,
00138 compass_sleep_,
00139 compass_normal_,
00140 compass_forced_
00141 };
00142
00143 enum accel_mode
00144 {
00145 accel_suspend_,
00146 accel_normal_,
00147 accel_low_power_
00148 };
00149
00150
00155 BMC050( bosch_hardware_interface* hw );
00156
00157
00158 ~BMC050();
00168 uint8_t getDeviceAddress();
00169
00176 bool initialize();
00177
00185 bool readRegistersAccel();
00186
00194 bool readRegistersCompass();
00195
00201 bool takeMeasurement();
00202
00210 bool softResetAccel();
00211
00222 bool changeAccelRange();
00223
00235 bool filterData( bool request );
00236
00247 bool changeAccelBandwidth();
00248
00256 bool getAccelData();
00257
00267 double getAccelX();
00268
00278 double getAccelY();
00279
00288 double getAccelZ();
00289
00298 double getTemperature();
00299
00311 void simpleCalibrationAccel();
00312
00313
00324 bool softResetCompass();
00325
00336 bool changeCompassRate();
00337
00344 bool changeNumRepetitionsXY();
00345
00352 bool changeNumRepetitionsZ();
00353
00354
00361 bool getCompassData();
00362
00363 double getCompassX();
00364 double getCompassY();
00365 double getCompassZ();
00366 uint16_t getRHall();
00367
00374 double getUncompensatedYaw();
00375
00376
00377 bool enterLowPowerModeAccel();
00378 bool enterSuspendModeAccel();
00379 bool enterNormalModeAccel();
00380
00381
00382 bool enterSuspendModeCompass();
00383 bool enterSleepModeCompass();
00384 bool enterNormalModeCompass();
00385 bool enterForcedModeCompass();
00386
00387 bool readRegAccel( uint8_t reg, uint8_t* value );
00388 bool readRegCompass( uint8_t reg, uint8_t* value );
00389 bool writeToAccelReg( uint8_t reg, uint8_t value );
00390 bool writeToCompassReg( uint8_t reg, uint8_t value );
00391 bool writeToCompassRegAndVerify( uint8_t reg, uint8_t value, uint8_t expected );
00392 bool writeToAccelRegAndVerify( uint8_t reg, uint8_t value, uint8_t expected );
00393 bool printOffsets();
00394
00395
00396
00397 static const uint8_t ADDRESS_ACCLXYZ = 0x02;
00398 static const uint8_t ADDRESS_ACC_X_LSB = 0x02;
00399 static const uint8_t ADDRESS_ACC_X_MSB = 0x03;
00400 static const uint8_t ADDRESS_ACC_Y_LSB = 0x04;
00401 static const uint8_t ADDRESS_ACC_Y_MSB = 0x05;
00402 static const uint8_t ADDRESS_ACC_Z_LSB = 0x06;
00403 static const uint8_t ADDRESS_ACC_Z_MSB = 0x07;
00404
00405 static const uint8_t ADDRESS_TEMPERATURE = 0x08;
00406
00407 static const uint8_t ADDRESS_ENABLE_CALIBRATION = 0x36;
00408 static const uint8_t ADDRESS_OFFSET_TARGET = 0x37;
00409 static const uint8_t OFFSET_FILT_X = 0x38;
00410 static const uint8_t OFFSET_UNFILT_Z = 0x3D;
00411
00412 static const uint8_t ADDRESS_COMPASS_XYZ = 0x42;
00413 static const uint8_t ADDRESS_COMPASS_X_LSB = 0x42;
00414 static const uint8_t ADDRESS_COMPASS_X_MSB = 0x43;
00415 static const uint8_t ADDRESS_COMPASS_Y_LSB = 0x44;
00416 static const uint8_t ADDRESS_COMPASS_Y_MSB = 0x45;
00417 static const uint8_t ADDRESS_COMPASS_Z_LSB = 0x46;
00418 static const uint8_t ADDRESS_COMPASS_Z_MSB = 0x47;
00419
00420 static const uint8_t ADDRESS_RHALL = 0x48;
00421 static const uint8_t ADDRESS_RHALL_LSB = 0x48;
00422 static const uint8_t ADDRESS_RHALL_MSB = 0x49;
00423
00424 static const uint8_t ADDRESS_COMPASS_REPZ = 0x51;
00425 static const uint8_t ADDRESS_COMPASS_REPXY = 0x52;
00426
00427 static const uint8_t ADDRESS_ACCEL_RANGE = 0x0F;
00428
00429
00430
00431 static const uint8_t MODECHANGE_ACCEL = 0x11;
00432 static const uint8_t SOFTRESET_ACCEL = 0x14;
00433 static const uint8_t BANDWIDTH_REG = 0x10;
00434 static const uint8_t SET_FILTER = 0x13;
00435
00436 static const uint8_t RATE_COMPASS = 0x4C;
00437 static const uint8_t SOFTRESET_COMPASS_REG = 0x4B;
00438
00439
00440 uint8_t RawData[13];
00441
00442 double AccelX_;
00443 double AccelY_;
00444 double AccelZ_;
00445 double Temperature_;
00446 double StaticPitch_;
00447 double StaticRoll_;
00448
00449 double CompassX_;
00450 double CompassY_;
00451 double CompassZ_;
00452 uint16_t RHall_;
00453
00454 double SensitivityXY_;
00455 double SensitivityZ_;
00456 double TempSlope_;
00457
00458 compass_mode compass_mode_;
00459 accel_mode accel_mode_;
00460 bandwidth prev_bw_reg_;
00461 };
00462
00463 #endif // BMC050_H_
00464