From aa5995368d500023f0a699177608d356c5e83bcf Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 27 Jul 2021 09:42:52 +0200 Subject: [PATCH] Update to latest main + fix unit tests ... in relation to the newly introduced stepping in physical units rather than in steps --- src/config/config.h | 44 ++++++------------- .../logic/cut_filament/test_cut_filament.cpp | 7 +-- .../load_filament/test_load_filament.cpp | 8 ++-- tests/unit/logic/stubs/main_loop_stub.h | 6 +++ tests/unit/logic/stubs/stub_motion.cpp | 12 ++--- .../logic/tool_change/test_tool_change.cpp | 4 +- .../unload_filament/test_unload_filament.cpp | 8 ++-- 7 files changed, 40 insertions(+), 49 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index 39af18f..1bc46ff 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -7,42 +7,26 @@ namespace config { static constexpr const uint8_t toolCount = 5U; ///< Max number of extruders/tools/slots -// Idler's setup -/* -static constexpr U_deg idlerSlotPositions[toolCount + 1] = { - 1.0_deg, 2.0_deg, 3.0_deg, 4.0_deg, 5.0_deg, 0 -}; ///< slots 0-4 are the real ones, the 5th is the idle position - -// Selector's setup -static constexpr U_mm selectorSlotPositions[toolCount + 1] = { - 1.0_mm, 2.0_mm, 3.0_mm, 4.0_mm, 5.0_mm, 6.0_mm -}; ///< slots 0-4 are the real ones, the 5th is the farthest parking positions -*/ -/// Idler steps between neighbor positions: 2 msteps = 180 / 4 -static constexpr uint16_t idlerSteps = 1420 / 4; - /// Absolute positions for Idler's slots: 0-4 are the real ones, the 5th index is the idle position -static constexpr uint16_t idlerSlotPositions[toolCount + 1] = { - idlerSteps, - idlerSteps * 2, - idlerSteps * 3, - idlerSteps * 4, - idlerSteps * 5, - 0 +static constexpr U_deg idlerSlotPositions[toolCount + 1] = { + 45.0_deg, + 90.0_deg, + 135.0_deg, + 180.0_deg, + 225.0_deg, + 0.0_deg }; // Selector's setup -/// Selector steps between neighbor positions -static constexpr uint16_t selectorSteps = 2790 / 4; /// slots 0-4 are the real ones, the 5th is the farthest parking positions -static constexpr uint16_t selectorSlotPositions[toolCount + 1] = { - selectorSteps, - selectorSteps * 2, - selectorSteps * 3, - selectorSteps * 4, - selectorSteps * 5, - selectorSteps * 6 +static constexpr U_mm selectorSlotPositions[toolCount + 1] = { + 20.0_mm, + 20.0_mm + 14.0_mm, + 20.0_mm + 2.0_mm * 14.0_mm, + 20.0_mm + 3.0_mm * 14.0_mm, + 20.0_mm + 4.0_mm * 14.0_mm, + 20.0_mm + 5.0_mm * 14.0_mm }; // Printer's filament sensor setup diff --git a/tests/unit/logic/cut_filament/test_cut_filament.cpp b/tests/unit/logic/cut_filament/test_cut_filament.cpp index d7b18b1..a0f325a 100644 --- a/tests/unit/logic/cut_filament/test_cut_filament.cpp +++ b/tests/unit/logic/cut_filament/test_cut_filament.cpp @@ -45,7 +45,8 @@ void CutSlot(uint8_t cutSlot) { REQUIRE(VerifyState(cf, false, mi::Idler::IdleSlotIndex(), cutSlot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::SelectingFilamentSlot)); // now cycle at most some number of cycles (to be determined yet) and then verify, that the idler and selector reached their target positions - REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, 5000)); + // Beware - with the real positions of the selector, the number of steps needed to finish some states grows, so the ~40K steps here has a reason + REQUIRE(WhileTopState(cf, ProgressCode::SelectingFilamentSlot, selectorMoveMaxSteps)); // idler and selector reached their target positions and the CF automaton will start feeding to FINDA as the next step REQUIRE(VerifyState(cf, false, cutSlot, cutSlot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::FeedingToFinda)); @@ -84,11 +85,11 @@ void CutSlot(uint8_t cutSlot) { REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, cutSlot + 1, false, cutSlot, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::PerformingCut)); // cutting - REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, 10000)); + REQUIRE(WhileTopState(cf, ProgressCode::PerformingCut, selectorMoveMaxSteps)); REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, 0, false, cutSlot, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::ReturningSelector)); // moving selector to the other end of its axis - REQUIRE(WhileTopState(cf, ProgressCode::ReturningSelector, 5000)); + REQUIRE(WhileTopState(cf, ProgressCode::ReturningSelector, selectorMoveMaxSteps)); REQUIRE(VerifyState2(cf, /*true*/ false, cutSlot, ms::Selector::IdleSlotIndex(), false, cutSlot, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK)); } diff --git a/tests/unit/logic/load_filament/test_load_filament.cpp b/tests/unit/logic/load_filament/test_load_filament.cpp index a8fe2cc..ed7adf3 100644 --- a/tests/unit/logic/load_filament/test_load_filament.cpp +++ b/tests/unit/logic/load_filament/test_load_filament.cpp @@ -50,7 +50,7 @@ void LoadFilamentCommonSetup(uint8_t slot, logic::LoadFilament &lf) { REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::EngagingIdler)); // Stage 1 - engaging idler - REQUIRE(WhileTopState(lf, ProgressCode::EngagingIdler, 5000)); + REQUIRE(WhileTopState(lf, ProgressCode::EngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(VerifyState(lf, false, slot, slot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::FeedingToFinda)); } @@ -80,7 +80,7 @@ void LoadFilamentSuccessful(uint8_t slot, logic::LoadFilament &lf) { REQUIRE(VerifyState(lf, false, slot, slot, true, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::DisengagingIdler)); // Stage 4 - disengaging idler - REQUIRE(WhileTopState(lf, ProgressCode::DisengagingIdler, 5000)); + REQUIRE(WhileTopState(lf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(VerifyState(lf, true, mi::Idler::IdleSlotIndex(), slot, true, ml::on, ml::off, ErrorCode::OK, ProgressCode::OK)); } @@ -99,7 +99,7 @@ void FailedLoadToFinda(uint8_t slot, logic::LoadFilament &lf) { REQUIRE(VerifyState(lf, false, slot, slot, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRDisengagingIdler)); // Stage 3 - disengaging idler in error mode - REQUIRE(WhileTopState(lf, ProgressCode::ERRDisengagingIdler, 5000)); + REQUIRE(WhileTopState(lf, ProgressCode::ERR1DisengagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRWaitingForUser)); } @@ -122,7 +122,7 @@ void FailedLoadToFindaResolveHelp(uint8_t slot, logic::LoadFilament &lf) { REQUIRE(VerifyState(lf, false, mi::Idler::IdleSlotIndex(), slot, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERREngagingIdler)); // Stage 4 - engage the idler - REQUIRE(WhileTopState(lf, ProgressCode::ERREngagingIdler, 5000)); + REQUIRE(WhileTopState(lf, ProgressCode::ERR1EngagingIdler, idlerEngageDisengageMaxSteps)); REQUIRE(VerifyState(lf, false, slot, slot, false, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_ON, ProgressCode::ERRHelpingFilament)); } diff --git a/tests/unit/logic/stubs/main_loop_stub.h b/tests/unit/logic/stubs/main_loop_stub.h index f1d804f..cd6a4ea 100644 --- a/tests/unit/logic/stubs/main_loop_stub.h +++ b/tests/unit/logic/stubs/main_loop_stub.h @@ -24,3 +24,9 @@ bool WhileTopState(SM &sm, ProgressCode state, uint32_t maxLoops = 5000) { extern void EnsureActiveSlotIndex(uint8_t slot); extern void SetFINDAStateAndDebounce(bool press); + +// these are recommended max steps for simulated movement of the idler and selector +// - roughly the amount of motion steps from one end to the other + some margin +// ... could be computed in the future from the pre-set number of microsteps and real positions +static constexpr uint32_t idlerEngageDisengageMaxSteps = 40000UL; +static constexpr uint32_t selectorMoveMaxSteps = 40000UL; diff --git a/tests/unit/logic/stubs/stub_motion.cpp b/tests/unit/logic/stubs/stub_motion.cpp index 8624714..c888ea7 100644 --- a/tests/unit/logic/stubs/stub_motion.cpp +++ b/tests/unit/logic/stubs/stub_motion.cpp @@ -74,14 +74,14 @@ void Motion::AbortPlannedMoves() { } void ReinitMotion() { - const pos_t selector_pos = unitToSteps(config::selectorSlotPositions[0]); - // reset the simulation data to defaults axes[0] = AxisSim({ 0, 0, false, false, false }); // pulley -// axes[1] = AxisSim({ selector_pos, selector_pos, false, false, false }); // selector //@@TODO proper selector positions once defined -// axes[2] = AxisSim({ 0, 0, false, false, false }); // idler - axes[1] = AxisSim({ config::selectorSlotPositions[0], config::selectorSlotPositions[0], false, false, false }); // selector - axes[2] = AxisSim({ config::idlerSlotPositions[mi::Idler::IdleSlotIndex()], config::idlerSlotPositions[mi::Idler::IdleSlotIndex()], false, false, false }); // idler + axes[1] = AxisSim({ unitToSteps(config::selectorSlotPositions[0]), + unitToSteps(config::selectorSlotPositions[0]), + false, false, false }); // selector + axes[2] = AxisSim({ unitToSteps(config::idlerSlotPositions[mi::Idler::IdleSlotIndex()]), + unitToSteps(config::idlerSlotPositions[mi::Idler::IdleSlotIndex()]), + false, false, false }); // idler } /// probably higher-level operations knowing the semantic meaning of axes diff --git a/tests/unit/logic/tool_change/test_tool_change.cpp b/tests/unit/logic/tool_change/test_tool_change.cpp index 3080d4e..406168f 100644 --- a/tests/unit/logic/tool_change/test_tool_change.cpp +++ b/tests/unit/logic/tool_change/test_tool_change.cpp @@ -44,7 +44,7 @@ void ToolChange(uint8_t fromSlot, uint8_t toSlot) { hal::adc::SetADC(config::findaADCIndex, 0); } return tc.TopLevelState() == ProgressCode::UnloadingFilament; }, - 50000)); + 200000UL)); REQUIRE(mg::globals.FilamentLoaded() == false); REQUIRE(WhileCondition( @@ -54,7 +54,7 @@ void ToolChange(uint8_t fromSlot, uint8_t toSlot) { hal::adc::SetADC(config::findaADCIndex, 900); } return tc.TopLevelState() == ProgressCode::LoadingFilament; }, - 50000)); + 200000UL)); REQUIRE(tc.TopLevelState() == ProgressCode::OK); REQUIRE(mg::globals.FilamentLoaded() == true); diff --git a/tests/unit/logic/unload_filament/test_unload_filament.cpp b/tests/unit/logic/unload_filament/test_unload_filament.cpp index 5d02745..aa22314 100644 --- a/tests/unit/logic/unload_filament/test_unload_filament.cpp +++ b/tests/unit/logic/unload_filament/test_unload_filament.cpp @@ -66,7 +66,7 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) { hal::adc::SetADC(config::findaADCIndex, 0); } return uf.TopLevelState() == ProgressCode::UnloadingToFinda; }, - 5000)); + 50000)); // we still think we have filament loaded at this stage // idler should have been activated by the underlying automaton @@ -76,7 +76,7 @@ void RegularUnloadFromSlot04(uint8_t slot, logic::UnloadFilament &uf) { REQUIRE(VerifyState(uf, true, slot, slot, false, ml::blink0, ml::off, ErrorCode::OK, ProgressCode::DisengagingIdler)); // Stage 2 - idler was engaged, disengage it - REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, 5000)); + REQUIRE(WhileTopState(uf, ProgressCode::DisengagingIdler, idlerEngageDisengageMaxSteps)); // we still think we have filament loaded at this stage // idler should have been disengaged @@ -161,7 +161,7 @@ void FindaDidntTriggerCommonSetup(uint8_t slot, logic::UnloadFilament &uf) { REQUIRE(VerifyState(uf, true, slot, slot, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERRDisengagingIdler)); // Stage 2 - idler should get disengaged - REQUIRE(WhileTopState(uf, ProgressCode::ERRDisengagingIdler, 5000)); + REQUIRE(WhileTopState(uf, ProgressCode::ERR1DisengagingIdler, idlerEngageDisengageMaxSteps)); // we still think we have filament loaded at this stage // idler should have been disengaged @@ -197,7 +197,7 @@ void FindaDidntTriggerResolveHelp(uint8_t slot, logic::UnloadFilament &uf) { REQUIRE(VerifyState(uf, true, mi::Idler::IdleSlotIndex(), slot, true, ml::off, ml::blink0, ErrorCode::FINDA_DIDNT_SWITCH_OFF, ProgressCode::ERREngagingIdler)); // Stage 4 - engage the idler - REQUIRE(WhileTopState(uf, ProgressCode::ERREngagingIdler, 5000)); + REQUIRE(WhileTopState(uf, ProgressCode::ERR1EngagingIdler, idlerEngageDisengageMaxSteps)); // we still think we have filament loaded at this stage // idler should be engaged