Skip to content

Commit

Permalink
✨ (spikes): Add spike imu_kit_calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Feb 1, 2023
1 parent 2f2d945 commit 9df5409
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_subdirectory(${SPIKES_DIR}/lk_file_manager_kit)
add_subdirectory(${SPIKES_DIR}/lk_flash_memory)
add_subdirectory(${SPIKES_DIR}/lk_fs)
add_subdirectory(${SPIKES_DIR}/lk_imu_kit)
add_subdirectory(${SPIKES_DIR}/lk_imu_kit_calibration)
add_subdirectory(${SPIKES_DIR}/lk_imu_kit_fusion)
add_subdirectory(${SPIKES_DIR}/lk_imu_kit_fusion_calibration)
add_subdirectory(${SPIKES_DIR}/lk_lcd)
Expand Down
23 changes: 23 additions & 0 deletions spikes/lk_imu_kit_calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_imu_kit_calibration)

target_include_directories(spike_lk_imu_kit_calibration
PRIVATE
.
)

target_sources(spike_lk_imu_kit_calibration
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_imu_kit_calibration
CoreIMU
CoreI2C
Fusion
)

target_link_custom_leka_targets(spike_lk_imu_kit_calibration)
65 changes: 65 additions & 0 deletions spikes/lk_imu_kit_calibration/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "rtos/ThisThread.h"

#include "CoreAccelerometer.h"
#include "CoreGyroscope.h"
#include "CoreI2C.h"
#include "CoreLSM6DSOX.h"
#include "LogKit.h"

using namespace std::chrono;
using namespace leka;

namespace {

namespace imu {

namespace internal {

CoreI2C i2c(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL);
CoreLSM6DSOX lsm6dsox(internal::i2c);

} // namespace internal

CoreAccelerometer accel(internal::lsm6dsox);
CoreGyroscope gyro(internal::lsm6dsox);

} // namespace imu

} // namespace

const auto SLEEP_DELAY = 50ms;
auto counter = 0;

auto main() -> int
{
logger::init();

rtos::ThisThread::sleep_for(1s);

imu::internal::lsm6dsox.init();

rtos::ThisThread::sleep_for(1s);
log_free("#, ts, dt, ax, ay, az, gx, gy, gz\n");
rtos::ThisThread::sleep_for(500ms);

while (true) {
const auto start = rtos::Kernel::Clock::now();

auto [gx, gy, gz] = imu::gyro.getXYZ();
auto [ax, ay, az] = imu::accel.getXYZ();

const auto stop = rtos::Kernel::Clock::now();

const auto delta = static_cast<int>((stop - start).count());
const auto now = static_cast<int>(start.time_since_epoch().count());

log_free("%i, %i, %i, %f, %f, %f, %f, %f, %f\n", counter, now, delta, ax, ay, az, gx, gy, gz);

++counter;
rtos::ThisThread::sleep_for(SLEEP_DELAY);
}
}

0 comments on commit 9df5409

Please sign in to comment.