diff --git a/src/config/config.h b/src/config/config.h index 6876a57..bf66154 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -5,6 +5,7 @@ /// Define Debug mode to add additional serial output //#define DEBUG_FINDA +//#define DEBUG_LOGIC /// Wrangler for assorted compile-time configuration and constants. namespace config { diff --git a/src/logic/feed_to_bondtech.cpp b/src/logic/feed_to_bondtech.cpp index 1ea22ab..40e29a6 100644 --- a/src/logic/feed_to_bondtech.cpp +++ b/src/logic/feed_to_bondtech.cpp @@ -6,10 +6,18 @@ #include "../modules/leds.h" #include "../modules/motion.h" #include "../modules/permanent_storage.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace logic { void FeedToBondtech::Reset(uint8_t maxRetries) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("\nFeed to Bondtech\n\n"); + #endif //DEBUG_LOGIC state = EngagingIdler; this->maxRetries = maxRetries; ml::leds.SetMode(mg::globals.ActiveSlot(), ml::Color::green, ml::Mode::blink0); @@ -22,12 +30,21 @@ bool FeedToBondtech::Step() { switch (state) { case EngagingIdler: if (mi::idler.Engaged()) { + #ifdef DEBUG_LOGIC + uint16_t startSteps = mm::motion.CurPosition(mm::Pulley); + char str[30]; + sprintf_P(str, PSTR("\nPulley start steps %u\n\n"), startSteps); + hu::usart1.puts(str); + #endif //DEBUG_LOGIC state = PushingFilament; mm::motion.PlanMove(config::DefaultBowdenLength, config::pulleyFeedrate); //@@TODO constants - there was some strange acceleration sequence in the original FW, // we can probably hand over some array of constants for hand-tuned acceleration + leverage some smoothing in the stepper as well } return false; case PushingFilament: + #ifdef DEBUG_LOGIC + hu::usart1.puts("\nFeed to Bondtech --> Pushing\n\n"); + #endif //DEBUG_LOGIC if (mfs::fsensor.Pressed()) { mm::motion.AbortPlannedMoves(); // stop pushing filament mi::idler.Disengage(); @@ -40,13 +57,22 @@ bool FeedToBondtech::Step() { } return false; case DisengagingIdler: + #ifdef DEBUG_LOGIC + hu::usart1.puts("\nFeed to Bondtech --> DisengagingIdler\n\n"); + #endif //DEBUG_LOGIC if (!mi::idler.Engaged()) { state = OK; ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); } return false; case OK: + #ifdef DEBUG_LOGIC + hu::usart1.puts("\nFeed to Bondtech\n\n"); + #endif //DEBUG_LOGIC case Failed: + #ifdef DEBUG_LOGIC + hu::usart1.puts("\nFeed to Bondtech FAILED\n\n"); + #endif //DEBUG_LOGIC default: return true; } diff --git a/src/logic/load_filament.cpp b/src/logic/load_filament.cpp index fb2bbf2..052117c 100644 --- a/src/logic/load_filament.cpp +++ b/src/logic/load_filament.cpp @@ -7,6 +7,11 @@ #include "../modules/permanent_storage.h" #include "../modules/selector.h" #include "../modules/user_input.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace logic { @@ -16,7 +21,9 @@ void LoadFilament::Reset(uint8_t param) { if (!CheckToolIndex(param)) { return; } - + #ifdef DEBUG_LOGIC + hu::usart1.puts("Load Filament\n\n"); + #endif //DEBUG_LOGIC state = ProgressCode::EngagingIdler; error = ErrorCode::RUNNING; mg::globals.SetActiveSlot(param); diff --git a/src/logic/progress_codes.h b/src/logic/progress_codes.h index 1904549..f9f9170 100644 --- a/src/logic/progress_codes.h +++ b/src/logic/progress_codes.h @@ -8,29 +8,29 @@ enum class ProgressCode : uint_fast8_t { OK = 0, ///< finished ok - EngagingIdler, - DisengagingIdler, - UnloadingToFinda, - UnloadingToPulley, - FeedingToFinda, - FeedingToBondtech, - AvoidingGrind, - FinishingMoves, + EngagingIdler, // P1 + DisengagingIdler, // P2 + UnloadingToFinda, // P3 + UnloadingToPulley, //P4 + FeedingToFinda, // P5 + FeedingToBondtech, // P6 + AvoidingGrind, // P7 + FinishingMoves, // P8 - ERRDisengagingIdler, - ERREngagingIdler, - ERRWaitingForUser, - ERRInternal, - ERRHelpingFilament, - ERRTMCFailed, + ERRDisengagingIdler, // P9 + ERREngagingIdler, // P10 + ERRWaitingForUser, // P11 + ERRInternal, // P12 + ERRHelpingFilament, // P13 + ERRTMCFailed, // P14 - UnloadingFilament, - LoadingFilament, - SelectingFilamentSlot, - PreparingBlade, - PushingFilament, - PerformingCut, - ReturningSelector, - ParkingSelector, - EjectingFilament, + UnloadingFilament, // P15 + LoadingFilament, // P16 + SelectingFilamentSlot, // P17 + PreparingBlade, // P18 + PushingFilament, // P19 + PerformingCut, // P20 + ReturningSelector, // P21 + ParkingSelector, // P22 + EjectingFilament, // P23 }; diff --git a/src/logic/tool_change.cpp b/src/logic/tool_change.cpp index 4524066..ba48b31 100644 --- a/src/logic/tool_change.cpp +++ b/src/logic/tool_change.cpp @@ -7,6 +7,11 @@ #include "../modules/motion.h" #include "../modules/permanent_storage.h" #include "../modules/selector.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace logic { @@ -19,6 +24,9 @@ void ToolChange::Reset(uint8_t param) { if (param == mg::globals.ActiveSlot() && mg::globals.FilamentLoaded()) { // we are already at the correct slot and the filament is loaded - nothing to do + #ifdef DEBUG_LOGIC + hu::usart1.puts("we are already at the correct slot and the filament is loaded - nothing to do\n"); + #endif //DEBUG_LOGIC return; } @@ -27,10 +35,16 @@ void ToolChange::Reset(uint8_t param) { plannedSlot = param; if (mg::globals.FilamentLoaded()) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Filament is loaded --> unload\n"); + #endif //DEBUG_LOGIC state = ProgressCode::UnloadingFilament; unl.Reset(mg::globals.ActiveSlot()); } else { state = ProgressCode::LoadingFilament; + #ifdef DEBUG_LOGIC + hu::usart1.puts("Filament is not loaded --> load\n"); + #endif //DEBUG_LOGIC load.Reset(plannedSlot); } } diff --git a/src/logic/unload_filament.cpp b/src/logic/unload_filament.cpp index 010f15d..705e910 100644 --- a/src/logic/unload_filament.cpp +++ b/src/logic/unload_filament.cpp @@ -6,6 +6,11 @@ #include "../modules/motion.h" #include "../modules/permanent_storage.h" #include "../modules/user_input.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace logic { diff --git a/src/modules/idler.cpp b/src/modules/idler.cpp index 6691aa2..5775477 100644 --- a/src/modules/idler.cpp +++ b/src/modules/idler.cpp @@ -3,6 +3,11 @@ #include "leds.h" #include "motion.h" #include "permanent_storage.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace modules { namespace idler { @@ -11,34 +16,56 @@ Idler idler; void Idler::PrepareMoveToPlannedSlot() { mm::motion.PlanMoveTo(SlotPosition(plannedSlot), mm::unitToAxisUnit(config::idlerFeedrate)); + #ifdef DEBUG_LOGIC + char str[30]; + sprintf_P(str, PSTR("Prepare Move Idler slot %d\n"), plannedSlot); + hu::usart1.puts(str); + #endif //DEBUG_LOGIC } void Idler::PlanHomingMove() { mm::motion.PlanMove(mm::unitToAxisUnit(-config::idlerLimits.lenght * 2), mm::unitToAxisUnit(config::idlerFeedrate)); + #ifdef DEBUG_LOGIC + hu::usart1.puts("Plan Homing Idler\n"); + #endif //DEBUG_LOGIC } Idler::OperationResult Idler::Disengage() { - if (state == Moving) + if (state == Moving) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Moving --> Disengage refused\n"); + #endif //DEBUG_LOGIC return OperationResult::Refused; - + } plannedSlot = IdleSlotIndex(); plannedEngage = false; - if (!Engaged()) + if (!Engaged()) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Disengage Idler\n"); + #endif //DEBUG_LOGIC return OperationResult::Accepted; - + } return InitMovement(mm::Idler); } Idler::OperationResult Idler::Engage(uint8_t slot) { - if (state == Moving) + if (state == Moving){ + #ifdef DEBUG_LOGIC + hu::usart1.puts("Moving --> Engage refused\n"); + #endif //DEBUG_LOGIC return OperationResult::Refused; + } plannedSlot = slot; plannedEngage = true; - if (Engaged()) + if (Engaged()) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Engage Idler\n"); + #endif //DEBUG_LOGIC return OperationResult::Accepted; + } return InitMovement(mm::Idler); } @@ -54,12 +81,21 @@ bool Idler::Home() { bool Idler::Step() { switch (state) { case Moving: + #ifdef DEBUG_LOGIC + //hu::usart1.puts("Moving Idler\n"); + #endif //DEBUG_LOGIC PerformMove(mm::Idler); return false; case Homing: + #ifdef DEBUG_LOGIC + hu::usart1.puts("Homing Idler\n"); + #endif //DEBUG_LOGIC PerformHome(mm::Idler); return false; case Ready: + #ifdef DEBUG_LOGIC + //hu::usart1.puts("Idler Ready\n"); + #endif //DEBUG_LOGIC currentlyEngaged = plannedEngage; currentSlot = plannedSlot; @@ -68,6 +104,9 @@ bool Idler::Step() { return true; case Failed: + #ifdef DEBUG_LOGIC + hu::usart1.puts("Idler Failed\n"); + #endif //DEBUG_LOGIC default: return true; } diff --git a/src/modules/motion.cpp b/src/modules/motion.cpp index 0a4ab40..77e48a5 100644 --- a/src/modules/motion.cpp +++ b/src/modules/motion.cpp @@ -1,5 +1,10 @@ #include "motion.h" #include "../panic.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC // TODO: use proper timer abstraction #ifdef __AVR__ @@ -45,6 +50,12 @@ void Motion::StallGuardReset(Axis axis) { } void Motion::PlanMoveTo(Axis axis, pos_t pos, steps_t feed_rate, steps_t end_rate) { + #ifdef DEBUG_LOGIC + char str[30]; + sprintf_P(str, PSTR("Move axis %d to %u\n"), axis, pos); + hu::usart1.puts(str); + #endif //DEBUG_LOGIC + if (axisData[axis].ctrl.PlanMoveTo(pos, feed_rate, end_rate)) { // move was queued, prepare the axis if (!axisData[axis].enabled) diff --git a/src/modules/selector.cpp b/src/modules/selector.cpp index 794739a..da859ed 100644 --- a/src/modules/selector.cpp +++ b/src/modules/selector.cpp @@ -3,6 +3,11 @@ #include "leds.h" #include "motion.h" #include "permanent_storage.h" +#ifdef DEBUG_LOGIC + #include "../hal/usart.h" + #include + #include +#endif //DEBUG_LOGIC namespace modules { namespace selector { @@ -11,21 +16,35 @@ Selector selector; void Selector::PrepareMoveToPlannedSlot() { mm::motion.PlanMoveTo(SlotPosition(plannedSlot), mm::unitToAxisUnit(config::selectorFeedrate)); + #ifdef DEBUG_LOGIC + char str[30]; + sprintf_P(str, PSTR("Prepare Move Selector slot %d\n"), plannedSlot); + hu::usart1.puts(str); + #endif //DEBUG_LOGIC } void Selector::PlanHomingMove() { mm::motion.PlanMove(mm::unitToAxisUnit(config::selectorLimits.lenght * 2), mm::unitToAxisUnit(config::selectorFeedrate)); + #ifdef DEBUG_LOGIC + hu::usart1.puts("Plan Homing Selector\n"); + #endif //DEBUG_LOGIC } Selector::OperationResult Selector::MoveToSlot(uint8_t slot) { - if (state == Moving) + if (state == Moving) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Moving --> Selector refused\n"); + #endif //DEBUG_LOGIC return OperationResult::Refused; - + } plannedSlot = slot; - if (currentSlot == slot) + if (currentSlot == slot) { + #ifdef DEBUG_LOGIC + hu::usart1.puts("Moving Selector\n"); + #endif //DEBUG_LOGIC return OperationResult::Accepted; - + } return InitMovement(mm::Selector); } @@ -40,15 +59,27 @@ bool Selector::Step() { switch (state) { case Moving: PerformMove(mm::Selector); + #ifdef DEBUG_LOGIC + //hu::usart1.puts("Moving Selector\n"); + #endif //DEBUG_LOGIC return false; case Homing: + #ifdef DEBUG_LOGIC + hu::usart1.puts("Homing Selector\n"); + #endif //DEBUG_LOGIC PerformHome(mm::Selector); return false; case Ready: + #ifdef DEBUG_LOGIC + //hu::usart1.puts("Selector Ready\n"); + #endif //DEBUG_LOGIC currentSlot = plannedSlot; mm::motion.Disable(mm::Selector); // turn off selector motor's power every time return true; case Failed: + #ifdef DEBUG_LOGIC + hu::usart1.puts("Selector Failed\n"); + #endif //DEBUG_LOGIC default: return true; }