Add DEBUG_LOGIC

pull/126/head
3d-gussner 2021-09-22 20:35:17 +02:00 committed by DRracer
parent b8259ac555
commit 15adeaa180
9 changed files with 168 additions and 34 deletions

View File

@ -5,6 +5,7 @@
/// Define Debug mode to add additional serial output /// Define Debug mode to add additional serial output
//#define DEBUG_FINDA //#define DEBUG_FINDA
//#define DEBUG_LOGIC
/// Wrangler for assorted compile-time configuration and constants. /// Wrangler for assorted compile-time configuration and constants.
namespace config { namespace config {

View File

@ -6,10 +6,18 @@
#include "../modules/leds.h" #include "../modules/leds.h"
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace logic { namespace logic {
void FeedToBondtech::Reset(uint8_t maxRetries) { void FeedToBondtech::Reset(uint8_t maxRetries) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("\nFeed to Bondtech\n\n");
#endif //DEBUG_LOGIC
state = EngagingIdler; state = EngagingIdler;
this->maxRetries = maxRetries; this->maxRetries = maxRetries;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::Color::green, ml::Mode::blink0); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::Color::green, ml::Mode::blink0);
@ -22,12 +30,21 @@ bool FeedToBondtech::Step() {
switch (state) { switch (state) {
case EngagingIdler: case EngagingIdler:
if (mi::idler.Engaged()) { if (mi::idler.Engaged()) {
#ifdef DEBUG_LOGIC
uint16_t startSteps = mm::motion.CurPosition(mm::Pulley);
char str[30];
sprintf_P(str, PSTR("\nPulley start steps %u\n\n"), startSteps);
hu::usart1.puts(str);
#endif //DEBUG_LOGIC
state = PushingFilament; state = PushingFilament;
mm::motion.PlanMove<mm::Pulley>(config::DefaultBowdenLength, config::pulleyFeedrate); //@@TODO constants - there was some strange acceleration sequence in the original FW, mm::motion.PlanMove<mm::Pulley>(config::DefaultBowdenLength, config::pulleyFeedrate); //@@TODO constants - there was some strange acceleration sequence in the original FW,
// we can probably hand over some array of constants for hand-tuned acceleration + leverage some smoothing in the stepper as well // we can probably hand over some array of constants for hand-tuned acceleration + leverage some smoothing in the stepper as well
} }
return false; return false;
case PushingFilament: case PushingFilament:
#ifdef DEBUG_LOGIC
hu::usart1.puts("\nFeed to Bondtech --> Pushing\n\n");
#endif //DEBUG_LOGIC
if (mfs::fsensor.Pressed()) { if (mfs::fsensor.Pressed()) {
mm::motion.AbortPlannedMoves(); // stop pushing filament mm::motion.AbortPlannedMoves(); // stop pushing filament
mi::idler.Disengage(); mi::idler.Disengage();
@ -40,13 +57,22 @@ bool FeedToBondtech::Step() {
} }
return false; return false;
case DisengagingIdler: case DisengagingIdler:
#ifdef DEBUG_LOGIC
hu::usart1.puts("\nFeed to Bondtech --> DisengagingIdler\n\n");
#endif //DEBUG_LOGIC
if (!mi::idler.Engaged()) { if (!mi::idler.Engaged()) {
state = OK; state = OK;
ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on); ml::leds.SetMode(mg::globals.ActiveSlot(), ml::green, ml::on);
} }
return false; return false;
case OK: case OK:
#ifdef DEBUG_LOGIC
hu::usart1.puts("\nFeed to Bondtech\n\n");
#endif //DEBUG_LOGIC
case Failed: case Failed:
#ifdef DEBUG_LOGIC
hu::usart1.puts("\nFeed to Bondtech FAILED\n\n");
#endif //DEBUG_LOGIC
default: default:
return true; return true;
} }

View File

@ -7,6 +7,11 @@
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/selector.h" #include "../modules/selector.h"
#include "../modules/user_input.h" #include "../modules/user_input.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace logic { namespace logic {
@ -16,7 +21,9 @@ void LoadFilament::Reset(uint8_t param) {
if (!CheckToolIndex(param)) { if (!CheckToolIndex(param)) {
return; return;
} }
#ifdef DEBUG_LOGIC
hu::usart1.puts("Load Filament\n\n");
#endif //DEBUG_LOGIC
state = ProgressCode::EngagingIdler; state = ProgressCode::EngagingIdler;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
mg::globals.SetActiveSlot(param); mg::globals.SetActiveSlot(param);

View File

@ -8,29 +8,29 @@
enum class ProgressCode : uint_fast8_t { enum class ProgressCode : uint_fast8_t {
OK = 0, ///< finished ok OK = 0, ///< finished ok
EngagingIdler, EngagingIdler, // P1
DisengagingIdler, DisengagingIdler, // P2
UnloadingToFinda, UnloadingToFinda, // P3
UnloadingToPulley, UnloadingToPulley, //P4
FeedingToFinda, FeedingToFinda, // P5
FeedingToBondtech, FeedingToBondtech, // P6
AvoidingGrind, AvoidingGrind, // P7
FinishingMoves, FinishingMoves, // P8
ERRDisengagingIdler, ERRDisengagingIdler, // P9
ERREngagingIdler, ERREngagingIdler, // P10
ERRWaitingForUser, ERRWaitingForUser, // P11
ERRInternal, ERRInternal, // P12
ERRHelpingFilament, ERRHelpingFilament, // P13
ERRTMCFailed, ERRTMCFailed, // P14
UnloadingFilament, UnloadingFilament, // P15
LoadingFilament, LoadingFilament, // P16
SelectingFilamentSlot, SelectingFilamentSlot, // P17
PreparingBlade, PreparingBlade, // P18
PushingFilament, PushingFilament, // P19
PerformingCut, PerformingCut, // P20
ReturningSelector, ReturningSelector, // P21
ParkingSelector, ParkingSelector, // P22
EjectingFilament, EjectingFilament, // P23
}; };

View File

@ -7,6 +7,11 @@
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/selector.h" #include "../modules/selector.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace logic { namespace logic {
@ -19,6 +24,9 @@ void ToolChange::Reset(uint8_t param) {
if (param == mg::globals.ActiveSlot() && mg::globals.FilamentLoaded()) { if (param == mg::globals.ActiveSlot() && mg::globals.FilamentLoaded()) {
// we are already at the correct slot and the filament is loaded - nothing to do // we are already at the correct slot and the filament is loaded - nothing to do
#ifdef DEBUG_LOGIC
hu::usart1.puts("we are already at the correct slot and the filament is loaded - nothing to do\n");
#endif //DEBUG_LOGIC
return; return;
} }
@ -27,10 +35,16 @@ void ToolChange::Reset(uint8_t param) {
plannedSlot = param; plannedSlot = param;
if (mg::globals.FilamentLoaded()) { if (mg::globals.FilamentLoaded()) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Filament is loaded --> unload\n");
#endif //DEBUG_LOGIC
state = ProgressCode::UnloadingFilament; state = ProgressCode::UnloadingFilament;
unl.Reset(mg::globals.ActiveSlot()); unl.Reset(mg::globals.ActiveSlot());
} else { } else {
state = ProgressCode::LoadingFilament; state = ProgressCode::LoadingFilament;
#ifdef DEBUG_LOGIC
hu::usart1.puts("Filament is not loaded --> load\n");
#endif //DEBUG_LOGIC
load.Reset(plannedSlot); load.Reset(plannedSlot);
} }
} }

View File

@ -6,6 +6,11 @@
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/permanent_storage.h" #include "../modules/permanent_storage.h"
#include "../modules/user_input.h" #include "../modules/user_input.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace logic { namespace logic {

View File

@ -3,6 +3,11 @@
#include "leds.h" #include "leds.h"
#include "motion.h" #include "motion.h"
#include "permanent_storage.h" #include "permanent_storage.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace modules { namespace modules {
namespace idler { namespace idler {
@ -11,34 +16,56 @@ Idler idler;
void Idler::PrepareMoveToPlannedSlot() { void Idler::PrepareMoveToPlannedSlot() {
mm::motion.PlanMoveTo<mm::Idler>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate)); mm::motion.PlanMoveTo<mm::Idler>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate));
#ifdef DEBUG_LOGIC
char str[30];
sprintf_P(str, PSTR("Prepare Move Idler slot %d\n"), plannedSlot);
hu::usart1.puts(str);
#endif //DEBUG_LOGIC
} }
void Idler::PlanHomingMove() { void Idler::PlanHomingMove() {
mm::motion.PlanMove<mm::Idler>(mm::unitToAxisUnit<mm::I_pos_t>(-config::idlerLimits.lenght * 2), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate)); mm::motion.PlanMove<mm::Idler>(mm::unitToAxisUnit<mm::I_pos_t>(-config::idlerLimits.lenght * 2), mm::unitToAxisUnit<mm::I_speed_t>(config::idlerFeedrate));
#ifdef DEBUG_LOGIC
hu::usart1.puts("Plan Homing Idler\n");
#endif //DEBUG_LOGIC
} }
Idler::OperationResult Idler::Disengage() { Idler::OperationResult Idler::Disengage() {
if (state == Moving) if (state == Moving) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Moving --> Disengage refused\n");
#endif //DEBUG_LOGIC
return OperationResult::Refused; return OperationResult::Refused;
}
plannedSlot = IdleSlotIndex(); plannedSlot = IdleSlotIndex();
plannedEngage = false; plannedEngage = false;
if (!Engaged()) if (!Engaged()) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Disengage Idler\n");
#endif //DEBUG_LOGIC
return OperationResult::Accepted; return OperationResult::Accepted;
}
return InitMovement(mm::Idler); return InitMovement(mm::Idler);
} }
Idler::OperationResult Idler::Engage(uint8_t slot) { Idler::OperationResult Idler::Engage(uint8_t slot) {
if (state == Moving) if (state == Moving){
#ifdef DEBUG_LOGIC
hu::usart1.puts("Moving --> Engage refused\n");
#endif //DEBUG_LOGIC
return OperationResult::Refused; return OperationResult::Refused;
}
plannedSlot = slot; plannedSlot = slot;
plannedEngage = true; plannedEngage = true;
if (Engaged()) if (Engaged()) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Engage Idler\n");
#endif //DEBUG_LOGIC
return OperationResult::Accepted; return OperationResult::Accepted;
}
return InitMovement(mm::Idler); return InitMovement(mm::Idler);
} }
@ -54,12 +81,21 @@ bool Idler::Home() {
bool Idler::Step() { bool Idler::Step() {
switch (state) { switch (state) {
case Moving: case Moving:
#ifdef DEBUG_LOGIC
//hu::usart1.puts("Moving Idler\n");
#endif //DEBUG_LOGIC
PerformMove(mm::Idler); PerformMove(mm::Idler);
return false; return false;
case Homing: case Homing:
#ifdef DEBUG_LOGIC
hu::usart1.puts("Homing Idler\n");
#endif //DEBUG_LOGIC
PerformHome(mm::Idler); PerformHome(mm::Idler);
return false; return false;
case Ready: case Ready:
#ifdef DEBUG_LOGIC
//hu::usart1.puts("Idler Ready\n");
#endif //DEBUG_LOGIC
currentlyEngaged = plannedEngage; currentlyEngaged = plannedEngage;
currentSlot = plannedSlot; currentSlot = plannedSlot;
@ -68,6 +104,9 @@ bool Idler::Step() {
return true; return true;
case Failed: case Failed:
#ifdef DEBUG_LOGIC
hu::usart1.puts("Idler Failed\n");
#endif //DEBUG_LOGIC
default: default:
return true; return true;
} }

View File

@ -1,5 +1,10 @@
#include "motion.h" #include "motion.h"
#include "../panic.h" #include "../panic.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
// TODO: use proper timer abstraction // TODO: use proper timer abstraction
#ifdef __AVR__ #ifdef __AVR__
@ -45,6 +50,12 @@ void Motion::StallGuardReset(Axis axis) {
} }
void Motion::PlanMoveTo(Axis axis, pos_t pos, steps_t feed_rate, steps_t end_rate) { void Motion::PlanMoveTo(Axis axis, pos_t pos, steps_t feed_rate, steps_t end_rate) {
#ifdef DEBUG_LOGIC
char str[30];
sprintf_P(str, PSTR("Move axis %d to %u\n"), axis, pos);
hu::usart1.puts(str);
#endif //DEBUG_LOGIC
if (axisData[axis].ctrl.PlanMoveTo(pos, feed_rate, end_rate)) { if (axisData[axis].ctrl.PlanMoveTo(pos, feed_rate, end_rate)) {
// move was queued, prepare the axis // move was queued, prepare the axis
if (!axisData[axis].enabled) if (!axisData[axis].enabled)

View File

@ -3,6 +3,11 @@
#include "leds.h" #include "leds.h"
#include "motion.h" #include "motion.h"
#include "permanent_storage.h" #include "permanent_storage.h"
#ifdef DEBUG_LOGIC
#include "../hal/usart.h"
#include <string.h>
#include <stdio.h>
#endif //DEBUG_LOGIC
namespace modules { namespace modules {
namespace selector { namespace selector {
@ -11,21 +16,35 @@ Selector selector;
void Selector::PrepareMoveToPlannedSlot() { void Selector::PrepareMoveToPlannedSlot() {
mm::motion.PlanMoveTo<mm::Selector>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate)); mm::motion.PlanMoveTo<mm::Selector>(SlotPosition(plannedSlot), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate));
#ifdef DEBUG_LOGIC
char str[30];
sprintf_P(str, PSTR("Prepare Move Selector slot %d\n"), plannedSlot);
hu::usart1.puts(str);
#endif //DEBUG_LOGIC
} }
void Selector::PlanHomingMove() { void Selector::PlanHomingMove() {
mm::motion.PlanMove<mm::Selector>(mm::unitToAxisUnit<mm::S_pos_t>(config::selectorLimits.lenght * 2), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate)); mm::motion.PlanMove<mm::Selector>(mm::unitToAxisUnit<mm::S_pos_t>(config::selectorLimits.lenght * 2), mm::unitToAxisUnit<mm::S_speed_t>(config::selectorFeedrate));
#ifdef DEBUG_LOGIC
hu::usart1.puts("Plan Homing Selector\n");
#endif //DEBUG_LOGIC
} }
Selector::OperationResult Selector::MoveToSlot(uint8_t slot) { Selector::OperationResult Selector::MoveToSlot(uint8_t slot) {
if (state == Moving) if (state == Moving) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Moving --> Selector refused\n");
#endif //DEBUG_LOGIC
return OperationResult::Refused; return OperationResult::Refused;
}
plannedSlot = slot; plannedSlot = slot;
if (currentSlot == slot) if (currentSlot == slot) {
#ifdef DEBUG_LOGIC
hu::usart1.puts("Moving Selector\n");
#endif //DEBUG_LOGIC
return OperationResult::Accepted; return OperationResult::Accepted;
}
return InitMovement(mm::Selector); return InitMovement(mm::Selector);
} }
@ -40,15 +59,27 @@ bool Selector::Step() {
switch (state) { switch (state) {
case Moving: case Moving:
PerformMove(mm::Selector); PerformMove(mm::Selector);
#ifdef DEBUG_LOGIC
//hu::usart1.puts("Moving Selector\n");
#endif //DEBUG_LOGIC
return false; return false;
case Homing: case Homing:
#ifdef DEBUG_LOGIC
hu::usart1.puts("Homing Selector\n");
#endif //DEBUG_LOGIC
PerformHome(mm::Selector); PerformHome(mm::Selector);
return false; return false;
case Ready: case Ready:
#ifdef DEBUG_LOGIC
//hu::usart1.puts("Selector Ready\n");
#endif //DEBUG_LOGIC
currentSlot = plannedSlot; currentSlot = plannedSlot;
mm::motion.Disable(mm::Selector); // turn off selector motor's power every time mm::motion.Disable(mm::Selector); // turn off selector motor's power every time
return true; return true;
case Failed: case Failed:
#ifdef DEBUG_LOGIC
hu::usart1.puts("Selector Failed\n");
#endif //DEBUG_LOGIC
default: default:
return true; return true;
} }