Simplified cm_get_combined_state

This commit is contained in:
Alden Hart
2017-03-11 08:29:54 -05:00
parent 66e57594b5
commit 741014988d
2 changed files with 15 additions and 42 deletions
+13 -42
View File
@@ -284,59 +284,30 @@ cmProbeState cm_get_probe_state() { return cm->probe_state[0];}
/*
* cm_get_combined_state() - combines raw states into something a user might want to see
*
* NOTE: On issuing a gcode command we call cm_cycle_start() before the motion gets queued.
* We don't go to MOTION_RUN until the command is executed by mp_exec_aline(), planned,
* queued, and started. So MOTION_STOP must actually return COMBINED_RUN to address this
* case, even though under some circumstances it might actually be an exception case.
* Therefore this assertion isn't valid:
* cm_panic(STAT_STATE_MANAGEMENT_ASSERTION_FAILURE, "mots2"));//"mots is stop but machine is in cycle"
* return (COMBINED_PANIC);
*/
cmCombinedState cm_get_combined_state(cmMachine_t *_cm)
{
if (_cm->machine_state <= MACHINE_PROGRAM_END) { // replaces first 5 cm->machine_state cases
return ((cmCombinedState)_cm->machine_state); //...where MACHINE_xxx == COMBINED_xxx
}
switch(_cm->machine_state) {
case MACHINE_INITIALIZING:
case MACHINE_READY:
case MACHINE_ALARM:
case MACHINE_PROGRAM_STOP:
case MACHINE_PROGRAM_END: { return ((cmCombinedState)_cm->machine_state); }
case MACHINE_INTERLOCK: { return (COMBINED_INTERLOCK); }
case MACHINE_SHUTDOWN: { return (COMBINED_SHUTDOWN); }
case MACHINE_PANIC: { return (COMBINED_PANIC); }
case MACHINE_CYCLE: {
switch(_cm->cycle_type) {
case CYCLE_HOMING: { return (COMBINED_HOMING); }
case CYCLE_PROBE: { return (COMBINED_PROBE); }
case CYCLE_JOG: { return (COMBINED_JOG); }
// case CYCLE_MACHINING: case CYCLE_NONE: {
// switch(_cm->motion_state) {
// case MOTION_STOP: { return (COMBINED_RUN); } // See NOTE, above
// case MOTION_RUN: { return (COMBINED_RUN); }
// case MOTION_HOLD: { return (COMBINED_HOLD); }
// default: {
// cm_panic(STAT_STATE_MANAGEMENT_ASSERTION_FAILURE, "cm_get_combined_state() mots bad");// "mots has impossible value"
// return (COMBINED_PANIC);
// }
// }
case CYCLE_MACHINING: {
if (_cm->hold_state != FEEDHOLD_OFF) {
return (COMBINED_HOLD);
} else {
return (COMBINED_RUN);
}
}
default: {
cm_panic(STAT_STATE_MANAGEMENT_ASSERTION_FAILURE, "cm_get_combined_state() cycs bad"); // "cycs has impossible value"
return (COMBINED_PANIC);
}
switch(_cm->cycle_type) {
case CYCLE_NONE: { break; } // CYCLE_NONE cannot ever get here
case CYCLE_MACHINING: { return (_cm->hold_state == FEEDHOLD_OFF ? COMBINED_RUN : COMBINED_HOLD); }
case CYCLE_HOMING: { return (COMBINED_HOMING); }
case CYCLE_PROBE: { return (COMBINED_PROBE); }
case CYCLE_JOG: { return (COMBINED_JOG); }
}
}
default: {
cm_panic(STAT_STATE_MANAGEMENT_ASSERTION_FAILURE, "cm_get_combined_state() macs bad"); // "macs has impossible value"
return (COMBINED_PANIC);
}
}
cm_panic(STAT_STATE_MANAGEMENT_ASSERTION_FAILURE, "cm_get_combined_state() undefined state");
return (COMBINED_PANIC);
}
/***********************************************************************************
+2
View File
@@ -308,6 +308,7 @@ stat_t mp_exec_move()
// Manage motion state transitions
if ((cm->motion_state != MOTION_RUN) && (cm->motion_state != MOTION_HOLD)) {
// +++++ if (cm->motion_state != MOTION_RUN) {
cm_set_motion_state(MOTION_RUN); // also sets active model to RUNTIME
}
}
@@ -552,6 +553,7 @@ stat_t mp_exec_aline(mpBuf_t *bf)
if (bf->block_state == BLOCK_ACTIVE) {
if (mp_free_run_buffer()) { // returns true of the buffer is empty
if (cm->hold_state == FEEDHOLD_OFF) {
cm_set_motion_state(MOTION_STOP); // also sets active model to RUNTIME
cm_cycle_end(); // free buffer & end cycle if planner is empty
}
} else {