Add homing capability to Idler and Selector

MMU-73
pull/120/head
D.R.racer 2021-09-07 07:44:03 +02:00 committed by DRracer
parent d18032b729
commit dea41738a5
6 changed files with 49 additions and 6 deletions

View File

@ -13,6 +13,10 @@ void Idler::PrepareMoveToPlannedSlot() {
mm::motion.PlanMoveTo<mm::Idler>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate));
}
void Idler::PlanHomingMove() {
mm::motion.PlanMove<mm::Idler>(mm::unitToAxisUnit<mm::I_pos_t>(-360.0_deg), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate));
}
Idler::OperationResult Idler::Disengage() {
if (state == Moving)
return OperationResult::Refused;
@ -43,8 +47,7 @@ bool Idler::Home() {
if (state == Moving)
return false;
plannedEngage = false;
mm::motion.InitAxis(mm::Idler);
mm::motion.Home(mm::Idler, false);
PlanHome(mm::Idler);
return true;
}
@ -53,6 +56,9 @@ bool Idler::Step() {
case Moving:
PerformMove(mm::Idler);
return false;
case Homing:
PerformHome(mm::Idler);
return false;
case Ready:
currentlyEngaged = plannedEngage;
currentSlot = plannedSlot;

View File

@ -48,10 +48,9 @@ public:
/// @returns the index of idle position of the idler, usually 5 in case of 0-4 valid indices of filament slots
inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; }
// hal::tmc2130::MotorParams TMCDriverParams()const;
protected:
virtual void PrepareMoveToPlannedSlot() override;
virtual void PlanHomingMove() override;
private:
/// direction of travel - engage/disengage

View File

@ -1,9 +1,21 @@
#include "movable_base.h"
#include "globals.h"
#include "motion.h"
namespace modules {
namespace motion {
void MovableBase::PlanHome(config::Axis axis) {
// switch to normal mode on this axis
state = Homing;
mm::motion.InitAxis(axis);
mm::motion.SetMode(axis, mm::Normal);
mm::motion.StallGuardReset(axis);
// plan move at least as long as the axis can go from one side to the other
PlanHomingMove(); // mm::motion.PlanMove(axis, delta, 1000);
}
MovableBase::OperationResult MovableBase::InitMovement(config::Axis axis) {
if (motion.InitAxis(axis)) {
PrepareMoveToPlannedSlot();
@ -26,5 +38,17 @@ void MovableBase::PerformMove(config::Axis axis) {
}
}
void MovableBase::PerformHome(config::Axis axis) {
if (mm::motion.StallGuard(axis)) {
// we have reached the end of the axis - homed ok
mm::motion.SetMode(axis, mg::globals.MotorsStealth() ? mm::Stealth : mm::Normal);
state = Ready;
} else if (mm::motion.QueueEmpty(axis)) {
// we ran out of planned moves but no StallGuard event has occurred - homing failed
mm::motion.SetMode(axis, mg::globals.MotorsStealth() ? mm::Stealth : mm::Normal);
state = Failed;
}
}
} // namespace motion
} // namespace modules

View File

@ -13,6 +13,7 @@ public:
enum {
Ready = 0, // intentionally set as zero in order to allow zeroing the Idler structure upon startup -> avoid explicit initialization code
Moving,
Homing,
Failed
};
@ -40,6 +41,9 @@ public:
inline hal::tmc2130::ErrorFlags TMCErrorFlags() const { return tmcErrorFlags; }
/// Prepare a homing move of the axis
void PlanHome(config::Axis axis);
protected:
/// internal state of the automaton
uint8_t state;
@ -54,10 +58,13 @@ protected:
hal::tmc2130::ErrorFlags tmcErrorFlags;
virtual void PrepareMoveToPlannedSlot() = 0;
virtual void PlanHomingMove() = 0;
OperationResult InitMovement(config::Axis axis);
void PerformMove(config::Axis axis);
void PerformHome(config::Axis axis);
};
} // namespace motion

View File

@ -13,6 +13,10 @@ void Selector::PrepareMoveToPlannedSlot() {
mm::motion.PlanMoveTo<mm::Selector>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate));
}
void Selector::PlanHomingMove() {
mm::motion.PlanMove<mm::Selector>(mm::unitToAxisUnit<mm::S_pos_t>(-100.0_mm), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate));
}
Selector::OperationResult Selector::MoveToSlot(uint8_t slot) {
if (state == Moving)
return OperationResult::Refused;
@ -28,8 +32,7 @@ Selector::OperationResult Selector::MoveToSlot(uint8_t slot) {
bool Selector::Home() {
if (state == Moving)
return false;
mm::motion.InitAxis(mm::Selector);
mm::motion.Home(mm::Selector, false);
PlanHome(mm::Selector);
return true;
}
@ -38,6 +41,9 @@ bool Selector::Step() {
case Moving:
PerformMove(mm::Selector);
return false;
case Homing:
PerformHome(mm::Selector);
return false;
case Ready:
currentSlot = plannedSlot;
mm::motion.Disable(mm::Selector); // turn off selector motor's power every time

View File

@ -39,6 +39,7 @@ public:
protected:
virtual void PrepareMoveToPlannedSlot() override;
virtual void PlanHomingMove() override;
private:
};