-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ (functional): Add imu functional tests
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Leka - LekaOS | ||
# Copyright 2022 APF France handicap | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
register_functional_test( | ||
TARGET | ||
functional_ut_imu | ||
|
||
INCLUDE_DIRECTORIES | ||
|
||
SOURCES | ||
suite_lsm6dsox.cpp | ||
|
||
LINK_LIBRARIES | ||
CoreI2C | ||
CoreIMU | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Leka - LekaOS | ||
// Copyright 2022 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "CoreI2C.h" | ||
#include "CoreLSM6DSOX.h" | ||
#include "ThisThread.h" | ||
#include "tests/config.h" | ||
|
||
using namespace leka; | ||
using namespace std::chrono; | ||
using namespace boost::ut; | ||
|
||
suite suite_lsm6dsox = [] { | ||
auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); | ||
auto lsm6dsox = CoreLSM6DSOX {i2c}; | ||
lsm6dsox.init(); | ||
auto default_min_bound_az = 800.f; | ||
auto default_max_bound_az = 1200.f; | ||
|
||
"Initialization"_test = [&] { expect(neq(&lsm6dsox, nullptr)); }; | ||
|
||
"Get imu data "_test = [&] { | ||
auto data = lsm6dsox.getData(); | ||
expect(data.xl.x != 0.f) << "Null acceleration on X axis "; | ||
expect(data.xl.y != 0.f) << "Null acceleration on Y axis "; | ||
expect(data.xl.z >= default_min_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too low"; | ||
expect(data.xl.z <= default_max_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too high"; | ||
expect(data.gy.x != 0.f) << "Null angular speed on X axis "; | ||
expect(data.gy.y != 0.f) << "Null angular speed on Y axis "; | ||
expect(data.gy.x != 0.f) << "Null angular speed on Z axis "; | ||
}; | ||
|
||
"Turn off lsm6dsox"_test = [&] { | ||
lsm6dsox.turnOff(); | ||
auto data = lsm6dsox.getData(); | ||
rtos::ThisThread::sleep_for(40ms); | ||
auto current_data = lsm6dsox.getData(); | ||
expect(data.xl.x == current_data.xl.x) << "Lsm6dsox not turned off " << data.xl.x << "!=" << current_data.xl.x; | ||
expect(data.xl.y == current_data.xl.y) << "Lsm6dsox not turned off " << data.xl.y << "!=" << current_data.xl.y; | ||
expect(data.xl.z == current_data.xl.z) << "Lsm6dsox not turned off " << data.xl.z << "!=" << current_data.xl.z; | ||
expect(data.gy.x == current_data.gy.x) << "Lsm6dsox not turned off " << data.gy.x << "!=" << current_data.gy.x; | ||
expect(data.gy.y == current_data.gy.y) << "Lsm6dsox not turned off " << data.gy.y << "!=" << current_data.gy.y; | ||
expect(data.gy.z == current_data.gy.z) << "Lsm6dsox not turned off " << data.gy.z << "!=" << current_data.gy.z; | ||
}; | ||
|
||
"Assert data are different when lsm6dsox turned on "_test = [&] { | ||
lsm6dsox.turnOn(); | ||
auto data = lsm6dsox.getData(); | ||
rtos::ThisThread::sleep_for(40ms); | ||
auto current_data = lsm6dsox.getData(); | ||
expect(data.gy.z != current_data.gy.z) << "Datas are all the same " << data.gy.z << "!=" << current_data.gy.z; | ||
}; | ||
|
||
"Turn on lsm6dsox after turned off "_test = [&] { | ||
lsm6dsox.turnOff(); | ||
lsm6dsox.turnOn(); | ||
auto data = lsm6dsox.getData(); | ||
expect(data.xl.x != 0.f) << "Null acceleration on X axis "; | ||
expect(data.xl.y != 0.f) << "Null acceleration on Y axis "; | ||
expect(data.xl.z >= default_min_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too low"; | ||
expect(data.xl.z <= default_max_bound_az) << "Acceleration on Z axis:" << data.xl.z << "axis too high"; | ||
expect(data.gy.x != 0.f) << "Null angular speed on X axis "; | ||
expect(data.gy.y != 0.f) << "Null angular speed on Y axis "; | ||
expect(data.gy.x != 0.f) << "Null angular speed on Z axis "; | ||
}; | ||
}; |