Changed cycle_state to cycle_type

This commit is contained in:
Alden Hart
2017-03-06 11:19:41 -05:00
parent f265c57d7d
commit c457e50dd4
10 changed files with 62 additions and 53 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ void cm_halt_motion(void)
{
mp_halt_runtime(); // stop the runtime. Do this immediately. (Reset is in cm_clear)
canonical_machine_reset(cm); // halt the currently active machine
cm->cycle_state = CYCLE_OFF; // Note: leaves machine_state alone
cm->cycle_type = CYCLE_NONE; // Note: leaves machine_state alone
cm->motion_state = MOTION_STOP;
cm->hold_state = FEEDHOLD_OFF;
}
+17 -17
View File
@@ -199,7 +199,7 @@ void canonical_machine_reset(cmMachine_t *_cm)
_cm->shutdown_requested = 0; // ditto
// set initial state and signal that the machine is ready for action
_cm->cycle_state = CYCLE_OFF;
_cm->cycle_type = CYCLE_NONE;
_cm->motion_state = MOTION_STOP;
_cm->hold_state = FEEDHOLD_OFF;
_cm->esc_boot_timer = SysTickTimer_getValue();
@@ -271,13 +271,13 @@ void cm_set_motion_state(const cmMotionState motion_state)
/*
* cm_get_machine_state()
* cm_get_motion_state()
* cm_get_cycle_state()
* cm_get_cycle_type()
* cm_get_hold_state()
* cm_get_homing_state()
* cm_get_probe_state()
*/
cmMachineState cm_get_machine_state() { return cm->machine_state;}
cmCycleState cm_get_cycle_state() { return cm->cycle_state;}
cmCycleType cm_get_cycle_type() { return cm->cycle_type;}
cmMotionState cm_get_motion_state() { return cm->motion_state;}
cmFeedholdState cm_get_hold_state() { return cm->hold_state;}
cmHomingState cm_get_homing_state() { return cm->homing_state;}
@@ -304,11 +304,11 @@ cmCombinedState cm_get_combined_state(cmMachine_t *_cm)
case MACHINE_SHUTDOWN: { return (COMBINED_SHUTDOWN); }
case MACHINE_PANIC: { return (COMBINED_PANIC); }
case MACHINE_CYCLE: {
switch(_cm->cycle_state) {
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_OFF: {
case CYCLE_MACHINING: case CYCLE_NONE: {
switch(_cm->motion_state) {
case MOTION_STOP: { return (COMBINED_RUN); } // See NOTE_1, above
case MOTION_PLANNING: { return (COMBINED_RUN); }
@@ -534,7 +534,7 @@ void cm_update_model_position()
stat_t cm_deferred_write_callback()
{
if ((cm->cycle_state == CYCLE_OFF) && (cm->deferred_write_flag == true)) {
if ((cm->cycle_type == CYCLE_NONE) && (cm->deferred_write_flag == true)) {
cm->deferred_write_flag = false;
nvObj_t nv;
for (uint8_t i=1; i<=COORDS; i++) {
@@ -1563,18 +1563,18 @@ stat_t cm_tro_control(const float P_word, const bool P_flag) // M50.1
static void _exec_program_finalize(float *value, bool *flag)
{
cmMachineState machine_state = (cmMachineState)value[0];
cm_set_motion_state(MOTION_STOP); // also changes active model back to MODEL
cm_set_motion_state(MOTION_STOP); // also changes active model back to MODEL
// Allow update in the alarm state, to accommodate queue flush (RAS)
if ((cm->cycle_state == CYCLE_MACHINING || cm->cycle_state == CYCLE_OFF) &&
// (cm->machine_state != MACHINE_ALARM) && // omitted by OMC (RAS)
if ((cm->cycle_type == CYCLE_MACHINING || cm->cycle_type == CYCLE_NONE) &&
// (cm->machine_state != MACHINE_ALARM) && // omitted by OMC (RAS)
(cm->machine_state != MACHINE_SHUTDOWN)) {
cm->machine_state = machine_state; // don't update macs/cycs if we're in the middle of a canned cycle,
cm->cycle_state = CYCLE_OFF; // or if we're in machine alarm/shutdown mode
cm->machine_state = machine_state; // don't update macs/cycs if we're in the middle of a canned cycle,
cm->cycle_type = CYCLE_NONE; // or if we're in machine alarm/shutdown mode
}
// reset the rest of the states
cm->cycle_state = CYCLE_OFF;
cm->cycle_type = CYCLE_NONE;
cm->hold_state = FEEDHOLD_OFF;
mp_zero_segment_velocity(); // for reporting purposes
@@ -1599,16 +1599,16 @@ static void _exec_program_finalize(float *value, bool *flag)
void cm_cycle_start()
{
if (cm->cycle_state == CYCLE_OFF) { // don't (re)start homing, probe or other canned cycles
if (cm->cycle_type == CYCLE_NONE) { // don't (re)start homing, probe or other canned cycles
cm->cycle_type = CYCLE_MACHINING;
cm->machine_state = MACHINE_CYCLE;
cm->cycle_state = CYCLE_MACHINING;
qr_init_queue_report(); // clear queue reporting buffer counts
}
}
void cm_cycle_end()
{
if (cm->cycle_state == CYCLE_MACHINING) {
if (cm->cycle_type == CYCLE_MACHINING) {
float value[] = { (float)MACHINE_PROGRAM_STOP };
_exec_program_finalize(value, nullptr);
}
@@ -1616,7 +1616,7 @@ void cm_cycle_end()
void cm_canned_cycle_end()
{
cm->cycle_state = CYCLE_OFF;
cm->cycle_type = CYCLE_NONE;
float value[] = { (float)MACHINE_PROGRAM_STOP };
_exec_program_finalize(value, nullptr);
}
@@ -1979,7 +1979,7 @@ stat_t _get_msg_helper(nvObj_t *nv, const char *const msg_array[], uint8_t value
stat_t cm_get_stat(nvObj_t *nv) { return(_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm1)));}
stat_t cm_get_stat2(nvObj_t *nv) { return(_get_msg_helper(nv, msg_stat, cm_get_combined_state(&cm2)));}
stat_t cm_get_macs(nvObj_t *nv) { return(_get_msg_helper(nv, msg_macs, cm_get_machine_state()));}
stat_t cm_get_cycs(nvObj_t *nv) { return(_get_msg_helper(nv, msg_cycs, cm_get_cycle_state()));}
stat_t cm_get_cycs(nvObj_t *nv) { return(_get_msg_helper(nv, msg_cycs, cm_get_cycle_type()));}
stat_t cm_get_mots(nvObj_t *nv) { return(_get_msg_helper(nv, msg_mots, cm_get_motion_state()));}
stat_t cm_get_hold(nvObj_t *nv) { return(_get_msg_helper(nv, msg_hold, cm_get_hold_state()));}
+25 -18
View File
@@ -83,23 +83,25 @@ typedef enum { // check alignment with messages in config.c / m
typedef enum {
MACHINE_INITIALIZING = 0, // machine is initializing
MACHINE_READY, // machine is ready for use
MACHINE_ALARM, // machine in alarm state
MACHINE_READY, // machine is ready for use but idle
MACHINE_ALARM, // machine is in alarm state
MACHINE_PROGRAM_STOP, // no blocks to run; like PROGRAM_END but without the M2 to reset gcode state
MACHINE_PROGRAM_END, // program end (same as MACHINE_READY, really...)
MACHINE_CYCLE, // machine is running; blocks still to run, or steppers are busy
MACHINE_INTERLOCK, // machine in interlock state
MACHINE_SHUTDOWN, // machine in shutdown state
MACHINE_PANIC // machine in panic state
MACHINE_CYCLE, // machine is in cycle, running; blocks still to run, or steppers are busy
MACHINE_INTERLOCK, // machine is in interlock state
MACHINE_SHUTDOWN, // machine is in shutdown state
MACHINE_PANIC // machine is in panic state
} cmMachineState;
typedef enum {
CYCLE_OFF = 0, // machine is idle
CYCLE_NONE = 0, // machine is not ins a cycle
CYCLE_MACHINING, // in normal machining cycle
CYCLE_HOMING, // in homing cycle
CYCLE_PROBE, // in probe cycle
CYCLE_JOG // in jogging cycle
} cmCycleState;
// CYCLE_G81 // illustration of canned cycles
// ...
} cmCycleType;
typedef enum {
MOTION_STOP = 0, // motion has stopped: set when the steppers reach the end of the planner queue
@@ -109,11 +111,11 @@ typedef enum {
} cmMotionState;
typedef enum { // feedhold requests
FEEDHOLD_NO_REQUEST =0, // no pending request; reverts here when complete (read-only; cannot be set)
FEEDHOLD_HOLD_P1 =1, // enter p1 feedhold, enter HOLD state in p1
FEEDHOLD_HOLD_P2 =2, // (!) enter p1 feedhold, enter p2 with entry actions
FEEDHOLD_EXIT_RESUME =3, // (~) exit feedhold, perform exit actions if in p2, resume p1 motion
FEEDHOLD_EXIT_FLUSH =4, // (%) exit feedhold, perform exit actions if in p2, flush planner queue, enter p1 PROGRAM_STOP
FEEDHOLD_NO_REQUEST = 0, // no pending request; reverts here when complete (read-only; cannot be set)
FEEDHOLD_HOLD_P1, // enter p1 feedhold, enter HOLD state in p1
FEEDHOLD_HOLD_P2, // (!) enter p1 feedhold, enter p2 with entry actions
FEEDHOLD_CYCLE_START, // (~) exit feedhold, perform exit actions if in p2, resume p1 motion
FEEDHOLD_EXIT_FLUSH, // (%) exit feedhold, perform exit actions if in p2, flush planner queue, enter p1 PROGRAM_STOP
// Feedholds with specialized exits
// If not in hold, perform hold (or halt), then perform the exit immediately
@@ -267,11 +269,17 @@ typedef struct cmMachine { // struct to manage canonical machin
// Global state variables and flags
cmMachineState machine_state; // macs: machine/cycle/motion is the actual machine state
cmCycleState cycle_state; // cycs
cmCycleType cycle_type; // cycs
cmMotionState motion_state; // momo
cmFeedholdState hold_state; // hold: feedhold state machine
cmFeedholdRequest hold_request; // hold: pending feedhold request
cmFeedholdRequest hold_exit; // hold: pending feedhold exit request
cmFlushState flush_state; // hold: queue flush state machine
bool hold_exit_requested; // request normal exit from feedhold
bool hold_abort_requested; // request emergency exit from feedhold (typically ^d job kill)
cmOverrideState mfo_state; // feed override state machine
cmFlushState flush_state; // queue flush state machine
uint8_t safety_interlock_disengaged; // set non-zero to start interlock processing (value is input number)
uint8_t safety_interlock_reengaged; // set non-zero to end interlock processing (value is input number)
@@ -281,8 +289,7 @@ typedef struct cmMachine { // struct to manage canonical machin
uint8_t limit_requested; // set non-zero to request limit switch processing (value is input number)
uint8_t shutdown_requested; // set non-zero to request shutdown in support of external estop (value is input number)
bool deferred_write_flag; // G10 data has changed (e.g. offsets) - flag to persist them
bool hold_exit_requested; // request normal exit from feedhold
bool hold_abort_requested; // request emergency exit from feedhold (typically ^d job kill)
bool return_flags[AXES]; // flags for recording which axes moved - used in feedhold exit move
cmHomingState homing_state; // home: homing cycle sub-state machine
@@ -328,7 +335,7 @@ extern cmToolTable_t tt;
// Model state getters and setters
cmCombinedState cm_get_combined_state(cmMachine_t *_cm);
cmMachineState cm_get_machine_state(void);
cmCycleState cm_get_cycle_state(void);
cmCycleType cm_get_cycle_type(void);
cmMotionState cm_get_motion_state(void);
cmFeedholdState cm_get_hold_state(void);
cmHomingState cm_get_homing_state(void);
+6 -4
View File
@@ -89,7 +89,7 @@ static void _feedhold_abort(void);
* If this command is received while in p2, a FEEDHOLD_HOLD_SKIP
* is executed in p2.
*
* - FEEDHOLD_EXIT_RESUME (~) Exit HOLD state in P1 or p2. If in p2 perform exit actions,
* - FEEDHOLD_CYCLE_START (~) Exit HOLD state in P1 or p2. If in p2 perform exit actions,
* then resume motion in p1 planner.
*
* - FEEDHOLD_EXIT_FLUSH (%) Exit HOLD state in P1 or p2. If in p2 perform exit actions,
@@ -138,8 +138,6 @@ static void _feedhold_abort(void);
* Exit hold and resume motion when interlock is cleared. This may
* require some combination of interlock switch transitions, interlock
* JSON commands and {clear:n} depending on interlock configuration.
*
*
*/
/*
* Feedhold Processing - Performs the following cases (listed in rough sequence order):
@@ -225,7 +223,9 @@ void cm_request_feedhold(void) // !
{
// Only generate request if not already in a feedhold and the machine is in motion
if ((cm1.hold_state == FEEDHOLD_OFF) && (cm1.motion_state != MOTION_STOP)) {
cm1.hold_state = FEEDHOLD_REQUESTED;
cm1.hold_request = FEEDHOLD_HOLD_P2; // request a hold to p2
cm1.hold_exit = FEEDHOLD_NO_REQUEST; // no exit specified
cm1.hold_state = FEEDHOLD_REQUESTED; // signal request to state machine
} else
if ((cm2.hold_state == FEEDHOLD_OFF) && (cm2.motion_state != MOTION_STOP)) {
cm2.hold_state = FEEDHOLD_REQUESTED;
@@ -235,6 +235,7 @@ void cm_request_feedhold(void) // !
void cm_request_exit_hold(void) // ~
{
if (cm1.hold_state != FEEDHOLD_OFF) {
cm1.hold_exit = FEEDHOLD_CYCLE_START; // signal a normal feedhold resume as exit
cm1.hold_exit_requested = true;
}
}
@@ -244,6 +245,7 @@ void cm_request_queue_flush() // %
// NOTE: this function used to flush input buffers, but this is handled in xio *prior* to queue flush now
if ((cm1.hold_state != FEEDHOLD_OFF) && // don't honor request unless you are in a feedhold
(cm1.flush_state == FLUSH_OFF)) { // ...and only once
cm1.hold_exit = FEEDHOLD_EXIT_FLUSH; // signal a flush exit
cm1.flush_state = FLUSH_REQUESTED; // request planner flush once motion has stopped
}
}
+2 -2
View File
@@ -170,7 +170,7 @@ stat_t cm_homing_cycle_start(const float axes[], const bool flags[]) {
hm.axis = -1; // set to retrieve initial axis
hm.func = _homing_axis_start; // bind initial processing function
cm->machine_state = MACHINE_CYCLE;
cm->cycle_state = CYCLE_HOMING;
cm->cycle_type = CYCLE_HOMING;
cm->homing_state = HOMING_NOT_HOMED;
return (STAT_OK);
}
@@ -186,7 +186,7 @@ stat_t cm_homing_cycle_start_no_set(const float axes[], const bool flags[]) {
*/
stat_t cm_homing_cycle_callback(void) {
if (cm->cycle_state != CYCLE_HOMING) { // exit if not in a homing cycle
if (cm->cycle_type != CYCLE_HOMING) { // exit if not in a homing cycle
return (STAT_NOOP);
}
if (hm.waiting_for_motion_end) { // sync to planner move ends (using callback)
+5 -5
View File
@@ -100,17 +100,17 @@ stat_t cm_jogging_cycle_start(uint8_t axis) {
cm_set_feed_rate_mode(UNITS_PER_MINUTE_MODE);
jog.velocity_start = JOGGING_START_VELOCITY; // see canonical_machine.h for #define
jog.velocity_max = cm->a[axis].velocity_max;
jog.velocity_max = cm->a[axis].velocity_max;
jog.start_pos = cm_get_absolute_position(RUNTIME, axis);
jog.dest_pos = cm_get_jogging_dest();
jog.step = 0;
jog.dest_pos = cm_get_jogging_dest();
jog.step = 0;
jog.axis = axis;
jog.func = _jogging_axis_start; // bind initial processing function
cm->machine_state = MACHINE_CYCLE;
cm->cycle_state = CYCLE_JOG;
cm->cycle_type = CYCLE_JOG;
return (STAT_OK);
}
@@ -124,7 +124,7 @@ stat_t cm_jogging_cycle_start(uint8_t axis) {
*/
stat_t cm_jogging_cycle_callback(void) {
if (cm->cycle_state != CYCLE_JOG) {
if (cm->cycle_type != CYCLE_JOG) {
return (STAT_NOOP); // exit if not in a jogging cycle
}
if (jog.func == _jogging_finalize_exit && cm_get_runtime_busy() == true) {
+2 -2
View File
@@ -184,7 +184,7 @@ uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool al
uint8_t cm_probing_cycle_callback(void)
{
if ((cm->cycle_state != CYCLE_PROBE) && (cm->probe_state[0] != PROBE_WAITING)) {
if ((cm->cycle_type != CYCLE_PROBE) && (cm->probe_state[0] != PROBE_WAITING)) {
return (STAT_NOOP); // exit if not in a probing cycle
}
if (pb.wait_for_motion_end) { // sync to planner move ends (using callback)
@@ -207,7 +207,7 @@ static uint8_t _probing_start()
cm->probe_state[0] = PROBE_FAILED;
cm->machine_state = MACHINE_CYCLE;
cm->cycle_state = CYCLE_PROBE;
cm->cycle_type = CYCLE_PROBE;
// save relevant non-axis parameters from Gcode model
pb.saved_distance_mode = (cmDistanceMode)cm_get_distance_mode(ACTIVE_MODEL);
+2 -2
View File
@@ -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>
+1 -1
View File
@@ -1032,7 +1032,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf)
// If probing or homing, exit the move and advance to the _motion_end_callback()'s.
// Stop the runtime, clear the run buffer and do not transition to p2 planner.
else if ((cm->cycle_state == CYCLE_HOMING) || (cm->cycle_state == CYCLE_PROBE)) {
else if ((cm->cycle_type == CYCLE_HOMING) || (cm->cycle_type == CYCLE_PROBE)) {
mr->block_state = BLOCK_INACTIVE; // disable the rest of the runtime movement
mp_free_run_buffer(); // free buffer and enable finalization move to get loaded
cm->hold_state = FEEDHOLD_OFF;
+1 -1
View File
@@ -113,7 +113,7 @@ float mp_get_runtime_display_position(uint8_t axis) {
*/
bool mp_get_runtime_busy()
{
if (cm->cycle_state == CYCLE_OFF) {
if (cm->cycle_type == CYCLE_NONE) {
return (false);
}
if ((st_runtime_isbusy() == true) ||