UnloadFilament - refactor for the new Idler API

pull/21/head
D.R.racer 2021-06-09 09:35:39 +02:00 committed by DRracer
parent 96be4b18a2
commit 4a79b4b865
1 changed files with 8 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include "../modules/finda.h" #include "../modules/finda.h"
#include "../modules/leds.h" #include "../modules/leds.h"
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/idler.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
namespace logic { namespace logic {
@ -15,14 +16,15 @@ void UnloadFilament::Reset() {
mm::motion.InitAxis(mm::Pulley); mm::motion.InitAxis(mm::Pulley);
state = ProgressCode::EngagingIdler; state = ProgressCode::EngagingIdler;
error = ErrorCode::OK; error = ErrorCode::OK;
mm::motion.Idler(mm::Engage); modules::idler::idler.Engage(0); //@@TODO
} }
bool UnloadFilament::Step() { bool UnloadFilament::Step() {
namespace mm = modules::motion; namespace mm = modules::motion;
namespace mi = modules::idler;
switch (state) { switch (state) {
case ProgressCode::EngagingIdler: // state 1 engage idler case ProgressCode::EngagingIdler: // state 1 engage idler
if (mm::motion.IdlerEngaged()) { // if idler is in parked position un-park it get in contact with filament if (mi::idler.Engaged()) { // if idler is in parked position un-park it get in contact with filament
state = ProgressCode::UnloadingToFinda; state = ProgressCode::UnloadingToFinda;
unl.Reset(); unl.Reset();
} }
@ -37,11 +39,11 @@ bool UnloadFilament::Step() {
state = ProgressCode::DisengagingIdler; state = ProgressCode::DisengagingIdler;
} }
// in all cases disengage the idler // in all cases disengage the idler
mm::motion.Idler(mm::Disengage); mi::idler.Disengage();
} }
return false; return false;
case ProgressCode::DisengagingIdler: case ProgressCode::DisengagingIdler:
if (mm::motion.IdlerDisengaged()) { if (!mi::idler.Engaged()) {
state = ProgressCode::AvoidingGrind; state = ProgressCode::AvoidingGrind;
// mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants // mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants
} }
@ -49,7 +51,7 @@ bool UnloadFilament::Step() {
case ProgressCode::AvoidingGrind: // state 3 move a little bit so it is not a grinded hole in filament case ProgressCode::AvoidingGrind: // state 3 move a little bit so it is not a grinded hole in filament
if (mm::motion.QueueEmpty()) { if (mm::motion.QueueEmpty()) {
state = ProgressCode::FinishingMoves; state = ProgressCode::FinishingMoves;
mm::motion.Idler(mm::Disengage); mi::idler.Disengage();
return true; return true;
} }
return false; return false;
@ -61,7 +63,7 @@ bool UnloadFilament::Step() {
return false; return false;
case ProgressCode::ERR1DisengagingIdler: // couldn't unload to FINDA case ProgressCode::ERR1DisengagingIdler: // couldn't unload to FINDA
error = ErrorCode::UNLOAD_FINDA_DIDNT_TRIGGER; error = ErrorCode::UNLOAD_FINDA_DIDNT_TRIGGER;
if (mm::motion.IdlerDisengaged()) { if (!mi::idler.Engaged()) {
state = ProgressCode::ERR1WaitingForUser; state = ProgressCode::ERR1WaitingForUser;
} }
return false; return false;