diff --git a/src/config/config.h b/src/config/config.h index 0e9833c..41fc026 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -9,10 +9,10 @@ /// Enable DEBUG_LOGIC to compile debugging and error messages (beware of code base size ;) ) for the logic layer //#define DEBUG_LOGIC -/// Enable DEBUG_LOGIC to compile debugging and error messages (beware of code base size ;) ) for the logic layer +/// Enable DEBUG_MODULES to compile debugging and error messages (beware of code base size ;) ) for the modules layer //#define DEBUG_MODULES -/// Enable DEBUG_HAL to compile debugging and error messages (beware of code base size ;) ) for the logic layer +/// Enable DEBUG_HAL to compile debugging and error messages (beware of code base size ;) ) for the HAL layer //#define DEBUG_HAL /// Wrangler for assorted compile-time configuration and constants. @@ -53,7 +53,8 @@ static constexpr uint16_t maxStepFrequency = 40000; static constexpr uint16_t minStepRate = 120; /// Size for the motion planner block buffer size -static constexpr uint8_t blockBufferSize = 2; +/// Beware of too low setting (esp. because of Motion::PlanLongMove) +static constexpr uint8_t blockBufferSize = 4; /// Step timer frequency divider (F = F_CPU / divider) static constexpr uint8_t stepTimerFrequencyDivider = 8; @@ -83,7 +84,7 @@ static constexpr U_mm couplerToBowden = 3.5_mm; /// 3.5_mm /// FINDA Coupler scr // just another piece of PLA (probably having more resistance in the tubes) // and we are at least 40mm off! It looks like this really depends on the exact position // We'll probably need to check for stallguard while pushing the filament to avoid ginding the filament -static constexpr U_mm defaultBowdenLength = 467.0_mm; /// ~427.0_mm /// Default Bowden length. @TODO Should be stored in EEPROM. +static constexpr U_mm defaultBowdenLength = 427.0_mm; /// ~427.0_mm /// Default Bowden length. @TODO Should be stored in EEPROM. 392 a 784 static constexpr U_mm minimumBowdenLength = 341.0_mm; /// ~341.0_mm /// Minimum bowden length. @TODO Should be stored in EEPROM. static constexpr U_mm maximumBowdenLength = 792.0_mm; /// ~792.0_mm /// Maximum bowden length. @TODO Should be stored in EEPROM. static constexpr U_mm feedToFinda = cuttingEdgeToFindaMidpoint + filamentMinLoadedToMMU; diff --git a/src/logic/feed_to_bondtech.cpp b/src/logic/feed_to_bondtech.cpp index d4453d8..39b6450 100644 --- a/src/logic/feed_to_bondtech.cpp +++ b/src/logic/feed_to_bondtech.cpp @@ -27,8 +27,7 @@ bool FeedToBondtech::Step() { dbg_logic_fP(PSTR("Pulley start steps %u"), mm::motion.CurPosition(mm::Pulley)); state = PushingFilamentToFSensor; mm::motion.InitAxis(mm::Pulley); - 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 + mm::motion.PlanLongMove(config::defaultBowdenLength, config::pulleyFeedrate, config::pulleySlowFeedrate); } return false; case PushingFilamentToFSensor: diff --git a/src/modules/motion.h b/src/modules/motion.h index ff78c7c..1d634e2 100644 --- a/src/modules/motion.h +++ b/src/modules/motion.h @@ -162,6 +162,27 @@ public: unitToAxisUnit>(end_rate)); } + /// This function exists solely because of some mysterious overflow bug in planning/stepping + /// which occurrs when number of steps exceeds 32K. The bug doesn't even exhibit in unit tests :( . + /// Therefore it plans multiple segments in case the desired distance is longer than 32K steps. + /// So far this is only used for moving the Pulley... + template + constexpr void PlanLongMove(config::Unit delta, + config::Unit feed_rate, config::Unit end_rate = { 0 }) { + auto steps = unitToAxisUnit>(delta); + while (steps.v > 32767) { + PlanMove( + { 32767 }, + unitToAxisUnit>(feed_rate), + unitToAxisUnit>(feed_rate)); // keep the end feedrate the same to continue with the next segment + steps.v -= 32767; + } + PlanMove( // last segment + steps, + unitToAxisUnit>(feed_rate), + unitToAxisUnit>(end_rate)); + } + /// @returns head position of an axis (last enqueued position) /// @param axis axis affected pos_t Position(Axis axis) const; diff --git a/tests/unit/logic/tool_change/test_tool_change.cpp b/tests/unit/logic/tool_change/test_tool_change.cpp index 15ab460..fd7d4f7 100644 --- a/tests/unit/logic/tool_change/test_tool_change.cpp +++ b/tests/unit/logic/tool_change/test_tool_change.cpp @@ -39,11 +39,11 @@ void FeedingToBondtech(logic::ToolChange &tc, uint8_t toSlot) { REQUIRE(WhileCondition( tc, [&](int step) -> bool { - if(step == 5000){ // on 5000th step make filament sensor trigger + if(step == 2000){ // on 5000th step make filament sensor trigger mfs::fsensor.ProcessMessage(true); } return tc.TopLevelState() == ProgressCode::FeedingToBondtech; }, - 200000UL)); + 20000UL)); REQUIRE(VerifyState(tc, mg::FilamentLoadState::InNozzle, mi::Idler::IdleSlotIndex(), toSlot, true, false, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK)); }