Skip to content

Commit

Permalink
✨ (spike): Add lk_motion_kit
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Dec 8, 2022
1 parent 572ef48 commit 7f8a751
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_subdirectory(${SPIKES_DIR}/lk_imu_kit)
add_subdirectory(${SPIKES_DIR}/lk_lcd)
add_subdirectory(${SPIKES_DIR}/lk_led_kit)
add_subdirectory(${SPIKES_DIR}/lk_log_kit)
add_subdirectory(${SPIKES_DIR}/lk_motion_kit)
add_subdirectory(${SPIKES_DIR}/lk_motors)
add_subdirectory(${SPIKES_DIR}/lk_qdac)
add_subdirectory(${SPIKES_DIR}/lk_reinforcer)
Expand Down Expand Up @@ -62,6 +63,7 @@ add_dependencies(spikes_leka
spike_lk_lcd
spike_lk_led_kit
spike_lk_log_kit
spike_lk_motion_kit
spike_lk_motors
spike_lk_qdac
spike_lk_reinforcer
Expand Down
30 changes: 30 additions & 0 deletions spikes/lk_motion_kit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Leka - LekaOS
# Copyright 2022 APF France handicap
# SPDX-License-Identifier: Apache-2.0

add_mbed_executable(spike_lk_motion_kit)

target_include_directories(spike_lk_motion_kit
PRIVATE
.
)

target_sources(spike_lk_motion_kit
PRIVATE
main.cpp
)

target_link_libraries(spike_lk_motion_kit
CoreI2C
CoreIMU
CoreMotor
CorePwm
EventLoopKit
IMUKit
MotionKit
CoreBufferedSerial
CoreRFIDReader
RFIDKit
)

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

#include "rtos/ThisThread.h"

#include "CoreAccelerometer.h"
#include "CoreBufferedSerial.h"
#include "CoreGyroscope.h"
#include "CoreI2C.h"
#include "CoreLSM6DSOX.h"
#include "CoreMotor.h"
#include "CorePwm.h"
#include "CoreRFIDReaderCR95HF.h"
#include "EventLoopKit.h"
#include "HelloWorld.h"
#include "IMUKit.h"
#include "LogKit.h"
#include "MotionKit.h"
#include "RFIDKit.h"

using namespace std::chrono;
using namespace leka;

namespace {

namespace motors {

namespace left {

namespace internal {

auto dir_1 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_1};
auto dir_2 = mbed::DigitalOut {MOTOR_LEFT_DIRECTION_2};
auto speed = CorePwm {MOTOR_LEFT_PWM};

} // namespace internal

auto motor = CoreMotor {internal::dir_1, internal::dir_2, internal::speed};

} // namespace left

namespace right {

namespace internal {

auto dir_1 = mbed::DigitalOut {MOTOR_RIGHT_DIRECTION_1};
auto dir_2 = mbed::DigitalOut {MOTOR_RIGHT_DIRECTION_2};
auto speed = CorePwm {MOTOR_RIGHT_PWM};

} // namespace internal

auto motor = CoreMotor {internal::dir_1, internal::dir_2, internal::speed};

} // namespace right

} // namespace motors

namespace imu {

namespace internal {

CoreI2C i2c(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL);
EventLoopKit event_loop {};

} // namespace internal

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

} // namespace imu

auto imukit = IMUKit {imu::internal::event_loop, imu::accel, imu::gyro};

namespace motion::internal {

EventLoopKit event_loop {};

} // namespace motion::internal

auto motionkit = MotionKit {motors::left::motor, motors::right::motor, imukit, motion::internal::event_loop};

namespace rfid {

auto serial = CoreBufferedSerial(RFID_UART_TX, RFID_UART_RX, 57600);
auto reader = CoreRFIDReaderCR95HF(serial);

} // namespace rfid

auto rfidkit = RFIDKit(rfid::reader);

} // namespace

void onMagicCardAvailable(const MagicCard &card)
{
switch (card.getId()) {
case (MagicCard::number_1.getId()):
motionkit.rotate(1, Rotation::counterClockwise);
break;
case (MagicCard::number_2.getId()):
motionkit.rotate(2, Rotation::clockwise);
break;
case (MagicCard::number_3.getId()):
motionkit.rotate(3, Rotation::counterClockwise);
break;
case (MagicCard::number_4.getId()):
motionkit.rotate(4, Rotation::clockwise);
break;
case (MagicCard::number_5.getId()):
motionkit.rotate(5, Rotation::counterClockwise);
break;
case (MagicCard::number_6.getId()):
motionkit.rotate(6, Rotation::clockwise);
break;
case (MagicCard::number_7.getId()):
motionkit.rotate(7, Rotation::counterClockwise);
break;
case (MagicCard::number_8.getId()):
motionkit.startStabilisation();
rtos::ThisThread::sleep_for(10s);
motionkit.stop();
break;
case (MagicCard::number_9.getId()):
motionkit.startStabilisation();
break;
case (MagicCard::number_10.getId()):
motionkit.stop();
break;
}
}

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

HelloWorld hello;
hello.start();

imu::lsm6dsox.init();
imukit.init();
motionkit.init();
rfidkit.init();

auto callback = [](const MagicCard &card) { onMagicCardAvailable(card); };

rfidkit.onTagActivated(callback);

while (true) {
rtos::ThisThread::sleep_for(100ms);
}
}

0 comments on commit 7f8a751

Please sign in to comment.