From 92dd216dbafa65710c0c67ee8e5787c5d0b29d10 Mon Sep 17 00:00:00 2001 From: jkerpe Date: Mon, 13 Nov 2023 10:26:53 +0100 Subject: [PATCH] Implemented new Findings by BlueAndi --- lib/HALInterfaces/IIMU.h | 25 ++++--- lib/HALSim/IMU.h | 24 ++++-- lib/HALTarget/IMU.h | 33 ++++++--- lib/HALTest/IMU.h | 107 ++++++++++++++++++--------- lib/SensorFusion/SerialMuxChannels.h | 46 ++++++++++-- 5 files changed, 163 insertions(+), 72 deletions(-) diff --git a/lib/HALInterfaces/IIMU.h b/lib/HALInterfaces/IIMU.h index 201e10d3..8c54f656 100644 --- a/lib/HALInterfaces/IIMU.h +++ b/lib/HALInterfaces/IIMU.h @@ -52,7 +52,8 @@ * Types and Classes *****************************************************************************/ -/** Struct of the IMU data in x, y and z direction. */ +/** Struct of the raw, unitless and not yet converted IMU (=accelerometer, gyro or magnetometer) data in x, y and z + * direction. */ typedef struct _IMUData { int16_t valueX; /* Raw sensor value in x direction (unitless) */ @@ -113,37 +114,43 @@ class IIMU virtual bool accelerometerDataReady() = 0; /** - * Indicates whether the gyro has new measurement data ready. + * Indicates whether the gyro has new measurement data ready. * * @return True if there is new gyro data available; false otherwise. */ virtual bool gyroDataReady() = 0; /** - * Indicates whether the magnetometer has new measurement data ready. + * Indicates whether the magnetometer has new measurement data ready. * * @return True if there is new magnetometer data available; false otherwise. */ virtual bool magnetometerDataReady() = 0; /** - * Get last raw Accelerometer values as a IMUData struct containing values in x, y and z. + * Get last raw Accelerometer values as an IMUData struct containing values in x, y and z. * - * @param[in] accelerationValues Pointer to IMUData struct. + * @param[in] accelerationValues Pointer to IMUData struct where the raw, unitless acceleration values in + * x, y and z direction will be written into. The values can be converted into physical values in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. */ virtual const void getAccelerationValues(IMUData* accelerationValues) = 0; /** - * Get last raw Gyroscope values as a IMUData struct containing values in x, y and z. + * Get last raw Gyroscope values as an IMUData struct containing values in x, y and z. * - * @param[in] turnRates Pointer to IMUData struct. + * @param[in] turnRates Pointer to IMUData struct where the raw, unitless turn Rates in x, y and z + * direction will be written into. The values can be converted into physical values in mrad/s via the multiplication + * with a sensitivity factor in mrad/s/bit. */ virtual const void getTurnRates(IMUData* turnRates) = 0; /** - * Get last raw Magnetometer values as a IMUData struct containing values in x, y and z. + * Get last raw Magnetometer values as an IMUData struct containing values in x, y and z. * - * @param[in] magnetometerValues Pointer to IMUData struct. + * @param[in] magnetometerValues Pointer to IMUData struct where the raw, unitless magnetometer values in + * x, y and z direction will be written into. The values can be converted into physical values in mgauss via the + * multiplication with a sensitivity factor in mgauss/bit. */ virtual const void getMagnetometerValues(IMUData* magnetometerValues) = 0; diff --git a/lib/HALSim/IMU.h b/lib/HALSim/IMU.h index e8186812..96fa0559 100644 --- a/lib/HALSim/IMU.h +++ b/lib/HALSim/IMU.h @@ -25,7 +25,7 @@ DESCRIPTION *******************************************************************************/ /** - * @brief IMU implementation of the simulation + * @brief IMU (Inertial Measurement Unit) implementation of the simulation * @author Juliane Kerpe * * @addtogroup HALSim @@ -58,7 +58,9 @@ * Types and Classes *****************************************************************************/ -/** The IMU adapter. */ +/** The IMU adapter. + * IMU stands for Inertial Measurement Unit. + */ class IMU : public IIMU { public: @@ -156,23 +158,29 @@ class IMU : public IIMU } /** - * Get last raw Accelerometer values as a IMUData struct containing values in x, y and z. + * Get last raw Accelerometer values as an IMUData struct containing values in x, y and z. * - * @param[in] accelerationValues Pointer to IMUData struct. + * @param[in] accelerationValues Pointer to IMUData struct where the raw, unitless acceleration values in + * x, y and z direction will be written into. The values can be converted into physical values in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. */ void const getAccelerationValues(IMUData* accelerationValues); /** - * Get last raw Gyroscope values as a IMUData struct containing values in x, y and z. + * Get last raw Gyroscope values as an IMUData struct containing values in x, y and z. * - * @param[in] turnRates Pointer to IMUData struct. + * @param[in] turnRates Pointer to IMUData struct where the raw, unitless turn Rates in x, y and z + * direction will be written into. The values can be converted into physical values in mrad/s via the multiplication + * with a sensitivity factor in mrad/s/bit. */ void const getTurnRates(IMUData* turnRates); /** - * Get last raw Magnetometer values as a IMUData struct containing values in x, y and z. + * Get last raw Magnetometer values as an IMUData struct containing values in x, y and z. * - * @param[in] magnetometerValues Pointer to IMUData struct. + * @param[in] magnetometerValues Pointer to IMUData struct where the raw, unitless magnetometer values in + * x, y and z direction will be written into. The values can be converted into physical values in mgauss via the + * multiplication with a sensitivity factor in mgauss/bit. */ void const getMagnetometerValues(IMUData* magnetometerValues); diff --git a/lib/HALTarget/IMU.h b/lib/HALTarget/IMU.h index a1c9c511..97e104b9 100644 --- a/lib/HALTarget/IMU.h +++ b/lib/HALTarget/IMU.h @@ -25,7 +25,7 @@ DESCRIPTION *******************************************************************************/ /** - * @brief IMU implementation + * @brief IMU (Inertial Measurement Unit) implementation * @author Juliane Kerpe * * @addtogroup HALSim @@ -53,7 +53,9 @@ * Types and Classes *****************************************************************************/ -/** The IMU adapter. */ +/** The IMU adapter. + * IMU stands for Inertial Measurement Unit. + */ class IMU : public IIMU { public: @@ -63,6 +65,9 @@ class IMU : public IIMU */ IMU() : IIMU(), + m_accelerometerValues{0, 0, 0}, + m_gyroValues{0, 0, 0}, + m_magnetometerValues{0, 0, 0}, m_rawAccelerometerOffsetX(0), m_rawAccelerometerOffsetY(0), m_rawAccelerometerOffsetZ(0), @@ -133,23 +138,29 @@ class IMU : public IIMU bool magnetometerDataReady(); /** - * Get last raw Accelerometer values as a IMUData struct containing values in x, y and z. + * Get last raw Accelerometer values as an IMUData struct containing values in x, y and z. * - * @param[in] accelerationValues Pointer to IMUData struct. + * @param[in] accelerationValues Pointer to IMUData struct where the raw, unitless acceleration values in + * x, y and z direction will be written into. The values can be converted into physical values in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. */ const void getAccelerationValues(IMUData* accelerationValues); /** - * Get last raw Gyroscope values as a IMUData struct containing values in x, y and z. + * Get last raw Gyroscope values as an IMUData struct containing values in x, y and z. * - * @param[in] turnRates Pointer to IMUData struct. + * @param[in] turnRates Pointer to IMUData struct where the raw, unitless turn Rates in x, y and z + * direction will be written into. The values can be converted into physical values in mrad/s via the multiplication + * with a sensitivity factor in mrad/s/bit. */ const void getTurnRates(IMUData* turnRates); /** - * Get last raw Magnetometer values as a IMUData struct containing values in x, y and z. + * Get last raw Magnetometer values as an IMUData struct containing values in x, y and z. * - * @param[in] magnetometerValues Pointer to IMUData struct. + * @param[in] magnetometerValues Pointer to IMUData struct where the raw, unitless magnetometer values in + * x, y and z direction will be written into. The values can be converted into physical values in mgauss via the + * multiplication with a sensitivity factor in mgauss/bit. */ const void getMagnetometerValues(IMUData* magnetometerValues); @@ -159,9 +170,9 @@ class IMU : public IIMU void calibrate(); private: - IMUData m_accelerometerValues = {0, 0, 0}; /* Raw accelerometer readings. */ - IMUData m_gyroValues = {0, 0, 0}; /* Raw gyro readings. */ - IMUData m_magnetometerValues = {0, 0, 0}; /* Raw magnetometer readings. */ + IMUData m_accelerometerValues; /* Raw accelerometer readings. */ + IMUData m_gyroValues; /* Raw gyro readings. */ + IMUData m_magnetometerValues; /* Raw magnetometer readings. */ protected: private: diff --git a/lib/HALTest/IMU.h b/lib/HALTest/IMU.h index 85b67a8f..c7a536d4 100644 --- a/lib/HALTest/IMU.h +++ b/lib/HALTest/IMU.h @@ -25,7 +25,7 @@ DESCRIPTION *******************************************************************************/ /** - * @brief IMU realization + * @brief IMU (Inertial Measurement Unit) realization * @author Juliane Kerpe * * @addtogroup HALSim @@ -36,7 +36,6 @@ #ifndef IMU_H #define IMU_H - /****************************************************************************** * Compile Switches *****************************************************************************/ @@ -45,7 +44,9 @@ * Includes *****************************************************************************/ #include "IIMU.h" - +/** The IMU adapter. + * IMU stands for Inertial Measurement Unit. + */ class IMU : public IIMU { public: @@ -61,80 +62,114 @@ class IMU : public IIMU * * @return True if the sensor type was detected succesfully; false otherwise. */ - bool init(){return true;} - + bool init() + { + return true; + } + /** * Enables all of the inertial sensors with a default configuration. */ - void enableDefault() {}; + void enableDefault(){}; /** * Configures the sensors with settings optimized for turn sensing. */ - void configureForTurnSensing() {} + void configureForTurnSensing() + { + } /** * Takes a reading from the accelerometer and makes the measurements available in a. - */ - void readAccelerometer() {} - + */ + void readAccelerometer() + { + } + /** * Takes a reading from the gyro and makes the measurements available in g. */ - void readGyro() {} - + void readGyro() + { + } + /** * Takes a reading from the magnetometer and makes the measurements available in m. */ - void readMagnetometer() {} - + void readMagnetometer() + { + } + /** * Indicates whether the accelerometer has new measurement data ready. - * - * @return True if there is new accelerometer data available; false otherwise. + * + * @return True if there is new accelerometer data available; false otherwise. */ - bool accelerometerDataReady() {return true;} - + bool accelerometerDataReady() + { + return true; + } + /** * Indicates whether the gyro has new measurement data ready. - * + * * @return True if there is new gyro data available; false otherwise. */ - bool gyroDataReady() {return true;} - + bool gyroDataReady() + { + return true; + } + /** * Indicates whether the magnetometer has new measurement data ready. - * + * * @return True if there is new magnetometer data available; false otherwise. */ - bool magnetometerDataReady() {return true;} - + bool magnetometerDataReady() + { + return true; + } + /** - * Get last raw Accelerometer values as a IMUData struct containing values in x, y and z. + * Get last raw Accelerometer values as an IMUData struct containing values in x, y and z. * - * @param[in] accelerationValues Pointer to IMUData struct. + * @param[in] accelerationValues Pointer to IMUData struct where the raw, unitless acceleration values in + * x, y and z direction will be written into. The values can be converted into physical values in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. */ - const void getAccelerationValues(IMUData* accelerationValues) {} + const void getAccelerationValues(IMUData* accelerationValues) + { + } /** - * Get last raw Gyroscope values as a IMUData struct containing values in x, y and z. + * Get last raw Gyroscope values as an IMUData struct containing values in x, y and z. * - * @param[in] turnRates Pointer to IMUData struct. + * @param[in] turnRates Pointer to IMUData struct where the raw, unitless turn Rates in x, y and z + * direction will be written into. The values can be converted into physical values in mrad/s via the multiplication + * with a sensitivity factor in mrad/s/bit. */ - const void getTurnRates(IMUData* turnRates) {} + const void getTurnRates(IMUData* turnRates) + { + } /** - * Get last raw Magnetometer values as a IMUData struct containing values in x, y and z. + * Get last raw Magnetometer values as an IMUData struct containing values in x, y and z. * - * @param[in] magnetometerValues Pointer to IMUData struct. + * @param[in] magnetometerValues Pointer to IMUData struct where the raw, unitless magnetometer values in + * x, y and z direction will be written into. The values can be converted into physical values in mgauss via the + * multiplication with a sensitivity factor in mgauss/bit. */ - const void getMagnetometerValues(IMUData* magnetometerValues) {} - + const void getMagnetometerValues(IMUData* magnetometerValues) + { + } + /** * Calibrate the IMU. */ - virtual void calibrate() {} - + virtual void calibrate() + { + } + private: }; diff --git a/lib/SensorFusion/SerialMuxChannels.h b/lib/SensorFusion/SerialMuxChannels.h index 30b6c3d7..8a01a88f 100644 --- a/lib/SensorFusion/SerialMuxChannels.h +++ b/lib/SensorFusion/SerialMuxChannels.h @@ -56,14 +56,44 @@ /** Struct of the Sensor Data channel payload. */ typedef struct _SensorData { - int32_t positionOdometryX; /* Position in x direction in mm calculated by odometry. */ - int32_t positionOdometryY; /* Position in y direction in mm calculated by odometry. */ - int32_t orientationOdometry; /* Orientation in mrad calculated by odometry. */ - int16_t accelerationX; /* Acceleration in x direction as a raw sensor value. */ - int16_t accelerationY; /* Acceleration in y direction as a raw sensor value. */ - int16_t magnetometerValueX; /* Magnetometer value in x direction as a raw sensor value. */ - int16_t magnetometerValueY; /* Magnetometer value in y direction as a raw sensor value. */ - int16_t turnRate; /* Gyroscope value around z axis as a raw sensor value. */ + /** Position in x direction in mm calculated by odometry. */ + int32_t positionOdometryX; + + /** Position in y direction in mm calculated by odometry. */ + int32_t positionOdometryY; + + /** Orientation in mrad calculated by odometry. */ + int32_t orientationOdometry; + + /** Acceleration in x direction as a raw sensor value in bit. + * This is a unitless bit value. It can be converted into a physical acceleration value in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. + */ + int16_t accelerationX; + + /** Acceleration in y direction as a raw sensor value in bit. + * This is a unitless bit value. It can be converted into a physical acceleration value in mm/s^2 via the + * multiplication with a sensitivity factor in mm/s^2/bit. + */ + int16_t accelerationY; + + /** Magnetometer value in x direction as a raw sensor value in bit. + * This is a unitless bit value. It does not require conversion into a physical magnetometer value since only the + * ratio with the value in y direction is important. + */ + int16_t magnetometerValueX; + + /** Magnetometer value in y direction as a raw sensor value in bit. + * This is a unitless bit value. It does not require conversion into a physical magnetometer value since only the + * ratio with the value in x direction is important. + */ + int16_t magnetometerValueY; + + /** Gyroscope value around z axis as a raw sensor value in bit. + * This is a unitless bit value. It can be converted into a physical turn rate in mrad/s via the multiplication + * with a sensitivity factor in mrad/s/bit. + */ + int16_t turnRate; } __attribute__((packed)) SensorData; /******************************************************************************