From 5363980d9f0bc73ae8ca6510431d003a7ecf69ad Mon Sep 17 00:00:00 2001 From: Alden Hart Date: Mon, 20 Feb 2017 10:50:34 -0500 Subject: [PATCH] =?UTF-8?q?Fixed=20some=20naming=20on=20the=20debug=20trap?= =?UTF-8?q?s;=20changed=20detection=20threshold=20for=20=E2=80=9Czero=20le?= =?UTF-8?q?ngth=20moves=E2=80=9D=20from=201/100=20micron=20to=201/10th=20m?= =?UTF-8?q?icron?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- g2core/alarm.cpp | 2 +- g2core/g2core.cppproj | 4 ++-- g2core/plan_exec.cpp | 27 +++++++++++++-------------- g2core/plan_line.cpp | 4 ++-- g2core/plan_zoid.cpp | 6 +++--- g2core/util.h | 14 +++++++------- g2core/xio.cpp | 10 +++++----- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/g2core/alarm.cpp b/g2core/alarm.cpp index 5b3c0856..e2da88a4 100644 --- a/g2core/alarm.cpp +++ b/g2core/alarm.cpp @@ -230,7 +230,7 @@ stat_t cm_shutdown(const stat_t status, const char *msg) stat_t cm_panic(const stat_t status, const char *msg) { - __debug_trap(msg); + debug_trap(msg); if (cm->machine_state == MACHINE_PANIC) { // only do this once return (STAT_OK); diff --git a/g2core/g2core.cppproj b/g2core/g2core.cppproj index b67c56bb..fd10f7b0 100644 --- a/g2core/g2core.cppproj +++ b/g2core/g2core.cppproj @@ -73,7 +73,7 @@ SWD com.atmel.avrdbg.tool.atmelice - J41800036434 + J41800030015 Atmel-ICE True @@ -100,7 +100,7 @@ True true - J41800036434 + J41800030015 0x284E0A60 10000000 diff --git a/g2core/plan_exec.cpp b/g2core/plan_exec.cpp index a2a53804..ca52d61a 100644 --- a/g2core/plan_exec.cpp +++ b/g2core/plan_exec.cpp @@ -166,10 +166,10 @@ static stat_t _plan_aline(mpBuf_t *bf, float entry_velocity) mpBlockRuntimeBuf_t* block = mr->p; // set a local planning block so it doesn't change on you mp_calculate_ramps(block, bf, entry_velocity); // (which it will if you don't do this) - __debug_trap_if_true((block->exit_velocity > block->cruise_velocity), + debug_trap_if_true((block->exit_velocity > block->cruise_velocity), "_plan_line() exit velocity > cruise velocity after calculate_ramps()"); - __debug_trap_if_true((block->head_length < 0.00001 && block->body_length < 0.00001 && block->tail_length < 0.00001), + debug_trap_if_true((block->head_length < 0.00001 && block->body_length < 0.00001 && block->tail_length < 0.00001), "_plan_line() zero or negative length block after calculate_ramps()"); bf->buffer_state = MP_BUFFER_PLANNED; //...here @@ -256,28 +256,28 @@ stat_t mp_exec_move() // first-time operations if (bf->buffer_state != MP_BUFFER_RUNNING) { if ((bf->buffer_state < MP_BUFFER_PREPPED) && (cm->motion_state == MOTION_RUN)) { - __debug_trap("mp_exec_move() buffer is not prepped"); // IMPORTANT: can't rpt_exception from here! + debug_trap("mp_exec_move() buffer is not prepped. Starvation"); // IMPORTANT: can't rpt_exception from here! st_prep_null(); return (STAT_NOOP); } - if (bf->nx->buffer_state < MP_BUFFER_PREPPED) { + if ((bf->nx->buffer_state < MP_BUFFER_PREPPED) && (bf->nx->buffer_state > MP_BUFFER_EMPTY)) { // This detects buffer starvation, but also can be a single-line "jog" or command // rpt_exception(42, "mp_exec_move() next buffer is empty"); // ^^^ CAUSES A CRASH. We can't rpt_exception from here! + debug_trap("mp_exec_move() no buffer prepped - starvation"); } if (bf->buffer_state == MP_BUFFER_PREPPED) { - if (cm->motion_state == MOTION_RUN) { - __debug_trap("mp_exec_move() don't have a block planned"); // IMPORTANT: can't rpt_exception from here! - } - // We need to have it planned. We don't want to do this here, as it - // might already be happening in a lower interrupt. + debug_trap_if_true((cm->motion_state == MOTION_RUN), "mp_exec_move() buffer prepped but not planned"); + // IMPORTANT: can't rpt_exception from here! + // We need to have it planned. We don't want to do this here, + // as it might already be happening in a lower interrupt. st_request_forward_plan(); return (STAT_NOOP); } if (bf->buffer_state == MP_BUFFER_PLANNED) { - bf->buffer_state = MP_BUFFER_RUNNING; // must precede mp_planner_time_acccounting() + bf->buffer_state = MP_BUFFER_RUNNING; // must precede mp_planner_time_acccounting() } else { return (STAT_NOOP); } @@ -289,7 +289,6 @@ stat_t mp_exec_move() // (and have called mp_exec_aline via bf->bf_func). // This also allows mp_exec_aline to advance mr->p first. if (bf->nx->buffer_state >= MP_BUFFER_PREPPED) { -// if (bf->nx->buffer_state == MP_BUFFER_PREPPED) { st_request_forward_plan(); } @@ -877,7 +876,7 @@ static stat_t _exec_aline_head(mpBuf_t *bf) _init_forward_diffs(mr->entry_velocity, mr->r->cruise_velocity); // <-- sets inital segment_velocity } if (mr->segment_time < MIN_SEGMENT_TIME) { - __debug_trap("mr->segment_time < MIN_SEGMENT_TIME (head)"); + debug_trap("mr->segment_time < MIN_SEGMENT_TIME (head)"); return(STAT_OK); // exit without advancing position, say we're done } mr->section = SECTION_HEAD; @@ -922,7 +921,7 @@ static stat_t _exec_aline_body(mpBuf_t *bf) mr->segment_velocity = mr->r->cruise_velocity; mr->segment_count = (uint32_t)mr->segments; if (mr->segment_time < MIN_SEGMENT_TIME) { - __debug_trap("mr->segment_time < MIN_SEGMENT_TIME (body)"); + debug_trap("mr->segment_time < MIN_SEGMENT_TIME (body)"); return(STAT_OK); // exit without advancing position, say we're done } @@ -963,7 +962,7 @@ static stat_t _exec_aline_tail(mpBuf_t *bf) _init_forward_diffs(mr->r->cruise_velocity, mr->r->exit_velocity); // <-- sets inital segment_velocity } if (mr->segment_time < MIN_SEGMENT_TIME) { - __debug_trap("mr->segment_time < MIN_SEGMENT_TIME (tail)"); + debug_trap("mr->segment_time < MIN_SEGMENT_TIME (tail)"); return(STAT_OK); // exit without advancing position, say we're done // return(STAT_MINIMUM_TIME_MOVE); // exit without advancing position } diff --git a/g2core/plan_line.cpp b/g2core/plan_line.cpp index c9e3ca32..40deeef0 100644 --- a/g2core/plan_line.cpp +++ b/g2core/plan_line.cpp @@ -200,8 +200,8 @@ stat_t mp_aline(GCodeState_t* gm_in) length = sqrt(length_square); // exit if the move has zero movement. At all. -// if (fp_ZERO(length)) { - if (length < 0.00002) { // this value is 2x EPSILON and prevents trap failures in _plan_aline() +// if (length < 0.00002) { // this value is 2x EPSILON and prevents trap failures in _plan_aline() + if (length < 0.0001) { // this value is 0.1 microns. Prevents planner trap failures sr_request_status_report(SR_REQUEST_TIMED_FULL); // Was SR_REQUEST_IMMEDIATE_FULL return (STAT_MINIMUM_LENGTH_MOVE); // STAT_MINIMUM_LENGTH_MOVE needed to end cycle } diff --git a/g2core/plan_zoid.cpp b/g2core/plan_zoid.cpp index a91562cf..bbff69e0 100644 --- a/g2core/plan_zoid.cpp +++ b/g2core/plan_zoid.cpp @@ -125,8 +125,8 @@ stat_t mp_calculate_ramps(mpBlockRuntimeBuf_t* block, mpBuf_t* bf, const float e bf->hint = COMMAND_BLOCK; return (STAT_NOOP); // NOOP status is informative, not actionable } - __debug_trap_if_zero(bf->length, "mp_calculate_ramps() - got L=0"); - __debug_trap_if_zero(bf->cruise_velocity, "mp_calculate_ramps() - got Vc=0"); + debug_trap_if_zero(bf->length, "mp_calculate_ramps() - got L=0"); + debug_trap_if_zero(bf->cruise_velocity, "mp_calculate_ramps() - got Vc=0"); // Timings from *here* @@ -303,7 +303,7 @@ stat_t mp_calculate_ramps(mpBlockRuntimeBuf_t* block, mpBuf_t* bf, const float e // Rate-limited asymmetric cases (3) // compute meet velocity to see if the cruise velocity rises above the entry and/or exit velocities block->cruise_velocity = _get_meet_velocity(entry_velocity, block->exit_velocity, bf->length, bf, block); - __debug_trap_if_zero(block->cruise_velocity, "mp_calculate_ramps() Vc=0 asymmetric HT case"); + debug_trap_if_zero(block->cruise_velocity, "mp_calculate_ramps() Vc=0 asymmetric HT case"); // We now store the head/tail lengths we computed in _get_meet_velocity. // treat as a full up and down (head and tail) diff --git a/g2core/util.h b/g2core/util.h index 1c4913e7..d5d5aa9b 100644 --- a/g2core/util.h +++ b/g2core/util.h @@ -190,28 +190,28 @@ inline T avg(const T a,const T b) {return (a+b)/2; } */ /* - * _debug_trap() - trap unconditionally - * _debug_trap_if_zero() - trap if floating point value is zero - * _debug_trap_if_true() - trap if condition is true + * debug_trap() - trap unconditionally + * debug_trap_if_zero() - trap if floating point value is zero + * debug_trap_if_true() - trap if condition is true * * The 'reason' value will display in GDB (but maybe not in AS7), and can also be passed * to a downstream logger if these are introduced into the function. * - * Note that it may be possible to print or generate exceptions in _debug_trap(), but + * Note that it may be possible to print or generate exceptions in debug_trap(), but * it MIGHT interrupt other output, or might have been called deep in an ISR, * so we had better just _NOP() and hope for the best. */ #pragma GCC push_options #pragma GCC optimize ("O0") -inline void __debug_trap(const char *reason) { +inline void debug_trap(const char *reason) { __NOP(); #if IN_DEBUGGER == 1 __asm__("BKPT"); #endif } -inline void __debug_trap_if_zero(float value, const char *reason) { +inline void debug_trap_if_zero(float value, const char *reason) { if (fp_ZERO(value)) { __NOP(); #if IN_DEBUGGER == 1 @@ -220,7 +220,7 @@ inline void __debug_trap_if_zero(float value, const char *reason) { } } -inline void __debug_trap_if_true(bool condition, const char *reason) { +inline void debug_trap_if_true(bool condition, const char *reason) { if (condition) { __NOP(); #if IN_DEBUGGER == 1 diff --git a/g2core/xio.cpp b/g2core/xio.cpp index d67fc25d..3993150e 100644 --- a/g2core/xio.cpp +++ b/g2core/xio.cpp @@ -600,7 +600,7 @@ struct LineRXBuffer : RXBuffer<_size, owner_type, char> { char c = _data[_scan_offset]; if (c == 0) { - __debug_trap("_scanBuffer() scan ran into NULL"); + debug_trap("_scanBuffer() scan ran into NULL"); flush(); // consider the connection and all data trashed return false; } @@ -747,14 +747,14 @@ struct LineRXBuffer : RXBuffer<_size, owner_type, char> { // Either way, _scan_offset is one past the end, so we don't care which. if (_data[_line_start_offset] == 0) { - __debug_trap("readline() read ran into NULL"); + debug_trap("readline() read ran into NULL"); } // scan past any leftover CR or LF from the previous line while ((_data[_line_start_offset] == '\n') || (_data[_line_start_offset] == '\r')) { _line_start_offset = (_line_start_offset+1)&(_size-1); if (_scan_offset == _line_start_offset) { - __debug_trap("readline() read ran into scan (1)"); + debug_trap("readline() read ran into scan (1)"); } } @@ -802,7 +802,7 @@ struct LineRXBuffer : RXBuffer<_size, owner_type, char> { if (_data[_read_offset] == 0) { - __debug_trap("readline() read ran into NULL"); + debug_trap("readline() read ran into NULL"); } // scan past any leftover CR or LF from the previous line @@ -810,7 +810,7 @@ struct LineRXBuffer : RXBuffer<_size, owner_type, char> { while ((c == '\n') || (c == '\r')) { _read_offset = (_read_offset+1)&(_size-1); if (_scan_offset == _read_offset) { - __debug_trap("readline() read ran into scan (2)"); + debug_trap("readline() read ran into scan (2)"); } // this also counts as the beginning of a line _skip_sections.skip(_read_offset);