Skip to content

Commit

Permalink
Reverse IMU I2C address from supplement to full
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirenliel committed Dec 20, 2024
1 parent da44803 commit af0cbb0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 37 deletions.
4 changes: 4 additions & 0 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#define PRIMARY_IMU_OPTIONAL false
#define SECONDARY_IMU_OPTIONAL true

// Set I2C address here or directly in IMU_DESC_ENTRY for each IMU used
#define PRIMARY_IMU_ADDRESS_ONE 0x4a
#define SECONDARY_IMU_ADDRESS_TWO 0x4b

#define MAX_IMU_COUNT 2

// Axis mapping example
Expand Down
1 change: 0 additions & 1 deletion src/sensors/SensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "icm20948sensor.h"
#include "mpu6050sensor.h"
#include "mpu9250sensor.h"
#include "sensoraddresses.h"
#include "softfusion/drivers/bmi270.h"
#include "softfusion/drivers/icm42688.h"
#include "softfusion/drivers/lsm6ds3trc.h"
Expand Down
15 changes: 7 additions & 8 deletions src/sensors/SensorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,19 @@ class SensorManager {
template <typename ImuType>
std::unique_ptr<Sensor> buildSensor(
uint8_t sensorID,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
bool optional = false,
int extraParam = 0
) {
const uint8_t address = ImuType::Address + addrSuppl;
m_Logger.trace(
"Building IMU with: id=%d,\n\
address=0x%02X, rotation=%f,\n\
sclPin=%d, sdaPin=%d, extraParam=%d, optional=%d",
sensorID,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand All @@ -89,21 +88,21 @@ class SensorManager {
I2CSCAN::clearBus(sdaPin, sclPin);
swapI2C(sclPin, sdaPin);

if (I2CSCAN::hasDevOnBus(address)) {
m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, address);
if (I2CSCAN::hasDevOnBus(i2cAddress)) {
m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, i2cAddress);
} else {
if (!optional) {
m_Logger.error(
"Mandatory sensor %d not found at address 0x%02X",
sensorID + 1,
address
i2cAddress
);
sensor = std::make_unique<ErroneousSensor>(sensorID, ImuType::TypeID);
} else {
m_Logger.debug(
"Optional sensor %d not found at address 0x%02X",
sensorID + 1,
address
i2cAddress
);
sensor = std::make_unique<EmptySensor>(sensorID);
}
Expand All @@ -113,7 +112,7 @@ class SensorManager {
uint8_t intPin = extraParam;
sensor = std::make_unique<ImuType>(
sensorID,
addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bmi160sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class BMI160Sensor : public Sensor {

BMI160Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -148,7 +148,7 @@ class BMI160Sensor : public Sensor {
"BMI160Sensor",
ImuID::BMI160,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bno055sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BNO055Sensor : public Sensor {

BNO055Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -45,7 +45,7 @@ class BNO055Sensor : public Sensor {
"BNO055Sensor",
ImuID::BNO055,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
16 changes: 8 additions & 8 deletions src/sensors/bno080sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BNO080Sensor : public Sensor {

BNO080Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -47,7 +47,7 @@ class BNO080Sensor : public Sensor {
"BNO080Sensor",
ImuID::BNO080,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand All @@ -69,13 +69,13 @@ class BNO080Sensor : public Sensor {
const char* sensorName,
ImuID imuId,
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
uint8_t intPin
)
: Sensor(sensorName, imuId, id, Address + addrSuppl, rotation, sclPin, sdaPin)
: Sensor(sensorName, imuId, id, i2cAddress, rotation, sclPin, sdaPin)
, m_IntPin(intPin){};

private:
Expand All @@ -102,7 +102,7 @@ class BNO085Sensor : public BNO080Sensor {
static constexpr auto TypeID = ImuID::BNO085;
BNO085Sensor(
uint8_t id,
uint8_t address,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -112,7 +112,7 @@ class BNO085Sensor : public BNO080Sensor {
"BNO085Sensor",
ImuID::BNO085,
id,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand All @@ -125,7 +125,7 @@ class BNO086Sensor : public BNO080Sensor {
static constexpr auto TypeID = ImuID::BNO086;
BNO086Sensor(
uint8_t id,
uint8_t address,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -135,7 +135,7 @@ class BNO086Sensor : public BNO080Sensor {
"BNO086Sensor",
ImuID::BNO086,
id,
address,
i2cAddress,
rotation,
sclPin,
sdaPin,
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/icm20948sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ICM20948Sensor : public Sensor {

ICM20948Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -45,7 +45,7 @@ class ICM20948Sensor : public Sensor {
"ICM20948Sensor",
ImuID::ICM20948,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/mpu6050sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MPU6050Sensor : public Sensor {

MPU6050Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -46,7 +46,7 @@ class MPU6050Sensor : public Sensor {
"MPU6050Sensor",
ImuID::MPU6050,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/mpu9250sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MPU9250Sensor : public Sensor {

MPU9250Sensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -59,7 +59,7 @@ class MPU9250Sensor : public Sensor {
"MPU9250Sensor",
ImuID::MPU9250,
id,
Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
Expand Down
7 changes: 0 additions & 7 deletions src/sensors/sensoraddresses.h

This file was deleted.

6 changes: 3 additions & 3 deletions src/sensors/softfusion/softfusionsensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class SoftFusionSensor : public Sensor {

SoftFusionSensor(
uint8_t id,
uint8_t addrSuppl,
uint8_t i2cAddress,
float rotation,
uint8_t sclPin,
uint8_t sdaPin,
Expand All @@ -191,13 +191,13 @@ class SoftFusionSensor : public Sensor {
imu::Name,
imu::Type,
id,
imu::Address + addrSuppl,
i2cAddress,
rotation,
sclPin,
sdaPin
)
, m_fusion(imu::GyrTs, imu::AccTs, imu::MagTs)
, m_sensor(I2CImpl(imu::Address + addrSuppl), m_Logger) {}
, m_sensor(I2CImpl(i2cAddress), m_Logger) {}
~SoftFusionSensor() {}

void motionLoop() override final {
Expand Down

0 comments on commit af0cbb0

Please sign in to comment.