Lay out the other high-level commands/operations

- cut, eject, load filament, toolchange
- uncomment them in main.cpp
- their implementation is still empty
pull/21/head
D.R.racer 2021-06-09 06:39:57 +02:00 committed by DRracer
parent 5b4eb0cee3
commit 05ff998c01
10 changed files with 218 additions and 6 deletions

View File

@ -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
)

View File

@ -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

26
src/logic/cut_filament.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#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

View File

@ -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

View File

@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#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

View File

@ -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

26
src/logic/load_filament.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#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

25
src/logic/tool_change.cpp Normal file
View File

@ -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

26
src/logic/tool_change.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#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

View File

@ -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();