Workaround planning moves longer than 32K steps

pull/135/head
D.R.racer 2021-10-29 17:09:43 +02:00 committed by DRracer
parent 7f9fc78cf6
commit 5f1e3e018e
4 changed files with 29 additions and 8 deletions

View File

@ -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;

View File

@ -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<mm::Pulley>(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<mm::Pulley>(config::defaultBowdenLength, config::pulleyFeedrate, config::pulleySlowFeedrate);
}
return false;
case PushingFilamentToFSensor:

View File

@ -162,6 +162,27 @@ public:
unitToAxisUnit<AxisUnit<steps_t, A, Speed>>(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 <Axis A, config::UnitBase B>
constexpr void PlanLongMove(config::Unit<long double, B, Lenght> delta,
config::Unit<long double, B, Speed> feed_rate, config::Unit<long double, B, Speed> end_rate = { 0 }) {
auto steps = unitToAxisUnit<AxisUnit<pos_t, A, Lenght>>(delta);
while (steps.v > 32767) {
PlanMove<A>(
{ 32767 },
unitToAxisUnit<AxisUnit<steps_t, A, Speed>>(feed_rate),
unitToAxisUnit<AxisUnit<steps_t, A, Speed>>(feed_rate)); // keep the end feedrate the same to continue with the next segment
steps.v -= 32767;
}
PlanMove<A>( // last segment
steps,
unitToAxisUnit<AxisUnit<steps_t, A, Speed>>(feed_rate),
unitToAxisUnit<AxisUnit<steps_t, A, Speed>>(end_rate));
}
/// @returns head position of an axis (last enqueued position)
/// @param axis axis affected
pos_t Position(Axis axis) const;

View File

@ -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));
}