diff --git a/app/os/main.cpp b/app/os/main.cpp index a7ebbd2458..001bb16e37 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -21,13 +21,13 @@ #include "CoreFont.hpp" #include "CoreGraphics.hpp" #include "CoreI2C.h" +#include "CoreIMU.hpp" #include "CoreInterruptIn.h" #include "CoreJPEG.hpp" #include "CoreJPEGModeDMA.hpp" #include "CoreLCD.hpp" #include "CoreLCDDriverOTM8009A.hpp" #include "CoreLL.h" -#include "CoreLSM6DSOX.hpp" #include "CoreLTDC.hpp" #include "CoreMCU.h" #include "CoreMotor.h" @@ -265,11 +265,11 @@ namespace imu { } // namespace internal - auto lsm6dsox = CoreLSM6DSOX(internal::i2c, internal::drdy_irq); + auto coreimu = CoreIMU(internal::i2c, internal::drdy_irq); } // namespace imu -auto imukit = IMUKit {imu::lsm6dsox}; +auto imukit = IMUKit {imu::coreimu}; namespace motion::internal { @@ -540,7 +540,7 @@ namespace deep_sleep { &motors::right::motor, &display::internal::corelcd, &rfid::reader, - &imu::lsm6dsox, + &imu::coreimu, }); } @@ -578,7 +578,7 @@ auto main() -> int commandkit.registerCommand(command::list); activitykit.registerActivities(activities::activities); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.init(); robot::controller.initializeComponents(); diff --git a/drivers/CoreIMU/CMakeLists.txt b/drivers/CoreIMU/CMakeLists.txt index edad0f0d94..ff11bf7333 100644 --- a/drivers/CoreIMU/CMakeLists.txt +++ b/drivers/CoreIMU/CMakeLists.txt @@ -13,7 +13,7 @@ target_include_directories(CoreIMU target_sources(CoreIMU PRIVATE extern/source/lsm6dsox_reg.c - source/CoreLSM6DSOX.cpp + source/CoreIMU.cpp ) target_link_libraries(CoreIMU @@ -23,6 +23,6 @@ target_link_libraries(CoreIMU if(${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests") leka_unit_tests_sources( - tests/CoreLSM6DSOX_test.cpp + tests/CoreIMU_test.cpp ) endif() diff --git a/drivers/CoreIMU/include/CoreLSM6DSOX.hpp b/drivers/CoreIMU/include/CoreIMU.hpp similarity index 79% rename from drivers/CoreIMU/include/CoreLSM6DSOX.hpp rename to drivers/CoreIMU/include/CoreIMU.hpp index 818cfd923d..bed4d3f779 100644 --- a/drivers/CoreIMU/include/CoreLSM6DSOX.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -8,17 +8,17 @@ #include "CoreEventQueue.h" #include "CoreInterruptIn.h" -#include "interface/LSM6DSOX.hpp" #include "interface/drivers/DeepSleepEnabled.h" #include "interface/drivers/I2C.h" +#include "interface/drivers/IMU.hpp" #include "lsm6dsox_reg.h" namespace leka { -class CoreLSM6DSOX : public interface::LSM6DSOX, public interface::DeepSleepEnabled +class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled { public: - explicit CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq); + explicit CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq); void init() final; @@ -33,9 +33,9 @@ class CoreLSM6DSOX : public interface::LSM6DSOX, public interface::DeepSleepEnab auto read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t; auto write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t; - static auto ptr_io_write(CoreLSM6DSOX *handle, uint8_t write_address, uint8_t *p_buffer, + static auto ptr_io_write(CoreIMU *handle, uint8_t write_address, uint8_t *p_buffer, uint16_t number_bytes_to_write) -> int32_t; - static auto ptr_io_read(CoreLSM6DSOX *handle, uint8_t read_address, uint8_t *p_buffer, + static auto ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buffer, uint16_t number_bytes_to_read) -> int32_t; void onGyrDataReadyHandler(auto timestamp); diff --git a/drivers/CoreIMU/source/CoreLSM6DSOX.cpp b/drivers/CoreIMU/source/CoreIMU.cpp similarity index 79% rename from drivers/CoreIMU/source/CoreLSM6DSOX.cpp rename to drivers/CoreIMU/source/CoreIMU.cpp index 2396598e43..2a749aafeb 100644 --- a/drivers/CoreIMU/source/CoreLSM6DSOX.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -2,11 +2,11 @@ // Copyright 2022 APF France handicap // SPDX-License-Identifier: Apache-2.0 -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" namespace leka { -CoreLSM6DSOX::CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2c(i2c), _drdy_irq(drdy_irq) +CoreIMU::CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2c(i2c), _drdy_irq(drdy_irq) { // ? NOLINTNEXTLINE - allow reinterpret_cast as there are no alternatives _register_io_function.write_reg = reinterpret_cast(ptr_io_write); @@ -15,7 +15,7 @@ CoreLSM6DSOX::CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2 _register_io_function.handle = static_cast(this); } -void CoreLSM6DSOX::init() +void CoreIMU::init() { _event_queue.dispatch_forever(); @@ -33,7 +33,7 @@ void CoreLSM6DSOX::init() setGyrDataReadyInterrupt(); } -void CoreLSM6DSOX::setPowerMode(PowerMode mode) +void CoreIMU::setPowerMode(PowerMode mode) { auto xl_power_mode = lsm6dsox_xl_hm_mode_t {}; auto gy_power_mode = lsm6dsox_g_hm_mode_t {}; @@ -71,12 +71,12 @@ void CoreLSM6DSOX::setPowerMode(PowerMode mode) lsm6dsox_gy_data_rate_set(&_register_io_function, gy_odr); } -void CoreLSM6DSOX::registerOnGyDataReadyCallback(drdy_callback_t const &callback) +void CoreIMU::registerOnGyDataReadyCallback(drdy_callback_t const &callback) { _on_gy_data_ready_callback = callback; } -void CoreLSM6DSOX::onGyrDataReadyHandler(auto timestamp) +void CoreIMU::onGyrDataReadyHandler(auto timestamp) { static constexpr auto _1k = float {1000.F}; @@ -97,17 +97,17 @@ void CoreLSM6DSOX::onGyrDataReadyHandler(auto timestamp) } } -void CoreLSM6DSOX::enableDeepSleep() +void CoreIMU::enableDeepSleep() { - setPowerMode(interface::LSM6DSOX::PowerMode::Off); + setPowerMode(interface::IMU::PowerMode::Off); } -void CoreLSM6DSOX::disableDeepSleep() +void CoreIMU::disableDeepSleep() { - setPowerMode(interface::LSM6DSOX::PowerMode::Normal); + setPowerMode(interface::IMU::PowerMode::Normal); } -auto CoreLSM6DSOX::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t +auto CoreIMU::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t { // Send component address, without STOP condition auto ret = _i2c.write(_address, ®ister_address, 1, true); @@ -119,7 +119,7 @@ auto CoreLSM6DSOX::read(uint8_t register_address, uint16_t number_bytes_to_read, return ret; } -auto CoreLSM6DSOX::write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t +auto CoreIMU::write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t { if (number_bytes_to_write >= kMaxBufferLength) { return 1; @@ -131,19 +131,19 @@ auto CoreLSM6DSOX::write(uint8_t register_address, uint16_t number_bytes_to_writ return ret; } -auto CoreLSM6DSOX::ptr_io_write(CoreLSM6DSOX *handle, uint8_t write_address, uint8_t *p_buffer, - uint16_t number_bytes_to_write) -> int32_t +auto CoreIMU::ptr_io_write(CoreIMU *handle, uint8_t write_address, uint8_t *p_buffer, + uint16_t number_bytes_to_write) -> int32_t { return handle->write(write_address, number_bytes_to_write, p_buffer); } -auto CoreLSM6DSOX::ptr_io_read(CoreLSM6DSOX *handle, uint8_t read_address, uint8_t *p_buffer, - uint16_t number_bytes_to_read) -> int32_t +auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buffer, + uint16_t number_bytes_to_read) -> int32_t { return handle->read(read_address, number_bytes_to_read, p_buffer); } -void CoreLSM6DSOX::setGyrDataReadyInterrupt() +void CoreIMU::setGyrDataReadyInterrupt() { lsm6dsox_dataready_pulsed_t drdy_pulsed {LSM6DSOX_DRDY_PULSED}; lsm6dsox_data_ready_mode_set(&_register_io_function, drdy_pulsed); diff --git a/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp b/drivers/CoreIMU/tests/CoreIMU_test.cpp similarity index 62% rename from drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp rename to drivers/CoreIMU/tests/CoreIMU_test.cpp index a63bcc635e..5f0136acca 100644 --- a/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp +++ b/drivers/CoreIMU/tests/CoreIMU_test.cpp @@ -4,7 +4,7 @@ #include -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "gtest/gtest.h" #include "mocks/leka/CoreI2C.h" #include "mocks/leka/EventQueue.h" @@ -16,24 +16,24 @@ using testing::_; using testing::AtLeast; using testing::MockFunction; -class CoreLSM6DSOXTest : public ::testing::Test +class CoreIMUTest : public ::testing::Test { protected: - CoreLSM6DSOXTest() = default; + CoreIMUTest() = default; void SetUp() override { EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.init(); + coreimu.init(); } // void TearDown() override {} mock::CoreI2C mocki2c {}; CoreInterruptIn drdy_irq {NC}; - CoreLSM6DSOX lsm6dsox {mocki2c, drdy_irq}; + CoreIMU coreimu {mocki2c, drdy_irq}; // ? Instantiation of mock::EventQueue is needed to setup the underlying stubs that will make the mock work // ? correctly. Without it UT are failing @@ -41,66 +41,66 @@ class CoreLSM6DSOXTest : public ::testing::Test mock::EventQueue _ {}; }; -TEST_F(CoreLSM6DSOXTest, initialization) +TEST_F(CoreIMUTest, initialization) { - ASSERT_NE(&lsm6dsox, nullptr); + ASSERT_NE(&coreimu, nullptr); } -TEST_F(CoreLSM6DSOXTest, setPowerMode) +TEST_F(CoreIMUTest, setPowerMode) { EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + coreimu.setPowerMode(CoreIMU::PowerMode::Off); EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::UltraLow); + coreimu.setPowerMode(CoreIMU::PowerMode::UltraLow); EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + coreimu.setPowerMode(CoreIMU::PowerMode::Normal); EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::High); + coreimu.setPowerMode(CoreIMU::PowerMode::High); } -TEST_F(CoreLSM6DSOXTest, onGyrDRDY) +TEST_F(CoreIMUTest, onGyrDRDY) { - MockFunction mock_callback; + MockFunction mock_callback; EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); EXPECT_CALL(mock_callback, Call).Times(1); - lsm6dsox.registerOnGyDataReadyCallback(mock_callback.AsStdFunction()); + coreimu.registerOnGyDataReadyCallback(mock_callback.AsStdFunction()); auto on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); } -TEST_F(CoreLSM6DSOXTest, emptyOnGyrDrdyCallback) +TEST_F(CoreIMUTest, emptyOnGyrDrdyCallback) { - lsm6dsox.registerOnGyDataReadyCallback({}); + coreimu.registerOnGyDataReadyCallback({}); auto on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); } -TEST_F(CoreLSM6DSOXTest, enableDeepSleep) +TEST_F(CoreIMUTest, enableDeepSleep) { EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + coreimu.setPowerMode(CoreIMU::PowerMode::Off); - lsm6dsox.enableDeepSleep(); + coreimu.enableDeepSleep(); } -TEST_F(CoreLSM6DSOXTest, disableDeepSleep) +TEST_F(CoreIMUTest, disableDeepSleep) { EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + coreimu.setPowerMode(CoreIMU::PowerMode::Normal); - lsm6dsox.disableDeepSleep(); + coreimu.disableDeepSleep(); } diff --git a/drivers/CoreIMU/include/interface/LSM6DSOX.hpp b/include/interface/drivers/IMU.hpp similarity index 95% rename from drivers/CoreIMU/include/interface/LSM6DSOX.hpp rename to include/interface/drivers/IMU.hpp index dc1bf18a39..71d70c798c 100644 --- a/drivers/CoreIMU/include/interface/LSM6DSOX.hpp +++ b/include/interface/drivers/IMU.hpp @@ -10,10 +10,10 @@ namespace leka::interface { -class LSM6DSOX +class IMU { public: - virtual ~LSM6DSOX() = default; + virtual ~IMU() = default; enum class PowerMode { diff --git a/libs/IMUKit/include/IMUKit.hpp b/libs/IMUKit/include/IMUKit.hpp index ababcfb531..10a459cdc1 100644 --- a/libs/IMUKit/include/IMUKit.hpp +++ b/libs/IMUKit/include/IMUKit.hpp @@ -4,7 +4,7 @@ #pragma once -#include "interface/LSM6DSOX.hpp" +#include "interface/drivers/IMU.hpp" #include "interface/libs/IMUKit.hpp" namespace leka { @@ -12,7 +12,7 @@ namespace leka { class IMUKit : public interface::IMUKit { public: - explicit IMUKit(interface::LSM6DSOX &lsm6dsox) : _lsm6dsox(lsm6dsox) {} + explicit IMUKit(interface::IMU &imu) : _imu(imu) {} void init(); void start() final; @@ -23,9 +23,9 @@ class IMUKit : public interface::IMUKit [[nodiscard]] auto getEulerAngles() const -> EulerAngles final; private: - void drdy_callback(interface::LSM6DSOX::SensorData data); + void drdy_callback(interface::IMU::SensorData data); - interface::LSM6DSOX &_lsm6dsox; + interface::IMU &_imu; EulerAngles _euler_angles {}; angles_ready_callback_t _on_euler_angles_rdy_callback {}; }; diff --git a/libs/IMUKit/source/IMUKit.cpp b/libs/IMUKit/source/IMUKit.cpp index d1681c2691..740ffbf1e2 100644 --- a/libs/IMUKit/source/IMUKit.cpp +++ b/libs/IMUKit/source/IMUKit.cpp @@ -55,19 +55,19 @@ void IMUKit::init() FusionOffsetInitialise(&fusion::global_offset, fusion::kODR_HZ); } - auto on_drdy_callback = [this](const interface::LSM6DSOX::SensorData &data) { drdy_callback(data); }; + auto on_drdy_callback = [this](const interface::IMU::SensorData &data) { drdy_callback(data); }; - _lsm6dsox.registerOnGyDataReadyCallback(on_drdy_callback); + _imu.registerOnGyDataReadyCallback(on_drdy_callback); } void IMUKit::start() { - _lsm6dsox.setPowerMode(interface::LSM6DSOX::PowerMode::Normal); + _imu.setPowerMode(interface::IMU::PowerMode::Normal); } void IMUKit::stop() { - _lsm6dsox.setPowerMode(interface::LSM6DSOX::PowerMode::Off); + _imu.setPowerMode(interface::IMU::PowerMode::Off); } void IMUKit::setOrigin() @@ -88,10 +88,10 @@ void IMUKit::onEulerAnglesReady(angles_ready_callback_t const &callback) _on_euler_angles_rdy_callback = callback; } -void IMUKit::drdy_callback(const interface::LSM6DSOX::SensorData data) +void IMUKit::drdy_callback(const interface::IMU::SensorData data) { // ? Note: For a detailed explanation on the code below, checkout - // ? https://github.com/leka/LekaOS/tree/develop/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration + // ? https://github.com/leka/LekaOS/tree/develop/spikes/lk_sensors_imu_imu_fusion_calibration fusion::timestamp_now = rtos::Kernel::Clock::now(); diff --git a/libs/IMUKit/tests/IMUKit_test.cpp b/libs/IMUKit/tests/IMUKit_test.cpp index 04b1692468..cd83887f93 100644 --- a/libs/IMUKit/tests/IMUKit_test.cpp +++ b/libs/IMUKit/tests/IMUKit_test.cpp @@ -4,12 +4,12 @@ #include "IMUKit.hpp" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "ThisThread.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "mocks/leka/CoreI2C.h" -#include "mocks/leka/LSM6DSOX.h" +#include "mocks/leka/IMU.h" #include "stubs/leka/EventLoopKit.h" #include "stubs/mbed/InterruptIn.h" #include "stubs/mbed/Kernel.h" @@ -25,9 +25,9 @@ class IMUKitTest : public ::testing::Test void SetUp() override { imukit.init(); } // void TearDown() override {} - mock::LSM6DSOX mock_lsm6dox {}; + mock::IMU mock_imu {}; - IMUKit imukit {mock_lsm6dox}; + IMUKit imukit {mock_imu}; }; TEST_F(IMUKitTest, initialization) @@ -37,14 +37,14 @@ TEST_F(IMUKitTest, initialization) TEST_F(IMUKitTest, start) { - EXPECT_CALL(mock_lsm6dox, setPowerMode(interface::LSM6DSOX::PowerMode::Normal)).Times(1); + EXPECT_CALL(mock_imu, setPowerMode(interface::IMU::PowerMode::Normal)).Times(1); imukit.start(); } TEST_F(IMUKitTest, stop) { - EXPECT_CALL(mock_lsm6dox, setPowerMode(interface::LSM6DSOX::PowerMode::Off)).Times(1); + EXPECT_CALL(mock_imu, setPowerMode(interface::IMU::PowerMode::Off)).Times(1); imukit.stop(); } @@ -71,22 +71,22 @@ TEST_F(IMUKitTest, onDataReady) imukit.onEulerAnglesReady(mock_callback.AsStdFunction()); const auto data_initial = - interface::LSM6DSOX::SensorData {.xl = {.x = 0.F, .y = 0.F, .z = 0.F}, .gy = {.x = 0.F, .y = 0.F, .z = 0.F}}; + interface::IMU::SensorData {.xl = {.x = 0.F, .y = 0.F, .z = 0.F}, .gy = {.x = 0.F, .y = 0.F, .z = 0.F}}; EXPECT_CALL(mock_callback, Call); - mock_lsm6dox.call_drdy_callback(data_initial); + mock_imu.call_drdy_callback(data_initial); const auto angles_initial = imukit.getEulerAngles(); spy_kernel_addElapsedTimeToTickCount(80ms); const auto data_updated = - interface::LSM6DSOX::SensorData {.xl = {.x = 1.F, .y = 2.F, .z = 3.F}, .gy = {.x = 1.F, .y = 2.F, .z = 3.F}}; + interface::IMU::SensorData {.xl = {.x = 1.F, .y = 2.F, .z = 3.F}, .gy = {.x = 1.F, .y = 2.F, .z = 3.F}}; EXPECT_CALL(mock_callback, Call); - mock_lsm6dox.call_drdy_callback(data_updated); + mock_imu.call_drdy_callback(data_updated); auto angles_updated = imukit.getEulerAngles(); @@ -100,18 +100,18 @@ TEST_F(IMUKitTest, onDataReadyEmptyEulerAngleCallback) imukit.onEulerAnglesReady({}); const auto data_initial = - interface::LSM6DSOX::SensorData {.xl = {.x = 0.F, .y = 0.F, .z = 0.F}, .gy = {.x = 0.F, .y = 0.F, .z = 0.F}}; + interface::IMU::SensorData {.xl = {.x = 0.F, .y = 0.F, .z = 0.F}, .gy = {.x = 0.F, .y = 0.F, .z = 0.F}}; - mock_lsm6dox.call_drdy_callback(data_initial); + mock_imu.call_drdy_callback(data_initial); const auto angles_initial = imukit.getEulerAngles(); spy_kernel_addElapsedTimeToTickCount(80ms); const auto data_updated = - interface::LSM6DSOX::SensorData {.xl = {.x = 1.F, .y = 2.F, .z = 3.F}, .gy = {.x = 1.F, .y = 2.F, .z = 3.F}}; + interface::IMU::SensorData {.xl = {.x = 1.F, .y = 2.F, .z = 3.F}, .gy = {.x = 1.F, .y = 2.F, .z = 3.F}}; - mock_lsm6dox.call_drdy_callback(data_updated); + mock_imu.call_drdy_callback(data_updated); auto angles_updated = imukit.getEulerAngles(); diff --git a/spikes/CMakeLists.txt b/spikes/CMakeLists.txt index cc3bd94479..e2deb2c4b9 100644 --- a/spikes/CMakeLists.txt +++ b/spikes/CMakeLists.txt @@ -28,8 +28,8 @@ add_subdirectory(${SPIKES_DIR}/lk_qdac) add_subdirectory(${SPIKES_DIR}/lk_reinforcer) add_subdirectory(${SPIKES_DIR}/lk_rfid) add_subdirectory(${SPIKES_DIR}/lk_sensors_battery) -add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_lsm6dsox) -add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_lsm6dsox_fusion_calibration) +add_subdirectory(${SPIKES_DIR}/lk_sensors_imu) +add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_fusion_calibration) add_subdirectory(${SPIKES_DIR}/lk_sensors_light) add_subdirectory(${SPIKES_DIR}/lk_sensors_microphone) add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity) @@ -71,8 +71,8 @@ add_dependencies(spikes_leka spike_lk_reinforcer spike_lk_rfid spike_lk_sensors_battery - spike_lk_sensors_imu_lsm6dsox - spike_lk_sensors_imu_lsm6dsox_fusion_calibration + spike_lk_sensors_imu + spike_lk_sensors_imu_fusion_calibration spike_lk_sensors_light spike_lk_sensors_microphone spike_lk_sensors_temperature_humidity diff --git a/spikes/lk_activity_kit/main.cpp b/spikes/lk_activity_kit/main.cpp index 453d817223..cd563f9912 100644 --- a/spikes/lk_activity_kit/main.cpp +++ b/spikes/lk_activity_kit/main.cpp @@ -18,6 +18,7 @@ #include "CoreFont.hpp" #include "CoreGraphics.hpp" #include "CoreI2C.h" +#include "CoreIMU.hpp" #include "CoreInterruptIn.h" #include "CoreJPEG.hpp" #include "CoreJPEGModeDMA.hpp" @@ -25,7 +26,6 @@ #include "CoreLCD.hpp" #include "CoreLCDDriverOTM8009A.hpp" #include "CoreLL.h" -#include "CoreLSM6DSOX.hpp" #include "CoreLTDC.hpp" #include "CoreMotor.h" #include "CorePwm.h" @@ -195,11 +195,11 @@ namespace imu { } // namespace internal - auto lsm6dsox = CoreLSM6DSOX(internal::i2c, internal::drdy_irq); + auto coreimu = CoreIMU(internal::i2c, internal::drdy_irq); } // namespace imu -auto imukit = IMUKit {imu::lsm6dsox}; +auto imukit = IMUKit {imu::coreimu}; namespace motion::internal { @@ -276,7 +276,7 @@ auto main() -> int sd::init(); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.init(); ledkit.init(); diff --git a/spikes/lk_command_kit/main.cpp b/spikes/lk_command_kit/main.cpp index 86c3bf1f79..f33ff82613 100644 --- a/spikes/lk_command_kit/main.cpp +++ b/spikes/lk_command_kit/main.cpp @@ -13,6 +13,7 @@ #include "CoreFont.hpp" #include "CoreGraphics.hpp" #include "CoreI2C.h" +#include "CoreIMU.hpp" #include "CoreJPEG.hpp" #include "CoreJPEGModeDMA.hpp" #include "CoreJPEGModePolling.hpp" @@ -20,7 +21,6 @@ #include "CoreLCDDriverOTM8009A.hpp" #include "CoreLED.h" #include "CoreLL.h" -#include "CoreLSM6DSOX.hpp" #include "CoreLTDC.hpp" #include "CoreMotor.h" #include "CorePwm.h" @@ -104,11 +104,11 @@ namespace internal { } // namespace internal -CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); +CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu -auto imukit = IMUKit {imu::lsm6dsox}; +auto imukit = IMUKit {imu::coreimu}; namespace motion::internal { @@ -255,7 +255,7 @@ auto main() -> int display::internal::corelcd.turnOn(); cmdkit.registerCommand(command::list); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.init(); turnOff(); diff --git a/spikes/lk_imu_kit/main.cpp b/spikes/lk_imu_kit/main.cpp index c93230c6ba..fc3c4fc594 100644 --- a/spikes/lk_imu_kit/main.cpp +++ b/spikes/lk_imu_kit/main.cpp @@ -5,7 +5,7 @@ #include "rtos/ThisThread.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "HelloWorld.h" #include "IMUKit.hpp" #include "LogKit.h" @@ -24,11 +24,11 @@ namespace imu { } // namespace internal - CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu -IMUKit imukit(imu::lsm6dsox); +IMUKit imukit(imu::coreimu); } // namespace @@ -40,7 +40,7 @@ auto main() -> int HelloWorld hello; hello.start(); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.stop(); imukit.init(); diff --git a/spikes/lk_motion_kit/main.cpp b/spikes/lk_motion_kit/main.cpp index 26ec4622ca..7b5b93e3ab 100644 --- a/spikes/lk_motion_kit/main.cpp +++ b/spikes/lk_motion_kit/main.cpp @@ -6,7 +6,7 @@ #include "CoreBufferedSerial.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "CoreMotor.h" #include "CorePwm.h" #include "CoreRFIDReaderCR95HF.h" @@ -65,11 +65,11 @@ namespace imu { } // namespace internal - CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu -auto imukit = IMUKit {imu::lsm6dsox}; +auto imukit = IMUKit {imu::coreimu}; namespace motion::internal { @@ -131,7 +131,7 @@ auto main() -> int HelloWorld hello; hello.start(); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.init(); rfidkit.init(); diff --git a/spikes/lk_reinforcer/main.cpp b/spikes/lk_reinforcer/main.cpp index ae6957ef85..763177c878 100644 --- a/spikes/lk_reinforcer/main.cpp +++ b/spikes/lk_reinforcer/main.cpp @@ -13,12 +13,12 @@ #include "CoreFont.hpp" #include "CoreGraphics.hpp" #include "CoreI2C.h" +#include "CoreIMU.hpp" #include "CoreJPEG.hpp" #include "CoreJPEGModeDMA.hpp" #include "CoreLCD.hpp" #include "CoreLED.h" #include "CoreLL.h" -#include "CoreLSM6DSOX.hpp" #include "CoreLTDC.hpp" #include "CoreMotor.h" #include "CorePwm.h" @@ -142,11 +142,11 @@ namespace imu { } // namespace internal - CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu -auto imukit = IMUKit {imu::lsm6dsox}; +auto imukit = IMUKit {imu::coreimu}; namespace motion::internal { @@ -202,7 +202,7 @@ auto main() -> int ledkit.init(); videokit.initializeScreen(); - imu::lsm6dsox.init(); + imu::coreimu.init(); imukit.init(); rtos::ThisThread::sleep_for(3s); diff --git a/spikes/lk_sensors_imu/CMakeLists.txt b/spikes/lk_sensors_imu/CMakeLists.txt new file mode 100644 index 0000000000..308279084e --- /dev/null +++ b/spikes/lk_sensors_imu/CMakeLists.txt @@ -0,0 +1,22 @@ +# Leka - LekaOS +# Copyright 2022 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +add_mbed_executable(spike_lk_sensors_imu) + +target_include_directories(spike_lk_sensors_imu + PRIVATE + . +) + +target_sources(spike_lk_sensors_imu + PRIVATE + main.cpp +) + +target_link_libraries(spike_lk_sensors_imu + CoreIMU + CoreI2C +) + +target_link_custom_leka_targets(spike_lk_sensors_imu) diff --git a/spikes/lk_sensors_imu_lsm6dsox/main.cpp b/spikes/lk_sensors_imu/main.cpp similarity index 73% rename from spikes/lk_sensors_imu_lsm6dsox/main.cpp rename to spikes/lk_sensors_imu/main.cpp index 554511ee4a..dd011ba1d7 100644 --- a/spikes/lk_sensors_imu_lsm6dsox/main.cpp +++ b/spikes/lk_sensors_imu/main.cpp @@ -7,7 +7,7 @@ #include "rtos/ThisThread.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "HelloWorld.h" #include "LogKit.h" @@ -25,7 +25,7 @@ namespace imu { } // namespace internal - CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu @@ -38,11 +38,11 @@ auto main() -> int HelloWorld hello; hello.start(); - imu::lsm6dsox.init(); + imu::coreimu.init(); - imu::lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Off); - auto callback = [](const interface::LSM6DSOX::SensorData data) { + auto callback = [](const interface::IMU::SensorData data) { const auto &[xlx, xly, xlz] = data.xl; const auto &[gx, gy, gz] = data.gy; const auto timestamp = data.timestamp.time_since_epoch().count(); @@ -51,16 +51,16 @@ auto main() -> int timestamp, xlx, xly, xlz, gx, gy, gz); }; - imu::lsm6dsox.registerOnGyDataReadyCallback(callback); + imu::coreimu.registerOnGyDataReadyCallback(callback); while (true) { log_info("Setting normal power mode for 5s"); rtos::ThisThread::sleep_for(1s); - imu::lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Normal); rtos::ThisThread::sleep_for(5s); - imu::lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Off); rtos::ThisThread::sleep_for(500ms); log_info("Turning off for 5s"); diff --git a/spikes/lk_sensors_imu_fusion_calibration/CMakeLists.txt b/spikes/lk_sensors_imu_fusion_calibration/CMakeLists.txt new file mode 100644 index 0000000000..ff06f2bb67 --- /dev/null +++ b/spikes/lk_sensors_imu_fusion_calibration/CMakeLists.txt @@ -0,0 +1,23 @@ +# Leka - LekaOS +# Copyright 2023 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +add_mbed_executable(spike_lk_sensors_imu_fusion_calibration) + +target_include_directories(spike_lk_sensors_imu_fusion_calibration + PRIVATE + . +) + +target_sources(spike_lk_sensors_imu_fusion_calibration + PRIVATE + main.cpp +) + +target_link_libraries(spike_lk_sensors_imu_fusion_calibration + CoreIMU + CoreI2C + Fusion +) + +target_link_custom_leka_targets(spike_lk_sensors_imu_fusion_calibration) diff --git a/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/main.cpp b/spikes/lk_sensors_imu_fusion_calibration/main.cpp similarity index 90% rename from spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/main.cpp rename to spikes/lk_sensors_imu_fusion_calibration/main.cpp index f9aee3d5db..b80691cb6b 100644 --- a/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/main.cpp +++ b/spikes/lk_sensors_imu_fusion_calibration/main.cpp @@ -8,7 +8,7 @@ #include "rtos/ThisThread.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "LogKit.h" // ? Note the following code has been heavily inspired from: @@ -31,7 +31,7 @@ namespace imu { } // namespace internal - CoreLSM6DSOX lsm6dsox(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::drdy_irq); } // namespace imu @@ -48,14 +48,14 @@ namespace fusion { .rejectionTimeout = static_cast(5 * kODR_HZ), // ? # of samples in 5 seconds }; - interface::LSM6DSOX::SensorData::time_point_t timestamp_previous = {}; + interface::IMU::SensorData::time_point_t timestamp_previous = {}; auto global_offset = FusionOffset {}; constexpr auto CALIBRATION = bool {true}; // constexpr auto CALIBRATION = bool {false}; - void callback(const interface::LSM6DSOX::SensorData data) + void callback(const interface::IMU::SensorData data) { auto timestamp_now = data.timestamp; auto timestamp_now_us = std::chrono::microseconds {timestamp_now.time_since_epoch()}.count(); @@ -119,9 +119,9 @@ auto main() -> int rtos::ThisThread::sleep_for(1s); - imu::lsm6dsox.init(); + imu::coreimu.init(); - imu::lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Off); // ? Initialise algorithms FusionAhrsInitialise(&fusion::ahrs); @@ -136,8 +136,8 @@ auto main() -> int rtos::ThisThread::sleep_for(1s); - imu::lsm6dsox.registerOnGyDataReadyCallback(fusion::callback); - imu::lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + imu::coreimu.registerOnGyDataReadyCallback(fusion::callback); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Normal); while (true) { rtos::ThisThread::sleep_for(5s); diff --git a/spikes/lk_sensors_imu_lsm6dsox/CMakeLists.txt b/spikes/lk_sensors_imu_lsm6dsox/CMakeLists.txt deleted file mode 100644 index 6764b69af4..0000000000 --- a/spikes/lk_sensors_imu_lsm6dsox/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -# Leka - LekaOS -# Copyright 2022 APF France handicap -# SPDX-License-Identifier: Apache-2.0 - -add_mbed_executable(spike_lk_sensors_imu_lsm6dsox) - -target_include_directories(spike_lk_sensors_imu_lsm6dsox - PRIVATE - . -) - -target_sources(spike_lk_sensors_imu_lsm6dsox - PRIVATE - main.cpp -) - -target_link_libraries(spike_lk_sensors_imu_lsm6dsox - CoreIMU - CoreI2C -) - -target_link_custom_leka_targets(spike_lk_sensors_imu_lsm6dsox) diff --git a/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/CMakeLists.txt b/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/CMakeLists.txt deleted file mode 100644 index d7ae9518e5..0000000000 --- a/spikes/lk_sensors_imu_lsm6dsox_fusion_calibration/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Leka - LekaOS -# Copyright 2023 APF France handicap -# SPDX-License-Identifier: Apache-2.0 - -add_mbed_executable(spike_lk_sensors_imu_lsm6dsox_fusion_calibration) - -target_include_directories(spike_lk_sensors_imu_lsm6dsox_fusion_calibration - PRIVATE - . -) - -target_sources(spike_lk_sensors_imu_lsm6dsox_fusion_calibration - PRIVATE - main.cpp -) - -target_link_libraries(spike_lk_sensors_imu_lsm6dsox_fusion_calibration - CoreIMU - CoreI2C - Fusion -) - -target_link_custom_leka_targets(spike_lk_sensors_imu_lsm6dsox_fusion_calibration) diff --git a/tests/functional/tests/core_imu/CMakeLists.txt b/tests/functional/tests/core_imu/CMakeLists.txt index 49964ee343..125723efc3 100644 --- a/tests/functional/tests/core_imu/CMakeLists.txt +++ b/tests/functional/tests/core_imu/CMakeLists.txt @@ -10,7 +10,7 @@ register_functional_test( . SOURCES - suite_core_lsm6dsox.cpp + suite_core_imu.cpp LINK_LIBRARIES CoreI2C diff --git a/tests/functional/tests/core_imu/suite_core_lsm6dsox.cpp b/tests/functional/tests/core_imu/suite_core_imu.cpp similarity index 53% rename from tests/functional/tests/core_imu/suite_core_lsm6dsox.cpp rename to tests/functional/tests/core_imu/suite_core_imu.cpp index ca848ed83a..0e35296aef 100644 --- a/tests/functional/tests/core_imu/suite_core_lsm6dsox.cpp +++ b/tests/functional/tests/core_imu/suite_core_imu.cpp @@ -6,7 +6,7 @@ #include "./utils.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "tests/config.h" using namespace leka; @@ -14,33 +14,33 @@ using namespace std::chrono; using namespace boost::ut; using namespace boost::ut::bdd; -suite suite_lsm6dsox = [] { +suite suite_coreimu = [] { auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto lsm6dsox = CoreLSM6DSOX {i2c, drdy_irq}; - auto sensor_data = leka::interface::LSM6DSOX::SensorData(); + auto coreimu = CoreIMU {i2c, drdy_irq}; + auto sensor_data = leka::interface::IMU::SensorData(); "initialization"_test = [&] { - expect(neq(&lsm6dsox, nullptr)); - lsm6dsox.init(); + expect(neq(&coreimu, nullptr)); + coreimu.init(); - auto sensor_callback = [&](const leka::interface::LSM6DSOX::SensorData &data) { sensor_data = data; }; - lsm6dsox.registerOnGyDataReadyCallback(sensor_callback); + auto sensor_callback = [&](const leka::interface::IMU::SensorData &data) { sensor_data = data; }; + coreimu.registerOnGyDataReadyCallback(sensor_callback); }; - scenario("lsm6dsox - power mode") = [&] { + scenario("imu - power mode") = [&] { given("powermode is set to off") = [&] { - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + coreimu.setPowerMode(CoreIMU::PowerMode::Off); then("I expect imu data to not change over time") = [&] { - expect(not values_did_change_over_time(lsm6dsox)); + expect(not values_did_change_over_time(coreimu)); }; }; given("powermode is set to normal again") = [&] { - lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + coreimu.setPowerMode(CoreIMU::PowerMode::Normal); - then("I expect imu data to change over time") = [&] { expect(values_did_change_over_time(lsm6dsox)); }; + then("I expect imu data to change over time") = [&] { expect(values_did_change_over_time(coreimu)); }; }; }; }; diff --git a/tests/functional/tests/core_imu/utils.h b/tests/functional/tests/core_imu/utils.h index e2e829cfdf..cbe25cf7ed 100644 --- a/tests/functional/tests/core_imu/utils.h +++ b/tests/functional/tests/core_imu/utils.h @@ -10,20 +10,20 @@ #include "rtos/ThisThread.h" #include "boost/ut.hpp" -#include "interface/LSM6DSOX.hpp" +#include "interface/drivers/IMU.hpp" -inline auto values_did_change_over_time(leka::interface::LSM6DSOX &lsm6dsox) +inline auto values_did_change_over_time(leka::interface::IMU &imu) { using namespace std::chrono; using namespace boost::ut; - auto sensor_data = leka::interface::LSM6DSOX::SensorData(); + auto sensor_data = leka::interface::IMU::SensorData(); auto i_batch = std::vector {}; auto f_batch = std::vector {}; - auto sensor_callback = [&](const leka::interface::LSM6DSOX::SensorData &data) { sensor_data = data; }; - lsm6dsox.registerOnGyDataReadyCallback(sensor_callback); + auto sensor_callback = [&](const leka::interface::IMU::SensorData &data) { sensor_data = data; }; + imu.registerOnGyDataReadyCallback(sensor_callback); for (auto i = 0; i < 10; ++i) { auto [xlx, xly, xlz] = sensor_data.xl; diff --git a/tests/functional/tests/deep_sleep_imu/suite_imu.cpp b/tests/functional/tests/deep_sleep_imu/suite_imu.cpp index 294e1a0154..ea9cae75f2 100644 --- a/tests/functional/tests/deep_sleep_imu/suite_imu.cpp +++ b/tests/functional/tests/deep_sleep_imu/suite_imu.cpp @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "tests/config.h" #include "tests/utils_sleep.h" @@ -14,7 +14,7 @@ using namespace boost::ut::bdd; auto i2c = CoreI2C {PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL}; auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; -auto coreimu = CoreLSM6DSOX {i2c, drdy_irq}; +auto coreimu = CoreIMU {i2c, drdy_irq}; suite suite_imu = [] { scenario("imu initialization") = [] { diff --git a/tests/functional/tests/imu_kit/suite_imu_kit.cpp b/tests/functional/tests/imu_kit/suite_imu_kit.cpp index 56363c3744..0d1c9ac29b 100644 --- a/tests/functional/tests/imu_kit/suite_imu_kit.cpp +++ b/tests/functional/tests/imu_kit/suite_imu_kit.cpp @@ -5,7 +5,7 @@ #include "rtos/ThisThread.h" #include "CoreI2C.h" -#include "CoreLSM6DSOX.hpp" +#include "CoreIMU.hpp" #include "IMUKit.hpp" #include "tests/config.h" @@ -28,10 +28,10 @@ suite suite_imu_kit = [] { auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto lsm6dsox = CoreLSM6DSOX {i2c, drdy_irq}; - auto imukit = IMUKit {lsm6dsox}; + auto coreimu = CoreIMU {i2c, drdy_irq}; + auto imukit = IMUKit {coreimu}; - lsm6dsox.init(); + coreimu.init(); "Initialization"_test = [&] { expect(neq(&imukit, nullptr)); diff --git a/tests/unit/mocks/mocks/leka/LSM6DSOX.h b/tests/unit/mocks/mocks/leka/IMU.h similarity index 86% rename from tests/unit/mocks/mocks/leka/LSM6DSOX.h rename to tests/unit/mocks/mocks/leka/IMU.h index 5d0a21e80f..bd44872e3c 100644 --- a/tests/unit/mocks/mocks/leka/LSM6DSOX.h +++ b/tests/unit/mocks/mocks/leka/IMU.h @@ -5,11 +5,11 @@ #pragma once #include "gmock/gmock.h" -#include "interface/LSM6DSOX.hpp" +#include "interface/drivers/IMU.hpp" namespace leka::mock { -class LSM6DSOX : public interface::LSM6DSOX +class IMU : public interface::IMU { public: MOCK_METHOD(void, init, (), (override));