Skip to content

Commit

Permalink
Removed Functions writeReg and getType from IMU
Browse files Browse the repository at this point in the history
  • Loading branch information
jkerpe committed Oct 27, 2023
1 parent 813cb73 commit 8c737bb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 116 deletions.
28 changes: 1 addition & 27 deletions lib/HALInterfaces/IIMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
DESCRIPTION
*******************************************************************************/
/**
* @brief Abstract IMU interface
* @brief Abstract IMU interface, depicts Zumo32U4IMU library
* @author Juliane Kerpe <[email protected]>
*
* @addtogroup HALInterfaces
Expand All @@ -52,16 +52,6 @@
* Types and Classes
*****************************************************************************/


/**
* Own enum is necessary since it is only defined in the Zumo32U4-Library and will therefor only be found on HALTarget and not HALSim.
*/
enum class Zumo32U4IMUTypeRU : uint8_t {
Unknown,
LSM303D_L3GD20H,
LSM6DS33_LIS3MDL
};

/** The abstract IMU interface. */
class IIMU
{
Expand All @@ -79,13 +69,6 @@ class IIMU
* @return True if the sensor type was detected succesfully; false otherwise.
*/
virtual bool init() = 0;

/**
* Returns the type of the inertial sensors on the Zumo 32U4.
*
* @return The sensor type as a member of the Zumo32U4IMUType enum. If the type is not known (e.g. if init() has not been called yet), this will be Zumo32U4IMUType::Unknown.
*/
virtual Zumo32U4IMUTypeRU getType() = 0;

/**
* Enables all of the inertial sensors with a default configuration.
Expand All @@ -96,15 +79,6 @@ class IIMU
* Configures the sensors with settings optimized for turn sensing.
*/
virtual void configureForTurnSensing() = 0;

/**
* Writes an 8-bit sensor register.
*
* @param[in] addr Device address.
* @param[in] reg Register address.
* @param[in] value 8-bit register value to be written.
*/
virtual void writeReg(uint8_t addr, uint8_t reg, uint8_t value) = 0;

/**
* Takes a reading from the accelerometer and makes the measurements available in a.
Expand Down
5 changes: 0 additions & 5 deletions lib/HALSim/IMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ bool IMU::init()
return true;
}

Zumo32U4IMUTypeRU IMU::getType()
{
return m_sensorType;
}

void IMU::readAcc()
{
const double * accelerationValues = m_accelerometer->getValues();
Expand Down
26 changes: 1 addition & 25 deletions lib/HALSim/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
* Types and Classes
*****************************************************************************/

enum class Zumo32U4IMUType : uint8_t {
Unknown,
LSM303D_L3GD20H,
LSM6DS33_LIS3MDL
};

/** The IMU adapter. */
class IMU : public IIMU
{
Expand All @@ -81,8 +75,7 @@ class IMU : public IIMU
m_simTime(simTime),
m_accelerometer(accelerometer),
m_gyro(gyro),
m_magnetometer(compass),
m_sensorType(Zumo32U4IMUTypeRU::LSM303D_L3GD20H)
m_magnetometer(compass)
{
}

Expand All @@ -99,13 +92,6 @@ class IMU : public IIMU
* @return True if the sensor type was detected succesfully; false otherwise.
*/
bool init();

/**
* Returns the type of the inertial sensors on the Zumo 32U4.
*
* @return The sensor type as a member of the Zumo32U4IMUType enum. If the type is not known (e.g. if init() has not been called yet), this will be Zumo32U4IMUType::Unknown.
*/
Zumo32U4IMUTypeRU getType();

/**
* Enables all of the inertial sensors with a default configuration.
Expand All @@ -116,15 +102,6 @@ class IMU : public IIMU
* Configures the sensors with settings optimized for turn sensing.
*/
void configureForTurnSensing() {}

/**
* Writes an 8-bit sensor register.
*
* @param[in] addr Device address.
* @param[in] reg Register address.
* @param[in] value 8-bit register value to be written.
*/
void writeReg(uint8_t addr, uint8_t reg, uint8_t value) {};

/**
* Takes a reading from the accelerometer and makes the measurements available in a.
Expand Down Expand Up @@ -199,7 +176,6 @@ class IMU : public IIMU
webots::Accelerometer* m_accelerometer; /**< The accelerometer of Webots. */
webots::Gyro* m_gyro; /**< The gyro of Webots. */
webots::Compass* m_magnetometer; /**< The magnetometer of Webots. */
Zumo32U4IMUTypeRU m_sensorType; /**< The type of the IMU. */
};

/******************************************************************************
Expand Down
17 changes: 1 addition & 16 deletions lib/HALTarget/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,7 @@ void Board::init()
m_motors.init();
m_imu.init();
m_imu.enableDefault();
m_imu.configureForTurnSensing();

switch(m_imu.getType())
{
case Zumo32U4IMUTypeRU::LSM303D_L3GD20H:
// 0x00 means +/- 245 dps according to L3GD20H data sheet
m_imu.writeReg(L3GD20H_ADDR, L3GD20H_REG_CTRL4, 0x00);
break;
case Zumo32U4IMUTypeRU::LSM6DS33_LIS3MDL:
// 0x00 means +/- 245 dps according to LSM6DS33 data sheet
m_imu.writeReg(LSM6DS33_ADDR, LSM6DS33_REG_CTRL2_G, 00);
break;
default:
;
}

m_imu.configureForTurnSensing();
m_imu.calibrate();
}

Expand Down
25 changes: 14 additions & 11 deletions lib/HALTarget/IMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,23 @@ bool IMU::init()
if (isInitSuccessful) {
m_imu.enableDefault();
}

switch(m_imu.getType())
{
case Zumo32U4IMUType::LSM303D_L3GD20H:
// 0x00 means +/- 245 dps according to L3GD20H data sheet
m_imu.writeReg(L3GD20H_ADDR, L3GD20H_REG_CTRL4, 0x00);
break;
case Zumo32U4IMUType::LSM6DS33_LIS3MDL:
// 0x00 means +/- 245 dps according to LSM6DS33 data sheet
m_imu.writeReg(LSM6DS33_ADDR, LSM6DS33_REG_CTRL2_G, 00);
break;
default:
;
}
return isInitSuccessful;
}

Zumo32U4IMUTypeRU IMU::getType()
{
/* Return the Sensor Type mapped to the own enum class defined in IIMU. */
return static_cast<Zumo32U4IMUTypeRU>(m_imu.getType());
}

void IMU::enableDefault()
{
m_imu.enableDefault();
Expand All @@ -82,11 +90,6 @@ void IMU::configureForTurnSensing()
m_imu.configureForTurnSensing();
}

void IMU::writeReg(uint8_t addr, uint8_t reg, uint8_t value)
{
m_imu.writeReg(addr, reg, value);
}

void IMU::readAcc()
{
while(!m_imu.accDataReady()){}
Expand Down
16 changes: 0 additions & 16 deletions lib/HALTarget/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ class IMU : public IIMU
* @return True if the sensor type was detected succesfully; false otherwise.
*/
bool init();

/**
* Returns the type of the inertial sensors on the Zumo 32U4.
*
* @return The sensor type as a member of the Zumo32U4IMUType enum. If the type is not known (e.g. if init() has not been called yet), this will be Zumo32U4IMUType::Unknown.
*/
Zumo32U4IMUTypeRU getType();

/**
* Enables all of the inertial sensors with a default configuration.
Expand All @@ -107,15 +100,6 @@ class IMU : public IIMU
* Configures the sensors with settings optimized for turn sensing.
*/
void configureForTurnSensing();

/**
* Writes an 8-bit sensor register.
*
* @param[in] addr Device address.
* @param[in] reg Register address.
* @param[in] value 8-bit register value to be written.
*/
void writeReg(uint8_t addr, uint8_t reg, uint8_t value);

/**
* Takes a reading from the accelerometer and makes the measurements available in a.
Expand Down
16 changes: 0 additions & 16 deletions lib/HALTest/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ class IMU : public IIMU
* @return True if the sensor type was detected succesfully; false otherwise.
*/
bool init(){return true;}

/**
* Returns the type of the inertial sensors on the Zumo 32U4.
*
* @return The sensor type as a member of the Zumo32U4IMUType enum. If the type is not known (e.g. if init() has not been called yet), this will be Zumo32U4IMUType::Unknown.
*/
Zumo32U4IMUTypeRU getType() {return Zumo32U4IMUTypeRU::LSM303D_L3GD20H;}

/**
* Enables all of the inertial sensors with a default configuration.
Expand All @@ -79,15 +72,6 @@ class IMU : public IIMU
* Configures the sensors with settings optimized for turn sensing.
*/
void configureForTurnSensing() {}

/**
* Writes an 8-bit sensor register.
*
* @param[in] addr Device address.
* @param[in] reg Register address.
* @param[in] value 8-bit register value to be written.
*/
void writeReg(uint8_t addr, uint8_t reg, uint8_t value){}

/**
* Takes a reading from the accelerometer and makes the measurements available in a.
Expand Down

0 comments on commit 8c737bb

Please sign in to comment.