Extract common Dis/Engaging of idler in Error states into base class
parent
c2325b687a
commit
afab309d27
|
|
@ -1,5 +1,6 @@
|
||||||
/// @file command_base.cpp
|
/// @file command_base.cpp
|
||||||
#include "command_base.h"
|
#include "command_base.h"
|
||||||
|
#include "../modules/globals.h"
|
||||||
#include "../modules/idler.h"
|
#include "../modules/idler.h"
|
||||||
#include "../modules/selector.h"
|
#include "../modules/selector.h"
|
||||||
#include "../modules/motion.h"
|
#include "../modules/motion.h"
|
||||||
|
|
@ -105,4 +106,17 @@ void CommandBase::ErrDisengagingIdler() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandBase::GoToErrDisengagingIdler(ErrorCode ec) {
|
||||||
|
state = ProgressCode::ERRDisengagingIdler;
|
||||||
|
error = ec;
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
||||||
|
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
|
||||||
|
mi::idler.Disengage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandBase::GoToErrEngagingIdler() {
|
||||||
|
state = ProgressCode::ERREngagingIdler;
|
||||||
|
mi::idler.Engage(mg::globals.ActiveSlot());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace logic
|
} // namespace logic
|
||||||
|
|
|
||||||
|
|
@ -75,9 +75,15 @@ protected:
|
||||||
/// If not, it returns false and sets the error to ErrorCode::INVALID_TOOL
|
/// If not, it returns false and sets the error to ErrorCode::INVALID_TOOL
|
||||||
bool CheckToolIndex(uint8_t index);
|
bool CheckToolIndex(uint8_t index);
|
||||||
|
|
||||||
/// Common error processing - disengaging idler
|
/// Perform disengaging idler in ErrDisengagingIdler state
|
||||||
void ErrDisengagingIdler();
|
void ErrDisengagingIdler();
|
||||||
|
|
||||||
|
/// Transit the state machine into ErrDisengagingIdler
|
||||||
|
void GoToErrDisengagingIdler(ErrorCode ec);
|
||||||
|
|
||||||
|
/// Transit the state machine into ErrEngagingIdler
|
||||||
|
void GoToErrEngagingIdler();
|
||||||
|
|
||||||
ProgressCode state; ///< current progress state of the state machine
|
ProgressCode state; ///< current progress state of the state machine
|
||||||
ErrorCode error; ///< current error code
|
ErrorCode error; ///< current error code
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,7 @@ bool LoadFilament::StepInner() {
|
||||||
if (feed.Step()) {
|
if (feed.Step()) {
|
||||||
if (feed.State() == FeedToFinda::Failed) {
|
if (feed.State() == FeedToFinda::Failed) {
|
||||||
// @@TODO - try to repeat 6x - push/pull sequence - probably something to put into feed_to_finda as an option
|
// @@TODO - try to repeat 6x - push/pull sequence - probably something to put into feed_to_finda as an option
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON); // signal loading error
|
||||||
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
|
|
||||||
mi::idler.Disengage();
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::RetractingFromFinda;
|
state = ProgressCode::RetractingFromFinda;
|
||||||
retract.Reset();
|
retract.Reset();
|
||||||
|
|
@ -59,14 +55,11 @@ bool LoadFilament::StepInner() {
|
||||||
case ProgressCode::RetractingFromFinda:
|
case ProgressCode::RetractingFromFinda:
|
||||||
if (retract.Step()) {
|
if (retract.Step()) {
|
||||||
if (retract.State() == RetractFromFinda::Failed) {
|
if (retract.State() == RetractFromFinda::Failed) {
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF); // signal loading error
|
||||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::DisengagingIdler;
|
state = ProgressCode::DisengagingIdler;
|
||||||
|
mi::idler.Disengage();
|
||||||
}
|
}
|
||||||
mi::idler.Disengage(); // disengage in both cases
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProgressCode::DisengagingIdler:
|
case ProgressCode::DisengagingIdler:
|
||||||
|
|
@ -88,8 +81,7 @@ bool LoadFilament::StepInner() {
|
||||||
mui::Event ev = mui::userInput.ConsumeEvent();
|
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
||||||
state = ProgressCode::ERREngagingIdler;
|
GoToErrEngagingIdler();
|
||||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
|
||||||
break;
|
break;
|
||||||
case mui::Event::Middle: // try again the whole sequence
|
case mui::Event::Middle: // try again the whole sequence
|
||||||
// however it depends on the state of FINDA - if it is on, we must perform unload first
|
// however it depends on the state of FINDA - if it is on, we must perform unload first
|
||||||
|
|
@ -127,7 +119,7 @@ bool LoadFilament::StepInner() {
|
||||||
GoToRetractingFromFinda();
|
GoToRetractingFromFinda();
|
||||||
} else if (mm::motion.QueueEmpty()) {
|
} else if (mm::motion.QueueEmpty()) {
|
||||||
// helped a bit, but FINDA didn't trigger, return to the main error state
|
// helped a bit, but FINDA didn't trigger, return to the main error state
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
default: // we got into an unhandled state, better report it
|
default: // we got into an unhandled state, better report it
|
||||||
|
|
|
||||||
|
|
@ -60,11 +60,7 @@ bool ToolChange::StepInner() {
|
||||||
case ProgressCode::FeedingToFinda:
|
case ProgressCode::FeedingToFinda:
|
||||||
if (feed.Step()) {
|
if (feed.Step()) {
|
||||||
if (feed.State() == FeedToFinda::Failed) {
|
if (feed.State() == FeedToFinda::Failed) {
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_ON); // signal loading error
|
||||||
error = ErrorCode::FINDA_DIDNT_SWITCH_ON;
|
|
||||||
mi::idler.Disengage();
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::FeedingToBondtech;
|
state = ProgressCode::FeedingToBondtech;
|
||||||
james.Reset(3);
|
james.Reset(3);
|
||||||
|
|
@ -74,11 +70,7 @@ bool ToolChange::StepInner() {
|
||||||
case ProgressCode::FeedingToBondtech:
|
case ProgressCode::FeedingToBondtech:
|
||||||
if (james.Step()) {
|
if (james.Step()) {
|
||||||
if (james.State() == FeedToBondtech::Failed) {
|
if (james.State() == FeedToBondtech::Failed) {
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_ON); // signal loading error
|
||||||
error = ErrorCode::FSENSOR_DIDNT_SWITCH_ON;
|
|
||||||
mi::idler.Disengage();
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::OK;
|
state = ProgressCode::OK;
|
||||||
error = ErrorCode::OK;
|
error = ErrorCode::OK;
|
||||||
|
|
@ -97,8 +89,7 @@ bool ToolChange::StepInner() {
|
||||||
mui::Event ev = mui::userInput.ConsumeEvent();
|
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
case mui::Event::Left: // try to manually load just a tiny bit - help the filament with the pulley
|
||||||
state = ProgressCode::ERREngagingIdler;
|
GoToErrEngagingIdler();
|
||||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
|
||||||
break;
|
break;
|
||||||
case mui::Event::Middle: // try again the whole sequence
|
case mui::Event::Middle: // try again the whole sequence
|
||||||
Reset(mg::globals.ActiveSlot());
|
Reset(mg::globals.ActiveSlot());
|
||||||
|
|
@ -146,7 +137,7 @@ bool ToolChange::StepInner() {
|
||||||
error = ErrorCode::RUNNING;
|
error = ErrorCode::RUNNING;
|
||||||
} else if (mm::motion.QueueEmpty()) {
|
} else if (mm::motion.QueueEmpty()) {
|
||||||
// helped a bit, but FINDA/Fsensor didn't trigger, return to the main error state
|
// helped a bit, but FINDA/Fsensor didn't trigger, return to the main error state
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_ON);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
default: // we got into an unhandled state, better report it
|
default: // we got into an unhandled state, better report it
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,11 @@ bool UnloadFilament::StepInner() {
|
||||||
if (unl.Step()) {
|
if (unl.Step()) {
|
||||||
if (unl.State() == UnloadToFinda::Failed) {
|
if (unl.State() == UnloadToFinda::Failed) {
|
||||||
// couldn't unload to FINDA, report error and wait for user to resolve it
|
// couldn't unload to FINDA, report error and wait for user to resolve it
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF);
|
||||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0);
|
|
||||||
mi::idler.Disengage();
|
|
||||||
} else if (mfs::fsensor.Pressed()) {
|
} else if (mfs::fsensor.Pressed()) {
|
||||||
// fsensor still pressed - that smells bad - a piece of filament may still be present in the heatsink
|
// fsensor still pressed - that smells bad - a piece of filament may still be present in the heatsink
|
||||||
// and that would cause serious problems while loading another filament
|
// and that would cause serious problems while loading another filament
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FSENSOR_DIDNT_SWITCH_OFF);
|
||||||
error = ErrorCode::FSENSOR_DIDNT_SWITCH_OFF;
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::RetractingFromFinda;
|
state = ProgressCode::RetractingFromFinda;
|
||||||
retract.Reset();
|
retract.Reset();
|
||||||
|
|
@ -57,14 +52,11 @@ bool UnloadFilament::StepInner() {
|
||||||
case ProgressCode::RetractingFromFinda:
|
case ProgressCode::RetractingFromFinda:
|
||||||
if (retract.Step()) {
|
if (retract.Step()) {
|
||||||
if (retract.State() == RetractFromFinda::Failed) {
|
if (retract.State() == RetractFromFinda::Failed) {
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF); // signal unloading error
|
||||||
error = ErrorCode::FINDA_DIDNT_SWITCH_OFF;
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::off);
|
|
||||||
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::red, ml::blink0); // signal loading error
|
|
||||||
} else {
|
} else {
|
||||||
state = ProgressCode::DisengagingIdler;
|
state = ProgressCode::DisengagingIdler;
|
||||||
|
mi::idler.Disengage();
|
||||||
}
|
}
|
||||||
mi::idler.Disengage();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ProgressCode::DisengagingIdler:
|
case ProgressCode::DisengagingIdler:
|
||||||
|
|
@ -85,8 +77,7 @@ bool UnloadFilament::StepInner() {
|
||||||
mui::Event ev = mui::userInput.ConsumeEvent();
|
mui::Event ev = mui::userInput.ConsumeEvent();
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case mui::Event::Left: // try to manually unload just a tiny bit - help the filament with the pulley
|
case mui::Event::Left: // try to manually unload just a tiny bit - help the filament with the pulley
|
||||||
state = ProgressCode::ERREngagingIdler;
|
GoToErrEngagingIdler();
|
||||||
mi::idler.Engage(mg::globals.ActiveSlot());
|
|
||||||
break;
|
break;
|
||||||
case mui::Event::Middle: // try again the whole sequence
|
case mui::Event::Middle: // try again the whole sequence
|
||||||
Reset(0);
|
Reset(0);
|
||||||
|
|
@ -127,7 +118,7 @@ bool UnloadFilament::StepInner() {
|
||||||
error = ErrorCode::RUNNING;
|
error = ErrorCode::RUNNING;
|
||||||
} else if (mm::motion.QueueEmpty()) {
|
} else if (mm::motion.QueueEmpty()) {
|
||||||
// helped a bit, but FINDA didn't trigger, return to the main error state
|
// helped a bit, but FINDA didn't trigger, return to the main error state
|
||||||
state = ProgressCode::ERRDisengagingIdler;
|
GoToErrDisengagingIdler(ErrorCode::FINDA_DIDNT_SWITCH_OFF);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case ProgressCode::OK:
|
case ProgressCode::OK:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue