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