Make logic prototype compilable
parent
2159558d88
commit
6f1624b718
|
|
@ -195,6 +195,7 @@ target_sources(
|
|||
src/modules/finda.cpp
|
||||
src/modules/leds.cpp
|
||||
src/modules/motion.cpp
|
||||
src/logic/mm_control.cpp
|
||||
)
|
||||
|
||||
set_property(
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@ struct UnloadToFinda {
|
|||
// FINDA is sensing the filament, plan moves to unload it
|
||||
int unloadSteps = /*BowdenLength::get() +*/ 1100; // @@TODO
|
||||
const int second_point = unloadSteps - 1300;
|
||||
mm::motion.PlanMove(mm::Pulley, -1400, 6000); // @@TODO constants
|
||||
mm::motion.PlanMove(mm::Pulley, -1800 + 1400, 2500); // @@TODO constants 1800-1400 = 400
|
||||
mm::motion.PlanMove(mm::Pulley, -second_point + 1800, 550); // @@TODO constants
|
||||
// mm::motion.PlanMove(mm::Pulley, -1400, 6000); // @@TODO constants
|
||||
// mm::motion.PlanMove(mm::Pulley, -1800 + 1400, 2500); // @@TODO constants 1800-1400 = 400
|
||||
// mm::motion.PlanMove(mm::Pulley, -second_point + 1800, 550); // @@TODO constants
|
||||
state = WaitingForFINDA;
|
||||
}
|
||||
}
|
||||
|
|
@ -117,17 +117,17 @@ class UnloadFilament : public TaskBase {
|
|||
namespace mm = modules::motion;
|
||||
switch (state) {
|
||||
case EngagingIdler: // state 1 engage idler
|
||||
if (mm::motion.IdlerEngaged()) { // if idler is in parked position un-park him get in contact with filament
|
||||
if (mm::motion.IdlerEngaged()) { // if idler is in parked position un-park it get in contact with filament
|
||||
state = UnloadingToFinda;
|
||||
unl.Reset();
|
||||
}
|
||||
return false;
|
||||
case UnloadingToFinda: // state 2 rotate pulley as long as the FINDA is on
|
||||
if (unl.Step()) {
|
||||
if (unl.state == UnloadToFinda2::Failed) {
|
||||
if (unl.state == UnloadToFinda::Failed) {
|
||||
// couldn't unload to FINDA, report error and wait for user to resolve it
|
||||
state = ERR1DisengagingIdler;
|
||||
modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::blink0);
|
||||
// modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::blink0);
|
||||
} else {
|
||||
state = DisengagingIdler;
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ class UnloadFilament : public TaskBase {
|
|||
case DisengagingIdler:
|
||||
if (mm::motion.IdlerDisengaged()) {
|
||||
state = AvoidingGrind;
|
||||
mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants
|
||||
// mm::motion.PlanMove(mm::Pulley, -100, 10); // @@TODO constants
|
||||
}
|
||||
return false;
|
||||
case AvoidingGrind: // state 3 move a little bit so it is not a grinded hole in filament
|
||||
|
|
@ -159,7 +159,7 @@ class UnloadFilament : public TaskBase {
|
|||
state = ERR1WaitingForUser;
|
||||
}
|
||||
return false;
|
||||
case ERR1WaitingForUser:
|
||||
case ERR1WaitingForUser: {
|
||||
// waiting for user buttons and/or a command from the printer
|
||||
bool help = modules::buttons::buttons.ButtonPressed(modules::buttons::Left) /*|| command_help()*/;
|
||||
bool tryAgain = modules::buttons::buttons.ButtonPressed(modules::buttons::Middle) /*|| command_tryAgain()*/;
|
||||
|
|
@ -172,14 +172,15 @@ class UnloadFilament : public TaskBase {
|
|||
Reset();
|
||||
} else if (userResolved) {
|
||||
// problem resolved - the user pulled the fillament by hand
|
||||
modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::off);
|
||||
modules::leds::leds.SetMode(active_extruder, modules::leds::green, modules::leds::on);
|
||||
mm::motion.PlanMove(mm::Pulley, 450, 5000); // @@TODO constants
|
||||
// modules::leds::leds.SetMode(active_extruder, modules::leds::red, modules::leds::off);
|
||||
// modules::leds::leds.SetMode(active_extruder, modules::leds::green, modules::leds::on);
|
||||
// mm::motion.PlanMove(mm::Pulley, 450, 5000); // @@TODO constants
|
||||
state = AvoidingGrind;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case OK:
|
||||
isFilamentLoaded = false; // filament unloaded
|
||||
// isFilamentLoaded = false; // filament unloaded
|
||||
return true; // successfully finished
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ void setup() {
|
|||
|
||||
cpu::Init();
|
||||
|
||||
// watchdog init
|
||||
|
||||
shr16::shr16.Init();
|
||||
modules::leds::leds.SetMode(4, modules::leds::Color::green, modules::leds::Mode::blink0);
|
||||
modules::leds::leds.Step(0);
|
||||
|
|
@ -249,6 +251,7 @@ void loop() {
|
|||
modules::leds::leds.Step(0);
|
||||
modules::finda::finda.Step();
|
||||
currentCommand->Step();
|
||||
// add a watchdog reset
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
namespace modules {
|
||||
namespace leds {
|
||||
|
||||
LEDs leds;
|
||||
|
||||
void LED::SetMode(Mode mode) {
|
||||
state.mode = mode;
|
||||
// set initial state of LEDs correctly - transition from one mode to another
|
||||
|
|
|
|||
|
|
@ -6,14 +6,18 @@ namespace motion {
|
|||
|
||||
Motion motion;
|
||||
|
||||
void Motion::PlanMove(Axis axis, float targetPosition, uint16_t feedrate) {}
|
||||
void Motion::PlanMove(uint16_t pulley, uint16_t idler, uint16_t selector, uint16_t feedrate, uint16_t starting_speed, uint16_t ending_speed) {}
|
||||
|
||||
void Motion::Home(Axis axis) {}
|
||||
void Motion::Home(Axis axis, bool direction) {}
|
||||
|
||||
void Motion::SetMode(MotorMode mode) {}
|
||||
|
||||
void Motion::Step() {}
|
||||
|
||||
bool Motion::IdlerDisengaged() const { return true; }
|
||||
|
||||
bool Motion::IdlerEngaged() const { return true; }
|
||||
|
||||
void ISR() {}
|
||||
|
||||
//@@TODO check the directions
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ public:
|
|||
static void StepPulley(uint8_t on);
|
||||
};
|
||||
|
||||
/// @@TODO this is subject of discussion and change in the future
|
||||
class Motion {
|
||||
public:
|
||||
/// Init axis driver
|
||||
|
|
@ -67,10 +68,12 @@ public:
|
|||
void DisableAxis(Axis axis) {}
|
||||
|
||||
/// Enqueue move of a specific motor/axis into planner buffer
|
||||
void PlanMove(Axis axis, float targetPosition, uint16_t feedrate);
|
||||
/// @param pulley, idler, selector - target coords
|
||||
void PlanMove(uint16_t pulley, uint16_t idler, uint16_t selector, uint16_t feedrate, uint16_t starting_speed, uint16_t ending_speed);
|
||||
|
||||
/// Enqueue performing of homing of an axis
|
||||
void Home(Axis axis);
|
||||
/// @@TODO
|
||||
void Home(Axis axis, bool direction);
|
||||
|
||||
/// Set mode of TMC/motors operation
|
||||
/// Common for all axes/motors
|
||||
|
|
@ -88,6 +91,9 @@ public:
|
|||
/// probably higher-level operations knowing the semantic meaning of axes
|
||||
void Idler(IdlerMode im) {}
|
||||
|
||||
bool IdlerDisengaged() const;
|
||||
bool IdlerEngaged() const;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue