From 6f1624b71852e526563beb22a34b125596567a68 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Mon, 7 Jun 2021 12:23:51 +0200 Subject: [PATCH] Make logic prototype compilable --- CMakeLists.txt | 1 + src/logic/mm_control.cpp | 25 +++++++++++++------------ src/main.cpp | 3 +++ src/modules/leds.cpp | 2 ++ src/modules/motion.cpp | 8 ++++++-- src/modules/motion.h | 10 ++++++++-- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 050eb95..1cf92b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,7 @@ target_sources( src/modules/finda.cpp src/modules/leds.cpp src/modules/motion.cpp + src/logic/mm_control.cpp ) set_property( diff --git a/src/logic/mm_control.cpp b/src/logic/mm_control.cpp index 1256a32..1440a4c 100644 --- a/src/logic/mm_control.cpp +++ b/src/logic/mm_control.cpp @@ -49,9 +49,9 @@ struct UnloadToFinda { // FINDA is sensing the filament, plan moves to unload it int unloadSteps = /*BowdenLength::get() +*/ 1100; // @@TODO const int second_point = unloadSteps - 1300; - mm::motion.PlanMove(mm::Pulley, -1400, 6000); // @@TODO constants - mm::motion.PlanMove(mm::Pulley, -1800 + 1400, 2500); // @@TODO constants 1800-1400 = 400 - mm::motion.PlanMove(mm::Pulley, -second_point + 1800, 550); // @@TODO constants + // mm::motion.PlanMove(mm::Pulley, -1400, 6000); // @@TODO constants + // mm::motion.PlanMove(mm::Pulley, -1800 + 1400, 2500); // @@TODO constants 1800-1400 = 400 + // mm::motion.PlanMove(mm::Pulley, -second_point + 1800, 550); // @@TODO constants state = WaitingForFINDA; } } @@ -117,17 +117,17 @@ class UnloadFilament : public TaskBase { namespace mm = modules::motion; switch (state) { case EngagingIdler: // state 1 engage idler - if (mm::motion.IdlerEngaged()) { // if idler is in parked position un-park him get in contact with filament + if (mm::motion.IdlerEngaged()) { // if idler is in parked position un-park it get in contact with filament state = UnloadingToFinda; unl.Reset(); } return false; case UnloadingToFinda: // state 2 rotate pulley as long as the FINDA is on if (unl.Step()) { - if (unl.state == UnloadToFinda2::Failed) { + if (unl.state == UnloadToFinda::Failed) { // couldn't unload to FINDA, report error and wait for user to resolve it state = ERR1DisengagingIdler; - modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::blink0); + // modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::blink0); } else { state = DisengagingIdler; } @@ -138,7 +138,7 @@ class UnloadFilament : public TaskBase { case DisengagingIdler: if (mm::motion.IdlerDisengaged()) { state = AvoidingGrind; - mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants + // mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants } return false; case AvoidingGrind: // state 3 move a little bit so it is not a grinded hole in filament @@ -159,7 +159,7 @@ class UnloadFilament : public TaskBase { state = ERR1WaitingForUser; } return false; - case ERR1WaitingForUser: + case ERR1WaitingForUser: { // waiting for user buttons and/or a command from the printer bool help = modules::buttons::buttons.ButtonPressed(modules::buttons::Left) /*|| command_help()*/; bool tryAgain = modules::buttons::buttons.ButtonPressed(modules::buttons::Middle) /*|| command_tryAgain()*/; @@ -172,14 +172,15 @@ class UnloadFilament : public TaskBase { Reset(); } else if (userResolved) { // problem resolved - the user pulled the fillament by hand - modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::off); - modules::leds::leds.SetMode(active_extruder, modules::leds::green, modules::leds::on); - mm::motion.PlanMove(mm::Pulley, 450, 5000); // @@TODO constants + // modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::off); + // modules::leds::leds.SetMode(active_extruder, modules::leds::green, modules::leds::on); + // mm::motion.PlanMove(mm::Pulley, 450, 5000); // @@TODO constants state = AvoidingGrind; } return false; + } case OK: - isFilamentLoaded = false; // filament unloaded + // isFilamentLoaded = false; // filament unloaded return true; // successfully finished } } diff --git a/src/main.cpp b/src/main.cpp index 847bf6d..186a346 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,8 @@ void setup() { cpu::Init(); + // watchdog init + shr16::shr16.Init(); modules::leds::leds.SetMode(4, modules::leds::Color::green, modules::leds::Mode::blink0); modules::leds::leds.Step(0); @@ -249,6 +251,7 @@ void loop() { modules::leds::leds.Step(0); modules::finda::finda.Step(); currentCommand->Step(); + // add a watchdog reset } int main() { diff --git a/src/modules/leds.cpp b/src/modules/leds.cpp index 23fba84..ec28a47 100644 --- a/src/modules/leds.cpp +++ b/src/modules/leds.cpp @@ -4,6 +4,8 @@ namespace modules { namespace leds { +LEDs leds; + void LED::SetMode(Mode mode) { state.mode = mode; // set initial state of LEDs correctly - transition from one mode to another diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index 051c6a9..b179e73 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -6,14 +6,18 @@ namespace motion { Motion motion; -void Motion::PlanMove(Axis axis, float targetPosition, uint16_t feedrate) {} +void Motion::PlanMove(uint16_t pulley, uint16_t idler, uint16_t selector, uint16_t feedrate, uint16_t starting_speed, uint16_t ending_speed) {} -void Motion::Home(Axis axis) {} +void Motion::Home(Axis axis, bool direction) {} void Motion::SetMode(MotorMode mode) {} void Motion::Step() {} +bool Motion::IdlerDisengaged() const { return true; } + +bool Motion::IdlerEngaged() const { return true; } + void ISR() {} //@@TODO check the directions diff --git a/src/modules/motion.h b/src/modules/motion.h index 075e4e7..63198dd 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -58,6 +58,7 @@ public: static void StepPulley(uint8_t on); }; +/// @@TODO this is subject of discussion and change in the future class Motion { public: /// Init axis driver @@ -67,10 +68,12 @@ public: void DisableAxis(Axis axis) {} /// Enqueue move of a specific motor/axis into planner buffer - void PlanMove(Axis axis, float targetPosition, uint16_t feedrate); + /// @param pulley, idler, selector - target coords + void PlanMove(uint16_t pulley, uint16_t idler, uint16_t selector, uint16_t feedrate, uint16_t starting_speed, uint16_t ending_speed); /// Enqueue performing of homing of an axis - void Home(Axis axis); + /// @@TODO + void Home(Axis axis, bool direction); /// Set mode of TMC/motors operation /// Common for all axes/motors @@ -88,6 +91,9 @@ public: /// probably higher-level operations knowing the semantic meaning of axes void Idler(IdlerMode im) {} + bool IdlerDisengaged() const; + bool IdlerEngaged() const; + private: };