Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yann/feature/imu/add spike for calibration #1408

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions drivers/CoreIMU/source/CoreIMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ void CoreIMU::registerOnWakeUpCallback(std::function<void()> const &callback)

void CoreIMU::enableOnWakeUpInterrupt()
{
// ODR = 52Hz for reference

// ? Set filter and disable user offset
lsm6dsox_xl_hp_path_internal_set(&_register_io_function, LSM6DSOX_USE_SLOPE);
lsm6dsox_xl_usr_offset_on_wkup_set(&_register_io_function, 0);

// ? Set Wakeup config
lsm6dsox_wkup_threshold_set(&_register_io_function, 2);
lsm6dsox_wkup_ths_weight_set(&_register_io_function, LSM6DSOX_LSb_FS_DIV_64);
lsm6dsox_wkup_dur_set(&_register_io_function, 0x02);
lsm6dsox_wkup_threshold_set(&_register_io_function, 3); // LSB multiplier / Max: 31
lsm6dsox_wkup_ths_weight_set(&_register_io_function,
LSM6DSOX_LSb_FS_DIV_64); // 2 Weights, 1 LSB = FS_XL/2^x x:{6,8}
lsm6dsox_wkup_dur_set(&_register_io_function, 1); // 1 LSB = 1*ODR_time / Max: 3

// ? Set Activity config
lsm6dsox_act_sleep_dur_set(&_register_io_function, 0x02);
lsm6dsox_act_mode_set(&_register_io_function, LSM6DSOX_XL_AND_GY_NOT_AFFECTED);
lsm6dsox_act_sleep_dur_set(&_register_io_function, 0); // 1 LSB = 512*ODR / Max: 15
lsm6dsox_act_mode_set(&_register_io_function, LSM6DSOX_XL_12Hz5_GY_PD); // 4 Modes

lsm6dsox_pin_int1_route_t lsm6dsox_int1 {
.sleep_change = PROPERTY_ENABLE,
Expand Down
2 changes: 2 additions & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(${SPIKES_DIR}/lk_rfid)
add_subdirectory(${SPIKES_DIR}/lk_sensors_battery)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_fusion_calibration)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_wakeup_calibration)
add_subdirectory(${SPIKES_DIR}/lk_sensors_light)
add_subdirectory(${SPIKES_DIR}/lk_sensors_microphone)
add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity)
Expand Down Expand Up @@ -73,6 +74,7 @@ add_dependencies(spikes_leka
spike_lk_sensors_battery
spike_lk_sensors_imu
spike_lk_sensors_imu_fusion_calibration
spike_lk_sensors_imu_wakeup_calibration
spike_lk_sensors_light
spike_lk_sensors_microphone
spike_lk_sensors_temperature_humidity
Expand Down
23 changes: 23 additions & 0 deletions spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Leka - LekaOS
# Copyright 2024 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_sensors_imu_wakeup_calibration)

target_include_directories(spike_lk_sensors_imu_wakeup_calibration
PRIVATE
.
)

target_sources(spike_lk_sensors_imu_wakeup_calibration
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_sensors_imu_wakeup_calibration
CoreIMU
CoreI2C
CoreLED
)

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

#include <cinttypes>

#include "rtos/ThisThread.h"

#include "CoreI2C.h"
#include "CoreIMU.hpp"
#include "CoreLED.h"
#include "CoreSPI.h"
#include "HelloWorld.h"
#include "LogKit.h"

using namespace std::chrono;
using namespace leka;

namespace {

namespace imu {

namespace internal {

auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ};
auto i2c = CoreI2C {PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL};

} // namespace internal

CoreIMU coreimu(internal::i2c, internal::irq);

} // namespace imu

namespace leds {

namespace internal {

namespace ears {

auto spi = CoreSPI {LED_EARS_SPI_MOSI, NC, LED_EARS_SPI_SCK};
constexpr auto size = 2;

} // namespace ears

namespace belt {

auto spi = CoreSPI {LED_BELT_SPI_MOSI, NC, LED_BELT_SPI_SCK};
constexpr auto size = 20;

} // namespace belt

} // namespace internal

auto ears = CoreLED<internal::ears::size> {internal::ears::spi};
auto belt = CoreLED<internal::belt::size> {internal::belt::spi};

} // namespace leds

} // namespace

void setColor(RGB color)
{
leds::ears.setColor(color);
leds::belt.setColor(color);

leds::ears.show();
leds::belt.show();
}

void turnOff()
{
setColor(RGB::black);
}

void wakeUpReaction()
{
setColor(RGB::pure_blue);
rtos::ThisThread::sleep_for(2s);
turnOff();
}

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

log_info("Hello, World!\n\n");

HelloWorld hello;
hello.start();

imu::coreimu.init();
imu::coreimu.setPowerMode(CoreIMU::PowerMode::Normal);

auto callback = [] { wakeUpReaction(); };

imu::coreimu.enableOnWakeUpInterrupt(callback);

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
Loading