From 3ef113cf6cf82581504c502c31160bff9331467e Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 28 May 2021 09:50:09 +0200 Subject: [PATCH] Add basic motion API --- CMakeLists.txt | 1 + src/modules/motion.cpp | 19 +++++++++++++++++++ src/modules/motion.h | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/modules/motion.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8faa2ee..5e96867 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,7 @@ target_sources( src/modules/protocol.cpp src/modules/buttons.cpp src/modules/leds.cpp + src/modules/motion.cpp ) set_property( diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp new file mode 100644 index 0000000..a92e906 --- /dev/null +++ b/src/modules/motion.cpp @@ -0,0 +1,19 @@ +#include "motion.h" + +namespace modules { +namespace motion { + +Motion motion; + +void Motion::PlanMove(Axis axis, float targetPosition, uint16_t feedrate) {} + +void Motion::Home(Axis axis) {} + +void Motion::SetMode(Mode mode) {} + +void Motion::Step() {} + +void ISR() {} + +} // namespace motion +} // namespace modules diff --git a/src/modules/motion.h b/src/modules/motion.h index 6e468f2..c56050b 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -1,4 +1,5 @@ #pragma once +#include /// @@TODO /// Logic of motor handling @@ -19,3 +20,43 @@ /// rotate(speed) /// rotate(speed, angle/steps) /// home? + +namespace modules { +namespace motion { + +enum Axis { + Idler, + Selector, + Pulley +}; + +enum Mode { + Stealth, + Normal +}; + +class Motion { +public: + /// Enqueue move of a specific motor/axis into planner buffer + void PlanMove(Axis axis, float targetPosition, uint16_t feedrate); + + /// Enqueue performing of homing of an axis + void Home(Axis axis); + + /// Set mode of TMC/motors operation + /// Common for all axes/motors + void SetMode(Mode mode); + + /// State machine doing all the planning and stepping preparation based on received commands + void Step(); + +private: +}; + +/// ISR stepping routine +extern void ISR(); + +extern Motion motion; + +} // namespace motion +} // namespace modules