Lay out the other high-level commands/operations
- cut, eject, load filament, toolchange - uncomment them in main.cpp - their implementation is still emptypull/21/head
parent
5b4eb0cee3
commit
05ff998c01
|
|
@ -196,7 +196,11 @@ target_sources(
|
||||||
src/modules/leds.cpp
|
src/modules/leds.cpp
|
||||||
src/modules/motion.cpp
|
src/modules/motion.cpp
|
||||||
src/logic/command_base.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/no_command.cpp
|
||||||
|
src/logic/tool_change.cpp
|
||||||
src/logic/unload_filament.cpp
|
src/logic/unload_filament.cpp
|
||||||
src/logic/unload_to_finda.cpp
|
src/logic/unload_to_finda.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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
16
src/main.cpp
16
src/main.cpp
|
|
@ -14,7 +14,11 @@
|
||||||
#include "modules/protocol.h"
|
#include "modules/protocol.h"
|
||||||
|
|
||||||
#include "logic/command_base.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/no_command.h"
|
||||||
|
#include "logic/tool_change.h"
|
||||||
#include "logic/unload_filament.h"
|
#include "logic/unload_filament.h"
|
||||||
|
|
||||||
static modules::protocol::Protocol protocol;
|
static modules::protocol::Protocol protocol;
|
||||||
|
|
@ -122,25 +126,25 @@ void SendMessage(const modules::protocol::ResponseMsg &msg) {
|
||||||
void PlanCommand(const modules::protocol::RequestMsg &rq) {
|
void PlanCommand(const modules::protocol::RequestMsg &rq) {
|
||||||
namespace mp = modules::protocol;
|
namespace mp = modules::protocol;
|
||||||
if (currentCommand->Error() == ErrorCode::OK) {
|
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) {
|
switch (rq.code) {
|
||||||
case mp::RequestMsgCodes::Cut:
|
case mp::RequestMsgCodes::Cut:
|
||||||
//currentCommand = &cutCommand;
|
currentCommand = &logic::cutFilament;
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Eject:
|
case mp::RequestMsgCodes::Eject:
|
||||||
//currentCommand = &ejectCommand;
|
currentCommand = &logic::ejectFilament;
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Load:
|
case mp::RequestMsgCodes::Load:
|
||||||
// currentCommand = &loadCommand;
|
currentCommand = &logic::loadFilament;
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Tool:
|
case mp::RequestMsgCodes::Tool:
|
||||||
// currentCommand = &toolCommand;
|
currentCommand = &logic::toolChange;
|
||||||
break;
|
break;
|
||||||
case mp::RequestMsgCodes::Unload:
|
case mp::RequestMsgCodes::Unload:
|
||||||
currentCommand = &logic::unloadFilament;
|
currentCommand = &logic::unloadFilament;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// currentCommand = &noCommand;
|
currentCommand = &logic::noCommand;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currentCommand->Reset();
|
currentCommand->Reset();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue