mirror of
https://github.com/synthetos/g2.git
synced 2026-02-06 11:11:57 +08:00
Updated planner state names; edited planner diagnostics
This commit is contained in:
@@ -73,7 +73,7 @@
|
||||
<InterfaceName>SWD</InterfaceName>
|
||||
</ToolOptions>
|
||||
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||
<ToolNumber>J41800036434</ToolNumber>
|
||||
<ToolNumber>J41800019454</ToolNumber>
|
||||
<ToolName>Atmel-ICE</ToolName>
|
||||
</com_atmel_avrdbg_tool_atmelice>
|
||||
<UseGdb>True</UseGdb>
|
||||
@@ -100,7 +100,7 @@
|
||||
<HWProgramCounterSampling>True</HWProgramCounterSampling>
|
||||
</PercepioTrace>
|
||||
<preserveEEPROM>true</preserveEEPROM>
|
||||
<avrtoolserialnumber>J41800036434</avrtoolserialnumber>
|
||||
<avrtoolserialnumber>J41800019454</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x284E0A60</avrdeviceexpectedsignature>
|
||||
<avrtoolinterfaceclock>10000000</avrtoolinterfaceclock>
|
||||
<custom>
|
||||
|
||||
@@ -48,25 +48,25 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf);
|
||||
|
||||
static void _init_forward_diffs(float v_0, float v_1);
|
||||
|
||||
/*******************************************************************************
|
||||
/****************************************************************************************
|
||||
* mp_forward_plan() - plan commands and moves ahead of exec; call ramping for moves
|
||||
*
|
||||
**** WARNING ****
|
||||
* This function should NOT be called directly!
|
||||
* Instead call st_request_forward_plan(), which mediates access.
|
||||
* mp_forward_plan() should NOT be called directly!
|
||||
* Instead call st_request_forward_plan(), which mediates access.
|
||||
*
|
||||
* mp_forward_plan() performs just-in-time forward planning immediately before
|
||||
* lines and commands are queued to the move execution runtime (exec).
|
||||
* Unlike backward planning, buffers are only forward planned once.
|
||||
* moves and commands are queued to the move execution runtime (exec).
|
||||
* Unlike back planning, buffers are only forward planned once.
|
||||
*
|
||||
* mp_forward_plan() is called aggressively via st_request_forward_plan().
|
||||
* It has a relatively low interrupt level to call its own.
|
||||
* See also: Planner Overview notes in planner.h
|
||||
* See also: Planner Background and Overview notes in planner.h
|
||||
*
|
||||
* It examines the currently running buffer and its adjacent buffers to:
|
||||
* - Stop the system from re-planning or planning something that's not prepped
|
||||
* - Plan the next available ALINE (movement) block past the COMMAND blocks
|
||||
* - Skip past/ or pre-plan COMMAND blocks while labeling them as PLANNED
|
||||
* - Skip past/ or pre-plan COMMAND blocks while labeling them as FULLY_PLANNED
|
||||
*
|
||||
* Returns:
|
||||
* - STAT_OK if exec should be called to kickstart (or continue) movement
|
||||
@@ -86,68 +86,73 @@ static void _init_forward_diffs(float v_0, float v_1);
|
||||
*
|
||||
* See planner.h / bufferState enum for shorthand used in the descriptions.
|
||||
* All cases assume a mix of moves and commands, as noted in the shorthand.
|
||||
* All cases assume 2 'blocks' - Run block & Plan block. Cases will need to be
|
||||
* revisited and generalized if more blocks are used in the future (deeper
|
||||
* forward planning).
|
||||
* All cases assume 2 'blocks' - Run block (r) & Plan block (p). These cases
|
||||
* will need to be revisited and generalized if more blocks are used in the future
|
||||
* (i.e. deeper forward planning).
|
||||
*
|
||||
* 'NOT_PREPPED' refers to any preliminary state below PREPPED, i.e. < PREPPED.
|
||||
* ' NOT_PREPPED' can be either a move or command, we don't care so it's not specified.
|
||||
* 'NOT_PLANNED' means the block has not been back planned or forward planned
|
||||
* This refers to any state below BACK_PLANNED, i.e. < MP_BUFFER_BACK_PLANNED
|
||||
* 'NOT_PLANNED' can be either a move or command, we don't care so it's not specified.
|
||||
*
|
||||
* 'BACK_PLANNED' means the block has been back planned but not forward planned
|
||||
* 'FULLY_PLANNED' means the block is back planned and forward planned, is ready for execution
|
||||
* 'RUNNING' means the move is executing in the runtime. The bf is "locked" during this phase
|
||||
*
|
||||
* 'COMMAND' or 'COMMAND(s)' refers to one command or a contiguous group of command buffers
|
||||
* that may be in PREPPED or PLANNED states. Processing is always the same. Plan all
|
||||
* PREPPED commands and skip past all PLANNED commands.
|
||||
* that may be in BACK_PLANNED or FULLY_PLANNED states. Processing is always the same;
|
||||
* plan all BACK_PLANNED commands and skip past all FULLY_PLANNED commands.
|
||||
*
|
||||
* Note 1: For MOVEs use the exit velocity of the Run block (mr->r->exit_velocity) as the
|
||||
* entry velocity of the next adjacent move.
|
||||
* Note 1: For MOVEs use the exit velocity of the Run block (mr->r->exit_velocity)
|
||||
* as the entry velocity of the next adjacent move.
|
||||
*
|
||||
* Note 1a: In this special COMMAND case we trust mr->r->exit_velocity because the
|
||||
* backplanner has already handled this case for us.
|
||||
* Note 1a: In this special COMMAND case we trust mr->r->exit_velocity because the
|
||||
* back planner has already handled this case for us.
|
||||
*
|
||||
* Note 2: For COMMANDs use the entry velocity of the current runtime (mr->entry_velocity)
|
||||
* as the entry velocity for the next adjacent move. mr->entry_velocity is almost always 0,
|
||||
* but could be non-0 in a race condition.
|
||||
* FYI: mr->entry_velocity is set at the end of the last running block in mp_exec_aline().
|
||||
*
|
||||
*
|
||||
* CASE:
|
||||
* 0. Nothing to do
|
||||
* 0. Nothing to do
|
||||
*
|
||||
* run_buffer
|
||||
* ----------
|
||||
* a. <no buffer> Run buffer has not yet been initialized (prep null buffer and return NOOP)
|
||||
* b. NOT_PREPPED No moves or commands in run buffer. Exit with no action
|
||||
* run_buffer
|
||||
* ----------
|
||||
* a. <no buffer> Run buffer has not yet been initialized (prep null buffer and return NOOP)
|
||||
* b. NOT_BACK_PLANNED No moves or commands in run buffer. Exit with no action
|
||||
*
|
||||
* 1. Bootstrap cases (buffer state < RUNNING)
|
||||
* 1. Bootstrap cases (buffer state < RUNNING)
|
||||
*
|
||||
* run_buffer next N bufs terminal buf Actions
|
||||
* ---------- ----------- ------------ ----------------------------------
|
||||
* a. PREPPED-MOVE <don't care> <don't care> plan move, exit OK
|
||||
* b. PLANNED-MOVE NOT_PREPPED <don't care> exit NOOP
|
||||
* c. PLANNED-MOVE PREPPED-MOVE <don't care> exit NOOP (don't plan past a PLANNED buffer)
|
||||
* d. PLANNED-MOVE PLANNED-MOVE <don't care> trap illegal condition, exit NOOP
|
||||
* e. PLANNED-MOVE COMMAND(s) <don't care> exit NOOP
|
||||
* f. PREPPED-COMMAND NOT_PREPPED <don't care> plan command, exit OK
|
||||
* g. PREPPED-COMMAND PREPPED-MOVE <don't care> plan command, plan move (Note 2), exit OK
|
||||
* h. PREPPED-COMMAND PLANNED-MOVE <don't care> trap illegal condition, exit NOOP
|
||||
* i. PLANNED-COMMAND NOT_PREPPED <don't care> skip command, exit OK
|
||||
* j. PLANNED-COMMAND PREPPED-MOVE <don't care> skip command, plan move (Note 2), exit OK
|
||||
* k. PLANNED-COMMAND PLANNED-MOVE <don't care> exit NOOP
|
||||
* run_buffer next N bufs terminal buf Actions
|
||||
* ---------- ----------- ------------ ----------------------------------
|
||||
* a. BACK_PLANNED/MOVE <don't care> <don't care> plan move, exit OK
|
||||
* b. FULLY_PLANNED/MOVE NOT_PLANNED <don't care> exit NOOP
|
||||
* c. FULLY_PLANNED/MOVE BACK_PLANNED/MOVE <don't care> exit NOOP (don't plan past a PLANNED buffer)
|
||||
* d. FULLY_PLANNED/MOVE FULLY_PLANNED/MOVE <don't care> trap illegal condition, exit NOOP
|
||||
* e. FULLY_PLANNED/MOVE COMMAND(s) <don't care> exit NOOP
|
||||
* f. BACK_PLANNED/COMMAND NOT_PREPPED <don't care> plan command, exit OK
|
||||
* g. BACK_PLANNED/COMMAND BACK_PLANNED/MOVE <don't care> plan command, plan move (Note 2), exit OK
|
||||
* h. BACK_PLANNED/COMMAND FULLY_PLANNED/MOVE <don't care> trap illegal condition, exit NOOP
|
||||
* i. BACK_PLANNED/COMMAND NOT_PLANNED <don't care> skip command, exit OK
|
||||
* j. BACK_PLANNED/COMMAND BACK_PLANNED/MOVE <don't care> skip command, plan move (Note 2), exit OK
|
||||
* k. BACK_PLANNED/COMMAND FULLY_PLANNED/MOVE <don't care> exit NOOP
|
||||
*
|
||||
* 2. Running cases (buffer state == RUNNING)
|
||||
* 2. Running cases (buffer state == RUNNING)
|
||||
*
|
||||
* run_buffer next N bufs terminal buf Actions
|
||||
* ---------- ----------- ------------ ----------------------------------
|
||||
* a. RUNNING-MOVE PREPPED-MOVE <don't care> plan move, exit OK
|
||||
* b. RUNNING-MOVE PLANNED-MOVE <don't care> exit NOOP
|
||||
* c. RUNNING-MOVE COMMAND(s) NOT_PREPPED skip/plan command(s), exit OK
|
||||
* d. RUNNING-MOVE COMMAND(s) PREPPED-MOVE skip/plan command(s), plan move, exit OK
|
||||
* e. RUNNING-MOVE COMMAND(s) PLANNED-MOVE exit NOOP
|
||||
* f. RUNNING-COMMAND PREPPED-MOVE <don't care> plan move, exit OK
|
||||
* g. RUNNING-COMMAND PLANNED-MOVE <don't care> exit NOOP
|
||||
* h. RUNNING-COMMAND COMMAND(s) NOT_PREPPED skip/plan command(s), exit OK
|
||||
* i. RUNNING-COMMAND COMMAND(s) PREPPED-MOVE skip/plan command(s), plan move (Note 1a), exit OK
|
||||
* j. RUNNING-COMMAND COMMAND(s) PLANNED-MOVE skip command(s), exit NOOP
|
||||
* (Note: all COMMAND(s) in j. should be in PLANNED state)
|
||||
* run_buffer next N bufs terminal buf Actions
|
||||
* ---------- ----------- ------------ ----------------------------------
|
||||
* a. RUNNING/MOVE BACK_PLANNED/MOVE <don't care> plan move, exit OK
|
||||
* b. RUNNING/MOVE FULLY_PLANNED/MOVE <don't care> exit NOOP
|
||||
* c. RUNNING/MOVE COMMAND(s) NOT_PLANNED skip/plan command(s), exit OK
|
||||
* d. RUNNING/MOVE COMMAND(s) BACK_PLANNED/MOVE skip/plan command(s), plan move, exit OK
|
||||
* e. RUNNING/MOVE BACK_PLANNED(s) FULLY_PLANNED-MOVE exit NOOP
|
||||
* f. RUNNING/COMMAND BACK_PLANNED/MOVE <don't care> plan move, exit OK
|
||||
* g. RUNNING/COMMAND FULLY_PLANNED/MOVE <don't care> exit NOOP
|
||||
* h. RUNNING/COMMAND COMMAND(s) NOT_PLANNED skip/plan command(s), exit OK
|
||||
* i. RUNNING/COMMAND COMMAND(s) BACK_PLANNED/MOVE skip/plan command(s), plan move (Note 1a), exit OK
|
||||
* j. RUNNING/COMMAND COMMAND(s) FULLY_PLANNED/MOVE skip command(s), exit NOOP
|
||||
*
|
||||
* (Note: all COMMAND(s) in 2j. should be in PLANNED state)
|
||||
*/
|
||||
|
||||
// _plan_aline() - mp_forward_plan() helper
|
||||
@@ -174,7 +179,7 @@ static stat_t _plan_aline(mpBuf_t *bf, float entry_velocity)
|
||||
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
|
||||
bf->buffer_state = MP_BUFFER_FULLY_PLANNED; //...here
|
||||
bf->plannable = false;
|
||||
return (STAT_OK); // report that we planned something...
|
||||
}
|
||||
@@ -189,7 +194,7 @@ stat_t mp_forward_plan()
|
||||
st_prep_null();
|
||||
return (STAT_NOOP);
|
||||
}
|
||||
if (bf->buffer_state < MP_BUFFER_PREPPED) { // case 0b: nothing to do. get outta here.
|
||||
if (bf->buffer_state < MP_BUFFER_BACK_PLANNED) { // case 0b: nothing to do. get outta here.
|
||||
return (STAT_NOOP);
|
||||
}
|
||||
|
||||
@@ -206,22 +211,22 @@ stat_t mp_forward_plan()
|
||||
|
||||
if (bf->block_type != BLOCK_TYPE_ALINE) { // meaning it's a COMMAND
|
||||
while (bf->block_type >= BLOCK_TYPE_COMMAND) {
|
||||
if (bf->buffer_state == MP_BUFFER_PREPPED) {
|
||||
bf->buffer_state = MP_BUFFER_PLANNED;// "planning" is just setting the state (for now)
|
||||
if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) {
|
||||
bf->buffer_state = MP_BUFFER_FULLY_PLANNED; // "planning" is just setting the state (for now)
|
||||
planned_something = true;
|
||||
}
|
||||
bf = bf->nx;
|
||||
}
|
||||
// Note: bf now points to the first non-command buffer past the command(s)
|
||||
if ((bf->block_type == BLOCK_TYPE_ALINE) && (bf->buffer_state > MP_BUFFER_PREPPED )) { // case 1i
|
||||
if ((bf->block_type == BLOCK_TYPE_ALINE) && (bf->buffer_state > MP_BUFFER_BACK_PLANNED )) { // case 1i
|
||||
entry_velocity = mr->r->exit_velocity; // set entry_velocity for Note 1a
|
||||
}
|
||||
}
|
||||
// bf will always be on a non-command at this point - either a move or empty buffer
|
||||
|
||||
// process move
|
||||
if (bf->block_type == BLOCK_TYPE_ALINE) { // do cases 1a - 1e; finish cases 1f - 1k
|
||||
if (bf->buffer_state == MP_BUFFER_PREPPED) {// do 1a; finish 1f, 1j, 2d, 2i
|
||||
if (bf->block_type == BLOCK_TYPE_ALINE) { // do cases 1a - 1e; finish cases 1f - 1k
|
||||
if (bf->buffer_state == MP_BUFFER_BACK_PLANNED) {// do 1a; finish 1f, 1j, 2d, 2i
|
||||
_plan_aline(bf, entry_velocity);
|
||||
planned_something = true;
|
||||
}
|
||||
@@ -264,19 +269,19 @@ 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)) {
|
||||
if ((bf->buffer_state < MP_BUFFER_BACK_PLANNED) && (cm->motion_state == MOTION_RUN)) {
|
||||
// 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) && (bf->nx->buffer_state > MP_BUFFER_EMPTY)) {
|
||||
if ((bf->nx->buffer_state < MP_BUFFER_BACK_PLANNED) && (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 (bf->buffer_state == MP_BUFFER_BACK_PLANNED) {
|
||||
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,
|
||||
@@ -285,7 +290,7 @@ stat_t mp_exec_move()
|
||||
return (STAT_NOOP);
|
||||
}
|
||||
|
||||
if (bf->buffer_state == MP_BUFFER_PLANNED) {
|
||||
if (bf->buffer_state == MP_BUFFER_FULLY_PLANNED) {
|
||||
bf->buffer_state = MP_BUFFER_RUNNING; // must precede mp_planner_time_acccounting()
|
||||
} else {
|
||||
return (STAT_NOOP);
|
||||
@@ -297,7 +302,7 @@ stat_t mp_exec_move()
|
||||
// This won't call mp_plan_move until we leave this function
|
||||
// (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_BACK_PLANNED) {
|
||||
st_request_forward_plan();
|
||||
}
|
||||
|
||||
@@ -1045,7 +1050,8 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf)
|
||||
mr->block_state = BLOCK_INACTIVE; // invalidate mr buffer to reset the new move
|
||||
bf->plannable = true; // needed so black can be adjusted
|
||||
mp_replan_queue(mp_get_r()); // unplan current forward plan (bf head block), and reset all blocks
|
||||
mp_forward_plan(); // replan current bf block
|
||||
st_request_forward_plan(); // replan the current bf buffer
|
||||
// mp_forward_plan(); // the one case where you can call this function directly
|
||||
copy_vector(mp->position, mr->target); // update planner position to the target
|
||||
|
||||
// Set state to enable transition to p2 and perform entry actions in the p2 planner
|
||||
|
||||
@@ -263,10 +263,9 @@ void mp_plan_block_list()
|
||||
return;
|
||||
}
|
||||
|
||||
bf = _plan_block(bf); // returns next block to plan
|
||||
|
||||
bf = _plan_block(bf); // returns next block to plan
|
||||
planned_something = true;
|
||||
mp->p = bf; // DIAGNOSTIC - this is not needed but is set here for debugging purposes
|
||||
mp->p = bf; // DIAGNOSTIC - this is not needed but is set here for debugging purposes
|
||||
}
|
||||
if (mp->planner_state > PLANNER_STARTUP) {
|
||||
if (planned_something && (cm->hold_state != FEEDHOLD_HOLD)) {
|
||||
@@ -297,7 +296,7 @@ static mpBuf_t* _plan_block(mpBuf_t* bf)
|
||||
}
|
||||
_calculate_override(bf); // adjust cruise_vmax for feed/traverse override
|
||||
// bf->plannable_time = bf->pv->plannable_time; // set plannable time - excluding current move
|
||||
bf->buffer_state = MP_BUFFER_IN_PROCESS;
|
||||
bf->buffer_state = MP_BUFFER_NOT_PLANNED;
|
||||
bf->hint = NO_HINT; // ensure we've cleared the hints
|
||||
|
||||
// Time: 12us-41us
|
||||
@@ -418,18 +417,18 @@ static mpBuf_t* _plan_block(mpBuf_t* bf)
|
||||
optimal = true; // We can't improve this entry more
|
||||
}
|
||||
|
||||
// DIAGNOSTICS
|
||||
// Exit the loop if we've hit and passed the running buffer. It can happen.
|
||||
if (bf->buffer_state == MP_BUFFER_EMPTY) {
|
||||
// _debug_trap("Exec apparently cleared this block while we were planning it.");
|
||||
break; // exit the loop, we've hit and passed the running buffer
|
||||
break;
|
||||
}
|
||||
// if (fp_ZERO(bf->exit_velocity) && !fp_ZERO(bf->exit_vmax)) {
|
||||
// _debug_trap(); // why zero?
|
||||
|
||||
// if (fp_ZERO(bf->exit_velocity) && !fp_ZERO(bf->exit_vmax)) { // DIAGNOSTIC
|
||||
// debug_trap("_plan_block(): Why is exit velocity zero?");
|
||||
// }
|
||||
|
||||
// We might back plan into the running or planned buffer, so we have to check.
|
||||
if (bf->buffer_state < MP_BUFFER_PREPPED) {
|
||||
bf->buffer_state = MP_BUFFER_PREPPED;
|
||||
if (bf->buffer_state < MP_BUFFER_BACK_PLANNED) {
|
||||
bf->buffer_state = MP_BUFFER_BACK_PLANNED;
|
||||
}
|
||||
} // for loop
|
||||
} // exits with bf pointing to a locked or EMPTY block
|
||||
|
||||
@@ -568,10 +568,10 @@ stat_t mp_planner_callback()
|
||||
void mp_replan_queue(mpBuf_t *bf)
|
||||
{
|
||||
do {
|
||||
if (bf->buffer_state >= MP_BUFFER_PLANNED) { // revert from PLANNED state
|
||||
bf->buffer_state = MP_BUFFER_PREPPED;
|
||||
} else { // If it's not "planned" then it's either PREPPED or earlier.
|
||||
break; // We don't need to adjust it.
|
||||
if (bf->buffer_state >= MP_BUFFER_FULLY_PLANNED) { // revert from FULLY PLANNED state
|
||||
bf->buffer_state = MP_BUFFER_BACK_PLANNED;
|
||||
} else { // If it's not "planned" then it's either backplanned or earlier.
|
||||
break; // We don't need to adjust it.
|
||||
}
|
||||
} while ((bf = mp_get_next_buffer(bf)) != mp_get_r());
|
||||
|
||||
@@ -842,13 +842,20 @@ void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
*** DIAGNOSTICS ********************************************************************
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* mp_dump_planner
|
||||
* _planner_report()
|
||||
* _audit_buffers() - a DEBUG diagnostic
|
||||
* _audit_buffers()
|
||||
*/
|
||||
|
||||
//#define __DUMP_PLANNER
|
||||
//#define __PLANNER_REPORT_ENABLED
|
||||
//#define __AUDIT_BUFFERS
|
||||
|
||||
#ifdef __DUMP_PLANNER
|
||||
void mp_dump_planner(mpBuf_t *bf_start) // starting at bf
|
||||
@@ -884,47 +891,57 @@ void mp_dump_planner(mpBuf_t *bf_start) // starting at bf
|
||||
}
|
||||
#endif // __DUMP_PLANNER
|
||||
|
||||
#if 0 && defined(DEBUG)
|
||||
|
||||
#warning DEBUG TRAPS ENABLED
|
||||
|
||||
//static void _planner_report(const char *msg)
|
||||
//{
|
||||
// rpt_exception(STAT_PLANNER_ASSERTION_FAILURE, msg);
|
||||
//
|
||||
// for (uint8_t i=0; i<PLANNER_BUFFER_POOL_SIZE; i++) {
|
||||
// printf("{\"er\":{\"stat\":%d, \"type\":%d, \"lock\":%d, \"plannable\":%d",
|
||||
// mb.bf[i].buffer_state,
|
||||
// mb.bf[i].block_type,
|
||||
// mb.bf[i].locked,
|
||||
// mb.bf[i].plannable);
|
||||
// if (&mb.bf[i] == mb.r) {
|
||||
// printf(", \"RUN\":t");}
|
||||
// if (&mb.bf[i] == mb.w) {
|
||||
// printf(", \"WRT\":t");}
|
||||
// printf("}}\n");
|
||||
// }
|
||||
//}
|
||||
//#if 0 && defined(DEBUG)
|
||||
//#warning DEBUG TRAPS ENABLED
|
||||
|
||||
/*
|
||||
* _audit_buffers() - diagnostic to determine if buffers are sane
|
||||
* _planner_report() - a detailed report for buffer audits
|
||||
*/
|
||||
|
||||
#ifndef __AUDIT_BUFFERS
|
||||
|
||||
static void _audit_buffers()
|
||||
{
|
||||
// empty stub
|
||||
}
|
||||
#else
|
||||
|
||||
static void _planner_report(const char *msg)
|
||||
{
|
||||
#ifdef __PLANNER_REPORT_ENABLED
|
||||
rpt_exception(STAT_PLANNER_ASSERTION_FAILURE, msg);
|
||||
|
||||
for (uint8_t i=0; i<PLANNER_BUFFER_POOL_SIZE; i++) {
|
||||
printf("{\"er\":{\"stat\":%d, \"type\":%d, \"lock\":%d, \"plannable\":%d",
|
||||
mb.bf[i].buffer_state,
|
||||
mb.bf[i].block_type,
|
||||
mb.bf[i].locked,
|
||||
mb.bf[i].plannable);
|
||||
if (&mb.bf[i] == mb.r) {
|
||||
printf(", \"RUN\":t");}
|
||||
if (&mb.bf[i] == mb.w) {
|
||||
printf(", \"WRT\":t");}
|
||||
printf("}}\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _audit_buffers()
|
||||
{
|
||||
__disable_irq();
|
||||
|
||||
// Current buffer should be in the running state.
|
||||
if (mb.r->buffer_state != MP_BUFFER_RUNNING) {
|
||||
// _planner_report("buffer audit1");
|
||||
_planner_report("buffer audit1");
|
||||
__NOP();
|
||||
// _debug_trap();
|
||||
debug_trap("buffer audit1");
|
||||
}
|
||||
|
||||
// Check that the next from the previous is correct.
|
||||
if (mb.r->pv->nx != mb.r || mb.r->nx->pv != mb.r){
|
||||
// _planner_report("buffer audit2");
|
||||
_debug_trap("buffer audit2");
|
||||
_planner_report("buffer audit2");
|
||||
debug_trap("buffer audit2");
|
||||
}
|
||||
|
||||
// Now check every buffer, in order we would execute them.
|
||||
@@ -932,8 +949,8 @@ static void _audit_buffers()
|
||||
while (bf != mb.r) {
|
||||
// Check that the next from the previous is correct.
|
||||
if (bf->pv->nx != bf || bf->nx->pv != bf){
|
||||
// _planner_report("buffer audit3");
|
||||
_debug_trap("buffer audit3");
|
||||
_planner_report("buffer audit3");
|
||||
debug_trap("buffer audit3");
|
||||
}
|
||||
|
||||
// Order should be:
|
||||
@@ -954,8 +971,8 @@ static void _audit_buffers()
|
||||
if ((bf->buffer_state == MP_BUFFER_INITIALIZING) || (bf->buffer_state == MP_BUFFER_IN_PROCESS)) {
|
||||
__NOP();
|
||||
} else {
|
||||
// _planner_report("buffer audit4");
|
||||
_debug_trap("buffer audit4");
|
||||
_planner_report("buffer audit4");
|
||||
debug_trap("buffer audit4");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,8 +982,8 @@ static void _audit_buffers()
|
||||
bf->buffer_state != MP_BUFFER_INITIALIZING &&
|
||||
bf->buffer_state != MP_BUFFER_IN_PROCESS &&
|
||||
bf->buffer_state != MP_BUFFER_EMPTY) {
|
||||
// _planner_report("buffer audit5");
|
||||
_debug_trap("buffer audit5");
|
||||
_planner_report("buffer audit5");
|
||||
debug_trap("buffer audit5");
|
||||
}
|
||||
|
||||
// After PREPPED, we can see PREPPED, INITED, IN_PROCESS, or EMPTY
|
||||
@@ -975,14 +992,14 @@ static void _audit_buffers()
|
||||
bf->buffer_state != MP_BUFFER_INITIALIZING &&
|
||||
bf->buffer_state != MP_BUFFER_IN_PROCESS &&
|
||||
bf->buffer_state != MP_BUFFER_EMPTY) {
|
||||
// _planner_report("buffer audit6");
|
||||
_debug_trap("buffer audit6");
|
||||
_planner_report("buffer audit6");
|
||||
debug_trap("buffer audit6");
|
||||
}
|
||||
|
||||
// After EMPTY, we should only see EMPTY
|
||||
if (bf->pv->buffer_state == MP_BUFFER_EMPTY && bf->buffer_state != MP_BUFFER_EMPTY) {
|
||||
// _planner_report("buffer audit7");
|
||||
_debug_trap("buffer audit7");
|
||||
_planner_report("buffer audit7");
|
||||
debug_trap("buffer audit7");
|
||||
}
|
||||
// Now look at the next one.
|
||||
bf = bf->nx;
|
||||
@@ -990,15 +1007,7 @@ static void _audit_buffers()
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void _audit_buffers()
|
||||
{
|
||||
// empty stub
|
||||
}
|
||||
|
||||
#endif // 0
|
||||
|
||||
#endif // __AUDIT_BUFFERS
|
||||
|
||||
/****************************
|
||||
* END OF PLANNER FUNCTIONS *
|
||||
|
||||
@@ -164,15 +164,15 @@ typedef enum { // planner operating state
|
||||
PLANNER_IDLE = 0, // planner and movement are idle
|
||||
PLANNER_STARTUP, // ingesting blocks before movement is started
|
||||
PLANNER_PRIMING, // preparing new moves for planning ("stitching")
|
||||
PLANNER_BACK_PLANNING // plan by planning all blocks, from the newest added to the running block
|
||||
PLANNER_BACK_PLANNING // actively backplanning all blocks, from the newest added to the running block
|
||||
} plannerState;
|
||||
|
||||
typedef enum { // bf->buffer_state values in incresing order so > and < can be used
|
||||
MP_BUFFER_EMPTY = 0, // buffer is available for use (MUST BE 0)
|
||||
MP_BUFFER_INITIALIZING, // buffer has been checked out and is being initialzed by aline() or a command
|
||||
MP_BUFFER_IN_PROCESS, // planning is in progress - at least vmaxes have been set
|
||||
MP_BUFFER_PREPPED, // buffer ready for final planning; velocities have been set
|
||||
MP_BUFFER_PLANNED, // buffer fully planned. May still be replanned
|
||||
MP_BUFFER_NOT_PLANNED, // planning is in progress - at least vmaxes have been set
|
||||
MP_BUFFER_BACK_PLANNED, // buffer ready for final planning; velocities have been set
|
||||
MP_BUFFER_FULLY_PLANNED, // buffer fully planned. May still be replanned
|
||||
MP_BUFFER_RUNNING, // current running buffer
|
||||
MP_BUFFER_POLAND, // Hitler used Poland as a buffer state
|
||||
MP_BUFFER_UKRAINE // Later Stalin did the same to Ukraine
|
||||
|
||||
Reference in New Issue
Block a user