Add Tool change operation

pull/21/head
D.R.racer 2021-06-10 08:16:56 +02:00 committed by DRracer
parent ea65b75120
commit 7cab9dc915
4 changed files with 57 additions and 7 deletions

View File

@ -1,11 +1,11 @@
#include "eject_filament.h" #include "eject_filament.h"
#include "../modules/buttons.h" #include "../modules/buttons.h"
#include "../modules/finda.h" #include "../modules/finda.h"
#include "../modules/idler.h"
#include "../modules/leds.h" #include "../modules/leds.h"
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/selector.h"
#include "../modules/idler.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/selector.h"
namespace logic { namespace logic {

View File

@ -18,6 +18,7 @@ enum class ProgressCode : uint_fast8_t {
ERR1WaitingForUser, ERR1WaitingForUser,
UnloadingFilament, UnloadingFilament,
LoadingFilament,
SelectingFilamentSlot, SelectingFilamentSlot,
FeedingToFINDA, FeedingToFINDA,
PreparingBlade, PreparingBlade,

View File

@ -1,23 +1,68 @@
#include "tool_change.h" #include "tool_change.h"
#include "../modules/buttons.h" #include "../modules/buttons.h"
#include "../modules/finda.h" #include "../modules/finda.h"
#include "../modules/idler.h"
#include "../modules/leds.h" #include "../modules/leds.h"
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/selector.h"
namespace logic { namespace logic {
ToolChange toolChange; ToolChange toolChange;
void ToolChange::Reset(uint8_t param) {
namespace mm = modules::motion; namespace mm = modules::motion;
state = ProgressCode::EngagingIdler; namespace mi = modules::idler;
error = ErrorCode::OK; namespace ms = modules::selector;
void ToolChange::Reset(uint8_t param) {
// if( param == active_extruder ) // @@TODO
// return true;
plannedSlot = param;
bool isFilamentLoaded = true; //@@TODO
if (isFilamentLoaded) {
state = ProgressCode::UnloadingFilament;
unl.Reset(0); //@@TODO act on active extruder only
} else {
state = ProgressCode::LoadingFilament;
load.Reset(plannedSlot);
}
} }
bool ToolChange::Step() { bool ToolChange::Step() {
namespace mm = modules::motion;
switch (state) { switch (state) {
case ProgressCode::UnloadingFilament:
if (unl.Step()) {
// unloading sequence finished
switch (unl.Error()) {
case ErrorCode::OK: // finished successfully
state = ProgressCode::LoadingFilament;
load.Reset(plannedSlot);
break;
case ErrorCode::UNLOAD_ERROR2: // @@TODO what shall we do in case of this error?
case ErrorCode::UNLOAD_FINDA_DIDNT_TRIGGER:
break;
}
}
break;
case ProgressCode::LoadingFilament:
if (load.Step()) {
// unloading sequence finished
switch (load.Error()) {
case ErrorCode::OK: // finished successfully
state = ProgressCode::OK;
break;
// case ErrorCode::LOAD_ERROR2: // @@TODO load errors?
// case ErrorCode::LOAD_FINDA_DIDNT_TRIGGER:
break;
}
}
break;
case ProgressCode::OK:
return true;
} }
return false; return false;
} }

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include "command_base.h" #include "command_base.h"
#include "unload_to_finda.h" #include "unload_filament.h"
#include "load_filament.h"
namespace logic { namespace logic {
@ -19,6 +20,9 @@ public:
bool Step() override; bool Step() override;
private: private:
UnloadFilament unl; ///< a high-level command/operation may be used as a building block of other operations as well
LoadFilament load;
uint8_t plannedSlot;
}; };
extern ToolChange toolChange; extern ToolChange toolChange;