Introduce H0 command to invoke Idler+Selector homing seq. if safe

pull/148/head
D.R.racer 2021-11-19 11:52:05 +01:00 committed by DRracer
parent 9bf2b401e4
commit e064a6c2f5
6 changed files with 85 additions and 1 deletions

View File

@ -5,6 +5,7 @@ target_sources(
eject_filament.cpp
feed_to_bondtech.cpp
feed_to_finda.cpp
home.cpp
load_filament.cpp
no_command.cpp
retract_from_finda.cpp

39
src/logic/home.cpp Normal file
View File

@ -0,0 +1,39 @@
/// @file home.cpp
#include "home.h"
#include "../modules/finda.h"
#include "../modules/globals.h"
#include "../modules/idler.h"
#include "../modules/motion.h"
#include "../modules/permanent_storage.h"
#include "../modules/selector.h"
#include "../debug.h"
namespace logic {
Home home;
void Home::Reset(uint8_t /*param*/) {
error = ErrorCode::RUNNING;
state = ProgressCode::Homing;
InvalidateHomingAndFilamentState();
}
bool Home::StepInner() {
switch (state) {
case ProgressCode::Homing:
if (mi::idler.State() == mi::Idler::Ready && ms::selector.State() == ms::selector.Ready) {
state = ProgressCode::OK;
error = ErrorCode::OK;
}
break;
case ProgressCode::OK:
return true;
default: // we got into an unhandled state, better report it
state = ProgressCode::ERRInternal;
error = ErrorCode::INTERNAL;
return true;
}
return false;
}
} // namespace logic

37
src/logic/home.h Normal file
View File

@ -0,0 +1,37 @@
/// @file home.h
#pragma once
#include <stdint.h>
#include "command_base.h"
namespace logic {
/// @brief A high-level command state machine - wrapps the rehoming procedure to be used from a printer
///
/// The home operation consists of:
/// - invalidates Idler's and Selector's homing flags
/// - waits until Idler and Selector finish their homing sequences
///
/// Beware - Idler and Selector will NOT perform the homing moves if filament sensor state is not in the right state
/// - Idler: filament must not be in the fsensor or nozzle
/// - Selector: filament must not be in the selector, fsensor or nozzle
/// It is up to the printer to let the MMU unload filament first (to make sure everything is safe) and then issue the homing command
///
/// Moreover - Idler and Selector try to home automagically a runtime when they know it is safe.
/// This high-level command is just a way to invoke re-homing from the printer while all safety measures are kept.
class Home : public CommandBase {
public:
inline Home()
: CommandBase() {}
/// Restart the automaton
/// @param param unused
void Reset(uint8_t /*param*/) override;
/// @returns true if the state machine finished its job, false otherwise
bool StepInner() override;
};
/// The one and only instance of Home state machine in the FW
extern Home home;
} // namespace logic

View File

@ -35,4 +35,6 @@ enum class ProgressCode : uint_fast8_t {
ParkingSelector, // P23
EjectingFilament, // P24
RetractingFromFinda, // P25
Homing,
};

View File

@ -27,6 +27,7 @@
#include "logic/command_base.h"
#include "logic/cut_filament.h"
#include "logic/eject_filament.h"
#include "logic/home.h"
#include "logic/load_filament.h"
#include "logic/no_command.h"
#include "logic/set_mode.h"
@ -223,6 +224,9 @@ void PlanCommand(const mp::RequestMsg &rq) {
case mp::RequestMsgCodes::Eject:
currentCommand = &logic::ejectFilament;
break;
case mp::RequestMsgCodes::Home:
currentCommand = &logic::home;
break;
case mp::RequestMsgCodes::Load:
currentCommand = &logic::loadFilament;
break;

View File

@ -26,7 +26,8 @@ enum class RequestMsgCodes : uint8_t {
Wait = 'W',
Cut = 'K',
FilamentType = 'F',
FilamentSensor = 'f'
FilamentSensor = 'f',
Home = 'H'
};
/// Definition of response message parameter codes