diff --git a/CMakeLists.txt b/CMakeLists.txt index bbb38c9..fce1efb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,7 +196,11 @@ target_sources( src/modules/leds.cpp src/modules/motion.cpp src/logic/command_base.cpp + src/logic/cut_filament.cpp + src/logic/eject_filament.cpp + src/logic/load_filament.cpp src/logic/no_command.cpp + src/logic/tool_change.cpp src/logic/unload_filament.cpp src/logic/unload_to_finda.cpp ) diff --git a/src/logic/cut_filament.cpp b/src/logic/cut_filament.cpp new file mode 100644 index 0000000..92f7eeb --- /dev/null +++ b/src/logic/cut_filament.cpp @@ -0,0 +1,25 @@ +#include "cut_filament.h" +#include "../modules/buttons.h" +#include "../modules/finda.h" +#include "../modules/leds.h" +#include "../modules/motion.h" +#include "../modules/permanent_storage.h" + +namespace logic { + +CutFilament cutFilament; + +void CutFilament::Reset() { + namespace mm = modules::motion; + state = ProgressCode::EngagingIdler; + error = ErrorCode::OK; +} + +bool CutFilament::Step() { + namespace mm = modules::motion; + switch (state) { + } + return false; +} + +} // namespace logic diff --git a/src/logic/cut_filament.h b/src/logic/cut_filament.h new file mode 100644 index 0000000..1c6292f --- /dev/null +++ b/src/logic/cut_filament.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include "command_base.h" +#include "unload_to_finda.h" + +namespace logic { + +/// A high-level command state machine +/// Handles the complex logic of cutting filament +class CutFilament : public CommandBase { +public: + inline CutFilament() + : CommandBase() { Reset(); } + + /// Restart the automaton + void Reset() override; + + /// @returns true if the state machine finished its job, false otherwise + bool Step() override; + +private: +}; + +extern CutFilament cutFilament; + +} // namespace logic diff --git a/src/logic/eject_filament.cpp b/src/logic/eject_filament.cpp new file mode 100644 index 0000000..1f20a56 --- /dev/null +++ b/src/logic/eject_filament.cpp @@ -0,0 +1,25 @@ +#include "eject_filament.h" +#include "../modules/buttons.h" +#include "../modules/finda.h" +#include "../modules/leds.h" +#include "../modules/motion.h" +#include "../modules/permanent_storage.h" + +namespace logic { + +EjectFilament ejectFilament; + +void EjectFilament::Reset() { + namespace mm = modules::motion; + state = ProgressCode::EngagingIdler; + error = ErrorCode::OK; +} + +bool EjectFilament::Step() { + namespace mm = modules::motion; + switch (state) { + } + return false; +} + +} // namespace logic diff --git a/src/logic/eject_filament.h b/src/logic/eject_filament.h new file mode 100644 index 0000000..2717400 --- /dev/null +++ b/src/logic/eject_filament.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include "command_base.h" +#include "unload_to_finda.h" + +namespace logic { + +/// A high-level command state machine +/// Handles the complex logic of ejecting filament +class EjectFilament : public CommandBase { +public: + inline EjectFilament() + : CommandBase() { Reset(); } + + /// Restart the automaton + void Reset() override; + + /// @returns true if the state machine finished its job, false otherwise + bool Step() override; + +private: +}; + +extern EjectFilament ejectFilament; + +} // namespace logic diff --git a/src/logic/load_filament.cpp b/src/logic/load_filament.cpp new file mode 100644 index 0000000..c440947 --- /dev/null +++ b/src/logic/load_filament.cpp @@ -0,0 +1,25 @@ +#include "load_filament.h" +#include "../modules/buttons.h" +#include "../modules/finda.h" +#include "../modules/leds.h" +#include "../modules/motion.h" +#include "../modules/permanent_storage.h" + +namespace logic { + +LoadFilament loadFilament; + +void LoadFilament::Reset() { + namespace mm = modules::motion; + state = ProgressCode::EngagingIdler; + error = ErrorCode::OK; +} + +bool LoadFilament::Step() { + namespace mm = modules::motion; + switch (state) { + } + return false; +} + +} // namespace logic diff --git a/src/logic/load_filament.h b/src/logic/load_filament.h new file mode 100644 index 0000000..384fcd7 --- /dev/null +++ b/src/logic/load_filament.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include "command_base.h" +#include "unload_to_finda.h" + +namespace logic { + +/// A high-level command state machine +/// Handles the complex logic of loading filament +class LoadFilament : public CommandBase { +public: + inline LoadFilament() + : CommandBase() { Reset(); } + + /// Restart the automaton + void Reset() override; + + /// @returns true if the state machine finished its job, false otherwise + bool Step() override; + +private: +}; + +extern LoadFilament loadFilament; + +} // namespace logic diff --git a/src/logic/tool_change.cpp b/src/logic/tool_change.cpp new file mode 100644 index 0000000..d0126fc --- /dev/null +++ b/src/logic/tool_change.cpp @@ -0,0 +1,25 @@ +#include "tool_change.h" +#include "../modules/buttons.h" +#include "../modules/finda.h" +#include "../modules/leds.h" +#include "../modules/motion.h" +#include "../modules/permanent_storage.h" + +namespace logic { + +ToolChange toolChange; + +void ToolChange::Reset() { + namespace mm = modules::motion; + state = ProgressCode::EngagingIdler; + error = ErrorCode::OK; +} + +bool ToolChange::Step() { + namespace mm = modules::motion; + switch (state) { + } + return false; +} + +} // namespace logic diff --git a/src/logic/tool_change.h b/src/logic/tool_change.h new file mode 100644 index 0000000..7cac2ae --- /dev/null +++ b/src/logic/tool_change.h @@ -0,0 +1,26 @@ +#pragma once +#include +#include "command_base.h" +#include "unload_to_finda.h" + +namespace logic { + +/// A high-level command state machine +/// Handles the complex logic of tool change +class ToolChange : public CommandBase { +public: + inline ToolChange() + : CommandBase() { Reset(); } + + /// Restart the automaton + void Reset() override; + + /// @returns true if the state machine finished its job, false otherwise + bool Step() override; + +private: +}; + +extern ToolChange toolChange; + +} // namespace logic diff --git a/src/main.cpp b/src/main.cpp index e259942..1b673c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,11 @@ #include "modules/protocol.h" #include "logic/command_base.h" +#include "logic/cut_filament.h" +#include "logic/eject_filament.h" +#include "logic/load_filament.h" #include "logic/no_command.h" +#include "logic/tool_change.h" #include "logic/unload_filament.h" static modules::protocol::Protocol protocol; @@ -122,25 +126,25 @@ void SendMessage(const modules::protocol::ResponseMsg &msg) { void PlanCommand(const modules::protocol::RequestMsg &rq) { namespace mp = modules::protocol; if (currentCommand->Error() == ErrorCode::OK) { - // we are allowed to start a new command + // we are allowed to start a new command as the previous one is in the OK finished state switch (rq.code) { case mp::RequestMsgCodes::Cut: - //currentCommand = &cutCommand; + currentCommand = &logic::cutFilament; break; case mp::RequestMsgCodes::Eject: - //currentCommand = &ejectCommand; + currentCommand = &logic::ejectFilament; break; case mp::RequestMsgCodes::Load: - // currentCommand = &loadCommand; + currentCommand = &logic::loadFilament; break; case mp::RequestMsgCodes::Tool: - // currentCommand = &toolCommand; + currentCommand = &logic::toolChange; break; case mp::RequestMsgCodes::Unload: currentCommand = &logic::unloadFilament; break; default: - // currentCommand = &noCommand; + currentCommand = &logic::noCommand; break; } currentCommand->Reset();