Fixes after rebase onto PR#174
parent
ecd63b6138
commit
3ffe188143
|
|
@ -9,6 +9,7 @@
|
|||
#include "../modules/permanent_storage.h"
|
||||
#include "../modules/pulley.h"
|
||||
#include "../debug.h"
|
||||
#include "../config/axis.h"
|
||||
|
||||
namespace logic {
|
||||
|
||||
|
|
@ -40,18 +41,18 @@ void FeedToBondtech::UpdateBowdenLength(int32_t feedEnd_mm) {
|
|||
}
|
||||
}
|
||||
|
||||
bool FeedToBondtech::PushingFilament() {
|
||||
if (mfs::fsensor.Pressed()) {
|
||||
mm::motion.AbortPlannedMoves(); // stop pushing filament
|
||||
GoToPushToNozzle();
|
||||
} else if (mm::motion.StallGuard(mm::Pulley)) {
|
||||
// stall guard occurred during movement - the filament got stuck
|
||||
state = Failed; // @@TODO may be even report why it failed
|
||||
} else if (mm::motion.QueueEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//bool FeedToBondtech::PushingFilament() {
|
||||
// if (mfs::fsensor.Pressed()) {
|
||||
// mm::motion.AbortPlannedMoves(); // stop pushing filament
|
||||
// GoToPushToNozzle();
|
||||
// } else if (mm::motion.StallGuard(mm::Pulley)) {
|
||||
// // stall guard occurred during movement - the filament got stuck
|
||||
// state = Failed; // @@TODO may be even report why it failed
|
||||
// } else if (mm::motion.QueueEmpty()) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
//}
|
||||
|
||||
bool FeedToBondtech::Step() {
|
||||
switch (state) {
|
||||
|
|
@ -92,30 +93,6 @@ bool FeedToBondtech::Step() {
|
|||
// // stall guard occurred during movement - the filament got stuck
|
||||
// state = PulleyStalled;
|
||||
} else if (mm::motion.QueueEmpty()) { // all moves have been finished and the fsensor didn't switch on
|
||||
/*=======
|
||||
dbg_logic_fP(PSTR("Pulley start steps %u"), mm::motion.CurPosition(mm::Pulley));
|
||||
state = PushingFilamentToFSensorFast;
|
||||
mm::motion.InitAxis(mm::Pulley);
|
||||
feedStart_mm = mm::stepsToUnit<mm::P_pos_t>(mm::P_pos_t({ mm::motion.CurPosition(mm::Pulley) }));
|
||||
// fast feed in millimeters - if the EEPROM value is incorrect, we'll get the default length
|
||||
mm::motion.PlanMove<mm::Pulley>(
|
||||
{ (long double)mps::BowdenLength::Get(mg::globals.ActiveSlot()) },
|
||||
config::pulleyFeedrate, config::pulleySlowFeedrate);
|
||||
}
|
||||
return false;
|
||||
case PushingFilamentToFSensorFast:
|
||||
if (!PushingFilament()) { // ran out of stored bowden length, continue slowly
|
||||
state = PushingFilamentToFSensorSlow;
|
||||
// do the remaining move up to maximum bowden length slowly
|
||||
mm::motion.PlanMove<mm::Pulley>(
|
||||
{ (long double)abs(config::maximumBowdenLength.v - mps::BowdenLength::Get(mg::globals.ActiveSlot())) }, // fast feed in millimeters - if the EEPROM value is incorrect, we'll
|
||||
config::pulleySlowFeedrate, config::pulleySlowFeedrate);
|
||||
}
|
||||
return false;
|
||||
case PushingFilamentToFSensorSlow:
|
||||
if (!PushingFilament()) { // all moves have been finished and the fsensor didn't switch on
|
||||
>>>>>>> Add bowden length runtime detection and tuning
|
||||
*/
|
||||
state = Failed;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ private:
|
|||
void UpdateBowdenLength(int32_t feedEnd_mm);
|
||||
|
||||
/// Common processing of pushing filament into fsensor (reused by multiple states)
|
||||
bool PushingFilament();
|
||||
// bool PushingFilament();
|
||||
|
||||
uint8_t state;
|
||||
uint8_t maxRetries;
|
||||
|
|
|
|||
|
|
@ -138,6 +138,16 @@ static constexpr T truncatedUnit(U v, long double mul = 1.) {
|
|||
return (T)(v.v * mul);
|
||||
}
|
||||
|
||||
/// Convert an AxisUnit to unit::Unit.
|
||||
/// The scaling factor is stored with the pair config::AxisConfig::uSteps and
|
||||
/// config::AxisConfig::stepsPerUnit (one per-axis).
|
||||
template <typename U, typename AU>
|
||||
static constexpr typename U::type_t axisUnitToUnit(AU v) {
|
||||
static_assert(AU::unit == U::unit, "incorrect unit type conversion");
|
||||
//static_assert(U::base == axisScale[AU::axis].base, "incorrect unit base conversion");
|
||||
return { (typename U::type_t)(v.v / axisScale[AU::axis].stepsPerUnit) };
|
||||
}
|
||||
|
||||
/// Convert a unit::Unit to a steps type (pos_t or steps_t).
|
||||
/// Extract the raw step count from an AxisUnit with type checking.
|
||||
template <typename AU, typename U>
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ static bool validBowdenLen(const uint16_t BowdenLength) {
|
|||
uint16_t BowdenLength::Get(uint8_t slot) {
|
||||
if (validFilament(slot)) {
|
||||
// @@TODO these reinterpret_cast expressions look horrible but I'm keeping them almost intact to respect the original code from MM_control_01
|
||||
uint16_t bowdenLength = ee::EEPROM::ReadByte(reinterpret_cast<size_t>(&(eepromBase->eepromBowdenLen[slot])));
|
||||
uint16_t bowdenLength = ee::EEPROM::ReadWord(reinterpret_cast<size_t>(&(eepromBase->eepromBowdenLen[slot])));
|
||||
|
||||
if (eepromEmpty == bowdenLength) {
|
||||
const uint8_t LengthCorrectionLegacy = ee::EEPROM::ReadByte(reinterpret_cast<size_t>(&(eepromBase->eepromLengthCorrection)));
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ TEST_CASE("feed_to_bondtech::feed_phase_unlimited", "[feed_to_bondtech]") {
|
|||
ForceReinitAllAutomata();
|
||||
REQUIRE(EnsureActiveSlotIndex(slot, mg::FilamentLoadState::AtPulley));
|
||||
|
||||
// reset bowden lenghts in EEPROM
|
||||
InitBowdenLengths();
|
||||
// check bowden lengths
|
||||
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
|
||||
REQUIRE(mps::BowdenLength::Get(mg::globals.ActiveSlot()) == config::minimumBowdenLength.v);
|
||||
}
|
||||
|
||||
FeedToBondtech fb;
|
||||
main_loop();
|
||||
|
||||
|
|
@ -71,7 +78,7 @@ TEST_CASE("feed_to_bondtech::feed_phase_unlimited", "[feed_to_bondtech]") {
|
|||
if( step == 100 ){
|
||||
mfs::fsensor.ProcessMessage(true);
|
||||
}
|
||||
return fb.State() == FeedToBondtech::PushingFilamentToFSensorFast; },
|
||||
return fb.State() == FeedToBondtech::PushingFilamentToFSensor; },
|
||||
1500));
|
||||
|
||||
REQUIRE(mfs::fsensor.Pressed());
|
||||
|
|
|
|||
|
|
@ -158,6 +158,13 @@ void ClearButtons(logic::CommandBase &cb) {
|
|||
}
|
||||
}
|
||||
|
||||
void InitBowdenLengths() {
|
||||
// reset bowdenLenght in EEPROM
|
||||
for (uint8_t slot = 0; slot < config::toolCount; ++slot) {
|
||||
mps::BowdenLength::Set(slot, config::minimumBowdenLength.v);
|
||||
}
|
||||
}
|
||||
|
||||
void SetFSensorStateAndDebounce(bool press) {
|
||||
mfs::fsensor.ProcessMessage(press);
|
||||
for (uint8_t fs = 0; fs < config::fsensorDebounceMs + 1; ++fs) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ bool SimulateRetractFromFINDA(uint32_t step, uint32_t findaOff);
|
|||
void PressButtonAndDebounce(logic::CommandBase &cb, uint8_t btnIndex, bool fromPrinter);
|
||||
void ClearButtons(logic::CommandBase &cb);
|
||||
|
||||
void InitBowdenLengths();
|
||||
void SetFSensorStateAndDebounce(bool press);
|
||||
|
||||
// these are recommended max steps for simulated movement of the idler and selector
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ void CheckFinishedCorrectly(logic::ToolChange &tc, uint8_t toSlot) {
|
|||
|
||||
void ToolChange(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
||||
ForceReinitAllAutomata();
|
||||
InitBowdenLengths();
|
||||
|
||||
REQUIRE(EnsureActiveSlotIndex(fromSlot, mg::FilamentLoadState::InNozzle));
|
||||
SetFINDAStateAndDebounce(true);
|
||||
|
|
@ -96,6 +97,7 @@ void ToolChange(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
|||
|
||||
void NoToolChange(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
||||
ForceReinitAllAutomata();
|
||||
InitBowdenLengths();
|
||||
|
||||
REQUIRE(EnsureActiveSlotIndex(fromSlot, mg::FilamentLoadState::InNozzle));
|
||||
// the filament is LOADED
|
||||
|
|
@ -114,6 +116,7 @@ void NoToolChange(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
|||
|
||||
void JustLoadFilament(logic::ToolChange &tc, uint8_t slot) {
|
||||
ForceReinitAllAutomata();
|
||||
InitBowdenLengths();
|
||||
|
||||
REQUIRE(EnsureActiveSlotIndex(slot, mg::FilamentLoadState::AtPulley));
|
||||
|
||||
|
|
@ -175,6 +178,7 @@ TEST_CASE("tool_change::same_slot_just_unloaded_filament", "[tool_change]") {
|
|||
|
||||
void ToolChangeFailLoadToFinda(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
||||
ForceReinitAllAutomata();
|
||||
InitBowdenLengths();
|
||||
|
||||
REQUIRE(EnsureActiveSlotIndex(fromSlot, mg::FilamentLoadState::InNozzle));
|
||||
SetFINDAStateAndDebounce(true);
|
||||
|
|
@ -340,6 +344,7 @@ TEST_CASE("tool_change::load_fail_FINDA_resolve_btnR_FINDA", "[tool_change]") {
|
|||
void ToolChangeFailFSensor(logic::ToolChange &tc, uint8_t fromSlot, uint8_t toSlot) {
|
||||
using namespace std::placeholders;
|
||||
ForceReinitAllAutomata();
|
||||
InitBowdenLengths();
|
||||
|
||||
REQUIRE(EnsureActiveSlotIndex(fromSlot, mg::FilamentLoadState::InNozzle));
|
||||
SetFINDAStateAndDebounce(true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue