-
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.
- Loading branch information
Showing
3 changed files
with
184 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,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) |
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,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 | ||
|
||
IMUKit imu_kit(imu::internal::event_loop, imu::accel, imu::gyro); | ||
|
||
namespace motion::internal { | ||
|
||
EventLoopKit event_loop {}; | ||
|
||
} // namespace motion::internal | ||
|
||
MotionKit motion_kit(motors::left::motor, motors::right::motor, imu_kit, 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()): | ||
motion_kit.rotate(1, Rotation::counterClockwise); | ||
break; | ||
case (MagicCard::number_2.getId()): | ||
motion_kit.rotate(2, Rotation::clockwise); | ||
break; | ||
case (MagicCard::number_3.getId()): | ||
motion_kit.rotate(3, Rotation::counterClockwise); | ||
break; | ||
case (MagicCard::number_4.getId()): | ||
motion_kit.rotate(4, Rotation::clockwise); | ||
break; | ||
case (MagicCard::number_5.getId()): | ||
motion_kit.rotate(5, Rotation::counterClockwise); | ||
break; | ||
case (MagicCard::number_6.getId()): | ||
motion_kit.rotate(6, Rotation::clockwise); | ||
break; | ||
case (MagicCard::number_7.getId()): | ||
motion_kit.rotate(7, Rotation::counterClockwise); | ||
break; | ||
case (MagicCard::number_8.getId()): | ||
motion_kit.startStabilisation(); | ||
rtos::ThisThread::sleep_for(10s); | ||
motion_kit.stop(); | ||
break; | ||
case (MagicCard::number_9.getId()): | ||
motion_kit.startStabilisation(); | ||
break; | ||
case (MagicCard::number_10.getId()): | ||
motion_kit.stop(); | ||
break; | ||
} | ||
} | ||
|
||
auto main() -> int | ||
{ | ||
logger::init(); | ||
|
||
HelloWorld hello; | ||
hello.start(); | ||
|
||
imu::lsm6dsox.init(); | ||
imu_kit.init(); | ||
motion_kit.init(); | ||
rfidkit.init(); | ||
|
||
auto callback = [](const MagicCard &card) { onMagicCardAvailable(card); }; | ||
|
||
rfidkit.onTagActivated(callback); | ||
|
||
while (true) { | ||
rtos::ThisThread::sleep_for(100ms); | ||
} | ||
} |