Browse Source

AP_Compass: allow rotation of BMM150 compass

master
Andrew Tridgell 5 years ago
parent
commit
df387dc396
  1. 2
      libraries/AP_Compass/AP_Compass.cpp
  2. 10
      libraries/AP_Compass/AP_Compass_BMM150.cpp
  3. 5
      libraries/AP_Compass/AP_Compass_BMM150.h

2
libraries/AP_Compass/AP_Compass.cpp

@ -789,7 +789,7 @@ void Compass::_detect_backends(void)
case AP_BoardConfig::PX4_BOARD_PCNC1: case AP_BoardConfig::PX4_BOARD_PCNC1:
ADD_BACKEND(DRIVER_BMM150, ADD_BACKEND(DRIVER_BMM150,
AP_Compass_BMM150::probe(GET_I2C_DEVICE(0, 0x10))); AP_Compass_BMM150::probe(GET_I2C_DEVICE(0, 0x10), ROTATION_NONE));
break; break;
case AP_BoardConfig::VRX_BOARD_BRAIN54: { case AP_BoardConfig::VRX_BOARD_BRAIN54: {
// external i2c bus // external i2c bus

10
libraries/AP_Compass/AP_Compass_BMM150.cpp

@ -63,12 +63,12 @@
extern const AP_HAL::HAL &hal; extern const AP_HAL::HAL &hal;
AP_Compass_Backend *AP_Compass_BMM150::probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev) AP_Compass_Backend *AP_Compass_BMM150::probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, enum Rotation rotation)
{ {
if (!dev) { if (!dev) {
return nullptr; return nullptr;
} }
AP_Compass_BMM150 *sensor = new AP_Compass_BMM150(std::move(dev)); AP_Compass_BMM150 *sensor = new AP_Compass_BMM150(std::move(dev), rotation);
if (!sensor || !sensor->init()) { if (!sensor || !sensor->init()) {
delete sensor; delete sensor;
return nullptr; return nullptr;
@ -77,8 +77,8 @@ AP_Compass_Backend *AP_Compass_BMM150::probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> d
return sensor; return sensor;
} }
AP_Compass_BMM150::AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev) AP_Compass_BMM150::AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev, enum Rotation rotation)
: _dev(std::move(dev)) : _dev(std::move(dev)), _rotation(rotation)
{ {
} }
@ -216,6 +216,8 @@ bool AP_Compass_BMM150::init()
/* register the compass instance in the frontend */ /* register the compass instance in the frontend */
_compass_instance = register_compass(); _compass_instance = register_compass();
set_rotation(_compass_instance, _rotation);
_dev->set_device_type(DEVTYPE_BMM150); _dev->set_device_type(DEVTYPE_BMM150);
set_dev_id(_compass_instance, _dev->get_bus_id()); set_dev_id(_compass_instance, _dev->get_bus_id());

5
libraries/AP_Compass/AP_Compass_BMM150.h

@ -27,14 +27,14 @@
class AP_Compass_BMM150 : public AP_Compass_Backend class AP_Compass_BMM150 : public AP_Compass_Backend
{ {
public: public:
static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev); static AP_Compass_Backend *probe(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev, enum Rotation rotation);
void read() override; void read() override;
static constexpr const char *name = "BMM150"; static constexpr const char *name = "BMM150";
private: private:
AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev); AP_Compass_BMM150(AP_HAL::OwnPtr<AP_HAL::Device> dev, enum Rotation rotation);
/** /**
* Device periodic callback to read data from the sensor. * Device periodic callback to read data from the sensor.
@ -65,4 +65,5 @@ private:
uint32_t _last_read_ms; uint32_t _last_read_ms;
AP_HAL::Util::perf_counter_t _perf_err; AP_HAL::Util::perf_counter_t _perf_err;
enum Rotation _rotation;
}; };

Loading…
Cancel
Save