From 4b781f2d12ad4630200187e8fdcbd101a8329008 Mon Sep 17 00:00:00 2001 From: myles-parfeniuk Date: Sat, 16 Nov 2024 10:12:26 -0800 Subject: [PATCH] renamed IMUResetReason -> BNO08xResetReason IMUAccuracy -> BNO08xAccuracy --- include/BNO08x.hpp | 30 ++++++------ include/BNO08xTestHelper.hpp | 8 ++-- include/BNO08x_global_types.hpp | 10 ++-- source/BNO08x.cpp | 84 ++++++++++++++++----------------- test/InitDeinitTests.cpp | 2 +- 5 files changed, 69 insertions(+), 65 deletions(-) diff --git a/include/BNO08x.hpp b/include/BNO08x.hpp index 8b5fe4f..6a7ea77 100644 --- a/include/BNO08x.hpp +++ b/include/BNO08x.hpp @@ -30,7 +30,7 @@ class BNO08x bool hard_reset(); bool soft_reset(); - IMUResetReason get_reset_reason(); + BNO08xResetReason get_reset_reason(); bool mode_sleep(); bool mode_on(); @@ -96,17 +96,17 @@ class BNO08x uint32_t get_time_stamp(); - void get_magf(float& x, float& y, float& z, IMUAccuracy& accuracy); + void get_magf(float& x, float& y, float& z, BNO08xAccuracy& accuracy); float get_magf_X(); float get_magf_Y(); float get_magf_Z(); - IMUAccuracy get_magf_accuracy(); + BNO08xAccuracy get_magf_accuracy(); - void get_gravity(float& x, float& y, float& z, IMUAccuracy& accuracy); + void get_gravity(float& x, float& y, float& z, BNO08xAccuracy& accuracy); float get_gravity_X(); float get_gravity_Y(); float get_gravity_Z(); - IMUAccuracy get_gravity_accuracy(); + BNO08xAccuracy get_gravity_accuracy(); float get_roll(); float get_pitch(); @@ -116,25 +116,25 @@ class BNO08x float get_pitch_deg(); float get_yaw_deg(); - void get_quat(float& i, float& j, float& k, float& real, float& rad_accuracy, IMUAccuracy& accuracy); + void get_quat(float& i, float& j, float& k, float& real, float& rad_accuracy, BNO08xAccuracy& accuracy); float get_quat_I(); float get_quat_J(); float get_quat_K(); float get_quat_real(); float get_quat_radian_accuracy(); - IMUAccuracy get_quat_accuracy(); + BNO08xAccuracy get_quat_accuracy(); - void get_accel(float& x, float& y, float& z, IMUAccuracy& accuracy); + void get_accel(float& x, float& y, float& z, BNO08xAccuracy& accuracy); float get_accel_X(); float get_accel_Y(); float get_accel_Z(); - IMUAccuracy get_accel_accuracy(); + BNO08xAccuracy get_accel_accuracy(); - void get_linear_accel(float& x, float& y, float& z, IMUAccuracy& accuracy); + void get_linear_accel(float& x, float& y, float& z, BNO08xAccuracy& accuracy); float get_linear_accel_X(); float get_linear_accel_Y(); float get_linear_accel_Z(); - IMUAccuracy get_linear_accel_accuracy(); + BNO08xAccuracy get_linear_accel_accuracy(); int16_t get_raw_accel_X(); int16_t get_raw_accel_Y(); @@ -148,20 +148,20 @@ class BNO08x int16_t get_raw_magf_Y(); int16_t get_raw_magf_Z(); - void get_gyro_calibrated_velocity(float& x, float& y, float& z, IMUAccuracy& accuracy); + void get_gyro_calibrated_velocity(float& x, float& y, float& z, BNO08xAccuracy& accuracy); float get_gyro_calibrated_velocity_X(); float get_gyro_calibrated_velocity_Y(); float get_gyro_calibrated_velocity_Z(); - IMUAccuracy get_gyro_accuracy(); + BNO08xAccuracy get_gyro_accuracy(); - void get_uncalibrated_gyro(float& x, float& y, float& z, float& bx, float& by, float& bz, IMUAccuracy& accuracy); + void get_uncalibrated_gyro(float& x, float& y, float& z, float& bx, float& by, float& bz, BNO08xAccuracy& accuracy); float get_uncalibrated_gyro_X(); float get_uncalibrated_gyro_Y(); float get_uncalibrated_gyro_Z(); float get_uncalibrated_gyro_bias_X(); float get_uncalibrated_gyro_bias_Y(); float get_uncalibrated_gyro_bias_Z(); - IMUAccuracy get_uncalibrated_gyro_accuracy(); + BNO08xAccuracy get_uncalibrated_gyro_accuracy(); void get_gyro_velocity(float& x, float& y, float& z); float get_gyro_velocity_X(); diff --git a/include/BNO08xTestHelper.hpp b/include/BNO08xTestHelper.hpp index bd0b2db..53e7183 100644 --- a/include/BNO08xTestHelper.hpp +++ b/include/BNO08xTestHelper.hpp @@ -21,7 +21,7 @@ class BNO08xTestHelper float quat_K; float quat_real; float quat_radian_accuracy; - IMUAccuracy quat_accuracy; + BNO08xAccuracy quat_accuracy; float gyro_vel_x; float gyro_vel_y; @@ -30,7 +30,7 @@ class BNO08xTestHelper float accel_x; float accel_y; float accel_z; - IMUAccuracy accel_accuracy; + BNO08xAccuracy accel_accuracy; } imu_report_data_t; @@ -132,7 +132,7 @@ class BNO08xTestHelper if (report_data->quat_real != 1.0f) new_data = true; - if (report_data->quat_accuracy != IMUAccuracy::UNDEFINED) + if (report_data->quat_accuracy != BNO08xAccuracy::UNDEFINED) new_data = true; if (report_data->quat_radian_accuracy != 0.0f) @@ -182,7 +182,7 @@ class BNO08xTestHelper if (report_data->accel_z != 0.0f) new_data = true; - if (report_data->accel_accuracy != IMUAccuracy::UNDEFINED) + if (report_data->accel_accuracy != BNO08xAccuracy::UNDEFINED) new_data = true; return new_data; diff --git a/include/BNO08x_global_types.hpp b/include/BNO08x_global_types.hpp index 14e46fa..389dc20 100644 --- a/include/BNO08x_global_types.hpp +++ b/include/BNO08x_global_types.hpp @@ -5,16 +5,17 @@ #include /// @brief Sensor accuracy returned during sensor calibration -enum class IMUAccuracy +enum class BNO08xAccuracy { LOW = 1, MED, HIGH, UNDEFINED }; +using IMUAccuracy = BNO08xAccuracy; // legacy version compatibility /// @brief Reason for previous IMU reset (returned by get_reset_reason()) -enum class IMUResetReason +enum class BNO08xResetReason { UNDEFINED, ///< Undefined reset reason, this should never occur and is an error. POR, ///< Previous reset was due to power on reset. @@ -23,6 +24,7 @@ enum class IMUResetReason EXT_RST, ///< Previous reset was due to external reset. OTHER ///< Previous reset was due to power other reason. }; +using IMUResetReason = BNO08xResetReason; // legacy version compatibility /// @brief IMU configuration settings passed into constructor typedef struct bno08x_config_t @@ -71,4 +73,6 @@ typedef struct bno08x_config_t , install_isr_service(install_isr_service) { } -} bno08x_config_t; \ No newline at end of file +} bno08x_config_t; + +typedef bno08x_config_t imu_config_t; // legacy version compatibility \ No newline at end of file diff --git a/source/BNO08x.cpp b/source/BNO08x.cpp index fe5eee1..2e61e99 100644 --- a/source/BNO08x.cpp +++ b/source/BNO08x.cpp @@ -91,7 +91,7 @@ bool BNO08x::initialize() if (!hard_reset()) return false; - if (get_reset_reason() == IMUResetReason::UNDEFINED) + if (get_reset_reason() == BNO08xResetReason::UNDEFINED) { ESP_LOGE(TAG, "Initialization failed, undefined reset reason returned after reset."); return false; @@ -613,7 +613,7 @@ bool BNO08x::soft_reset() * @return The reason for the most recent recent reset ( 1 = POR (power on reset), 2 = internal reset, 3 = watchdog * timer, 4 = external reset 5 = other) */ -IMUResetReason BNO08x::get_reset_reason() +BNO08xResetReason BNO08x::get_reset_reason() { uint32_t reset_reason = 0; @@ -631,7 +631,7 @@ IMUResetReason BNO08x::get_reset_reason() ESP_LOGE(TAG, "Failed to receive product ID report."); } - return static_cast(reset_reason); + return static_cast(reset_reason); } /** @@ -1116,13 +1116,13 @@ bool BNO08x::run_full_calibration_routine() float magf_x = 0; float magf_y = 0; float magf_z = 0; - IMUAccuracy magnetometer_accuracy = IMUAccuracy::LOW; + BNO08xAccuracy magnetometer_accuracy = BNO08xAccuracy::LOW; float quat_I = 0; float quat_J = 0; float quat_K = 0; float quat_real = 0; - IMUAccuracy quat_accuracy = IMUAccuracy::LOW; + BNO08xAccuracy quat_accuracy = BNO08xAccuracy::LOW; uint16_t high_accuracy = 0; uint16_t save_calibration_attempt = 0; @@ -1157,7 +1157,7 @@ bool BNO08x::run_full_calibration_routine() vTaskDelay(5 / portTICK_PERIOD_MS); - if ((magnetometer_accuracy >= IMUAccuracy::MED) && (quat_accuracy == IMUAccuracy::HIGH)) + if ((magnetometer_accuracy >= BNO08xAccuracy::MED) && (quat_accuracy == BNO08xAccuracy::HIGH)) high_accuracy++; else high_accuracy = 0; @@ -2385,25 +2385,25 @@ void BNO08x::reset_all_data() raw_accel_X = 0U; raw_accel_Y = 0U; raw_accel_Z = 0U; - accel_accuracy = static_cast(IMUAccuracy::UNDEFINED); + accel_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); raw_lin_accel_X = 0U; raw_lin_accel_Y = 0U; raw_lin_accel_Z = 0U; - accel_lin_accuracy = static_cast(IMUAccuracy::UNDEFINED); + accel_lin_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); raw_gyro_X = 0U; raw_gyro_Y = 0U; raw_gyro_Z = 0U; - gyro_accuracy = static_cast(IMUAccuracy::UNDEFINED); + gyro_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); // reset quaternion to nan raw_quat_I = 0U; raw_quat_J = 0U; raw_quat_K = 0U; raw_quat_real = 0U; - raw_quat_radian_accuracy = static_cast(IMUAccuracy::UNDEFINED); - quat_accuracy = static_cast(IMUAccuracy::UNDEFINED); + raw_quat_radian_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); + quat_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); raw_velocity_gyro_X = 0U; raw_velocity_gyro_Y = 0U; @@ -2412,7 +2412,7 @@ void BNO08x::reset_all_data() gravity_X = 0U; gravity_Y = 0U; gravity_Z = 0U; - gravity_accuracy = static_cast(IMUAccuracy::UNDEFINED); + gravity_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); raw_uncalib_gyro_X = 0U; raw_uncalib_gyro_Y = 0U; @@ -2420,12 +2420,12 @@ void BNO08x::reset_all_data() raw_bias_X = 0U; raw_bias_Y = 0U; raw_bias_Z = 0U; - uncalib_gyro_accuracy = static_cast(IMUAccuracy::UNDEFINED); + uncalib_gyro_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); raw_magf_X = 0U; raw_magf_Y = 0U; raw_magf_Z = 0U; - magf_accuracy = static_cast(IMUAccuracy::UNDEFINED); + magf_accuracy = static_cast(BNO08xAccuracy::UNDEFINED); tap_detector = 0U; step_count = 0U; @@ -2455,12 +2455,12 @@ void BNO08x::reset_all_data() * * @return void, nothing to return */ -void BNO08x::get_magf(float& x, float& y, float& z, IMUAccuracy& accuracy) +void BNO08x::get_magf(float& x, float& y, float& z, BNO08xAccuracy& accuracy) { x = q_to_float(raw_magf_X, MAGNETOMETER_Q1); y = q_to_float(raw_magf_Y, MAGNETOMETER_Q1); z = q_to_float(raw_magf_Z, MAGNETOMETER_Q1); - accuracy = static_cast(magf_accuracy); + accuracy = static_cast(magf_accuracy); } /** @@ -2501,9 +2501,9 @@ float BNO08x::get_magf_Z() * * @return The accuracy of reported magnetic field vector. */ -IMUAccuracy BNO08x::get_magf_accuracy() +BNO08xAccuracy BNO08x::get_magf_accuracy() { - return static_cast(magf_accuracy); + return static_cast(magf_accuracy); } /** @@ -2516,12 +2516,12 @@ IMUAccuracy BNO08x::get_magf_accuracy() * * @return void, nothing to return */ -void BNO08x::get_gravity(float& x, float& y, float& z, IMUAccuracy& accuracy) +void BNO08x::get_gravity(float& x, float& y, float& z, BNO08xAccuracy& accuracy) { x = q_to_float(gravity_X, GRAVITY_Q1); y = q_to_float(gravity_Y, GRAVITY_Q1); z = q_to_float(gravity_Z, GRAVITY_Q1); - accuracy = static_cast(gravity_accuracy); + accuracy = static_cast(gravity_accuracy); } /** @@ -2559,9 +2559,9 @@ float BNO08x::get_gravity_Z() * * @return Accuracy of reported gravity. */ -IMUAccuracy BNO08x::get_gravity_accuracy() +BNO08xAccuracy BNO08x::get_gravity_accuracy() { - return static_cast(gravity_accuracy); + return static_cast(gravity_accuracy); } /** @@ -2689,14 +2689,14 @@ float BNO08x::get_yaw_deg() * * @return void, nothing to return */ -void BNO08x::get_quat(float& i, float& j, float& k, float& real, float& rad_accuracy, IMUAccuracy& accuracy) +void BNO08x::get_quat(float& i, float& j, float& k, float& real, float& rad_accuracy, BNO08xAccuracy& accuracy) { i = q_to_float(raw_quat_I, ROTATION_VECTOR_Q1); j = q_to_float(raw_quat_J, ROTATION_VECTOR_Q1); k = q_to_float(raw_quat_K, ROTATION_VECTOR_Q1); real = q_to_float(raw_quat_real, ROTATION_VECTOR_Q1); rad_accuracy = q_to_float(raw_quat_radian_accuracy, ROTATION_VECTOR_Q1); - accuracy = static_cast(quat_accuracy); + accuracy = static_cast(quat_accuracy); } /** @@ -2759,9 +2759,9 @@ float BNO08x::get_quat_radian_accuracy() * * @return The accuracy of reported quaternion. */ -IMUAccuracy BNO08x::get_quat_accuracy() +BNO08xAccuracy BNO08x::get_quat_accuracy() { - return static_cast(quat_accuracy); + return static_cast(quat_accuracy); } /** @@ -2774,12 +2774,12 @@ IMUAccuracy BNO08x::get_quat_accuracy() * * @return void, nothing to return */ -void BNO08x::get_accel(float& x, float& y, float& z, IMUAccuracy& accuracy) +void BNO08x::get_accel(float& x, float& y, float& z, BNO08xAccuracy& accuracy) { x = q_to_float(raw_accel_X, ACCELEROMETER_Q1); y = q_to_float(raw_accel_Y, ACCELEROMETER_Q1); z = q_to_float(raw_accel_Z, ACCELEROMETER_Q1); - accuracy = static_cast(accel_accuracy); + accuracy = static_cast(accel_accuracy); } /** @@ -2817,9 +2817,9 @@ float BNO08x::get_accel_Z() * * @return Accuracy of linear acceleration. */ -IMUAccuracy BNO08x::get_accel_accuracy() +BNO08xAccuracy BNO08x::get_accel_accuracy() { - return static_cast(accel_accuracy); + return static_cast(accel_accuracy); } /** @@ -2832,12 +2832,12 @@ IMUAccuracy BNO08x::get_accel_accuracy() * * @return void, nothing to return */ -void BNO08x::get_linear_accel(float& x, float& y, float& z, IMUAccuracy& accuracy) +void BNO08x::get_linear_accel(float& x, float& y, float& z, BNO08xAccuracy& accuracy) { x = q_to_float(raw_lin_accel_X, LINEAR_ACCELEROMETER_Q1); y = q_to_float(raw_lin_accel_Y, LINEAR_ACCELEROMETER_Q1); z = q_to_float(raw_lin_accel_Z, LINEAR_ACCELEROMETER_Q1); - accuracy = static_cast(accel_lin_accuracy); + accuracy = static_cast(accel_lin_accuracy); } /** @@ -2875,9 +2875,9 @@ float BNO08x::get_linear_accel_Z() * * @return Accuracy of linear acceleration. */ -IMUAccuracy BNO08x::get_linear_accel_accuracy() +BNO08xAccuracy BNO08x::get_linear_accel_accuracy() { - return static_cast(accel_lin_accuracy); + return static_cast(accel_lin_accuracy); } /** @@ -2980,12 +2980,12 @@ int16_t BNO08x::get_raw_magf_Z() * * @return void, nothing to return */ -void BNO08x::get_gyro_calibrated_velocity(float& x, float& y, float& z, IMUAccuracy& accuracy) +void BNO08x::get_gyro_calibrated_velocity(float& x, float& y, float& z, BNO08xAccuracy& accuracy) { x = q_to_float(raw_gyro_X, GYRO_Q1); y = q_to_float(raw_gyro_Y, GYRO_Q1); z = q_to_float(raw_gyro_Z, GYRO_Q1); - accuracy = static_cast(gyro_accuracy); + accuracy = static_cast(gyro_accuracy); } /** @@ -3023,9 +3023,9 @@ float BNO08x::get_gyro_calibrated_velocity_Z() * * @return Accuracy of calibrated gyro. */ -IMUAccuracy BNO08x::get_gyro_accuracy() +BNO08xAccuracy BNO08x::get_gyro_accuracy() { - return static_cast(gyro_accuracy); + return static_cast(gyro_accuracy); } /** @@ -3042,7 +3042,7 @@ IMUAccuracy BNO08x::get_gyro_accuracy() * * @return void, nothing to return */ -void BNO08x::get_uncalibrated_gyro(float& x, float& y, float& z, float& b_x, float& b_y, float& b_z, IMUAccuracy& accuracy) +void BNO08x::get_uncalibrated_gyro(float& x, float& y, float& z, float& b_x, float& b_y, float& b_z, BNO08xAccuracy& accuracy) { x = q_to_float(raw_uncalib_gyro_X, GYRO_Q1); y = q_to_float(raw_uncalib_gyro_Y, GYRO_Q1); @@ -3050,7 +3050,7 @@ void BNO08x::get_uncalibrated_gyro(float& x, float& y, float& z, float& b_x, flo b_x = q_to_float(raw_bias_X, GYRO_Q1); b_y = q_to_float(raw_bias_Y, GYRO_Q1); b_z = q_to_float(raw_bias_Z, GYRO_Q1); - accuracy = static_cast(uncalib_gyro_accuracy); + accuracy = static_cast(uncalib_gyro_accuracy); } /** @@ -3118,9 +3118,9 @@ float BNO08x::get_uncalibrated_gyro_bias_Z() * * @return Accuracy of uncalibrated gyro. */ -IMUAccuracy BNO08x::get_uncalibrated_gyro_accuracy() +BNO08xAccuracy BNO08x::get_uncalibrated_gyro_accuracy() { - return static_cast(uncalib_gyro_accuracy); + return static_cast(uncalib_gyro_accuracy); } /** diff --git a/test/InitDeinitTests.cpp b/test/InitDeinitTests.cpp index c1b626c..8038d68 100644 --- a/test/InitDeinitTests.cpp +++ b/test/InitDeinitTests.cpp @@ -86,7 +86,7 @@ TEST_CASE("Finish Init", "[InitComprehensive]") TEST_ASSERT_EQUAL(true, imu->hard_reset()); // check if reason is valid - TEST_ASSERT_NOT_EQUAL(IMUResetReason::UNDEFINED, imu->get_reset_reason()); + TEST_ASSERT_NOT_EQUAL(BNO08xResetReason::UNDEFINED, imu->get_reset_reason()); BNO08xTestHelper::print_test_msg(TEST_TAG, "Destroying test IMU."); BNO08xTestHelper::destroy_test_imu();