mirror of
https://github.com/synthetos/g2.git
synced 2026-09-26 01:02:30 +08:00
checkpoint
This commit is contained in:
+16
-30
@@ -112,7 +112,7 @@ stat_t cm_is_alarmed()
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* cm_halt_all() - stop, spindle and coolant immediately
|
||||
* cm_halt() - stop motion, spindle, coolant and heaters immediately
|
||||
* cm_halt_motion() - stop motion immediately. Does not affect spindle, coolant, or other IO
|
||||
*
|
||||
* Stop motors and reset all system states accordingly.
|
||||
@@ -120,11 +120,12 @@ stat_t cm_is_alarmed()
|
||||
* in order to prevent an axis from crashing.
|
||||
*/
|
||||
|
||||
void cm_halt_all(void)
|
||||
void cm_halt(void)
|
||||
{
|
||||
cm_halt_motion();
|
||||
spindle_control_immediate(SPINDLE_OFF);
|
||||
coolant_control_immediate(COOLANT_OFF, COOLANT_BOTH);
|
||||
temperature_init();
|
||||
}
|
||||
|
||||
void cm_halt_motion(void)
|
||||
@@ -165,19 +166,8 @@ stat_t cm_alarm(const stat_t status, const char *msg)
|
||||
(cm->machine_state == MACHINE_PANIC)) {
|
||||
return (STAT_OK); // don't alarm if already in an alarm state
|
||||
}
|
||||
cm1.machine_state = MACHINE_ALARM; // alarm both machines
|
||||
cm2.machine_state = MACHINE_ALARM;
|
||||
cm_request_feedhold(); // stop motion
|
||||
cm_request_queue_flush(); // do a queue flush once runtime is not busy
|
||||
|
||||
// TBD - these functions should probably be called - See cm_shutdown()
|
||||
// cm_spindle_control_immediate(SPINDLE_OFF);
|
||||
// cm_coolant_off_immediate();
|
||||
// cm_spindle_optional_pause(spindle.pause_on_hold);
|
||||
// cm_coolant_optional_pause(coolant.pause_on_hold);
|
||||
rpt_exception(status, msg); // send alarm message
|
||||
|
||||
// If "stat" is in the status report, we need to poke it to send.
|
||||
cm_request_feedhold(FEEDHOLD_TYPE_SCRAM, FEEDHOLD_FINAL_ALARM); // fast stop and alarm
|
||||
rpt_exception(status, msg); // send alarm message
|
||||
sr_request_status_report(SR_REQUEST_TIMED);
|
||||
return (status);
|
||||
}
|
||||
@@ -204,20 +194,23 @@ stat_t cm_shutdown(const stat_t status, const char *msg)
|
||||
if ((cm->machine_state == MACHINE_SHUTDOWN) || (cm->machine_state == MACHINE_PANIC)) {
|
||||
return (STAT_OK); // don't shutdown if shutdown or panic'd
|
||||
}
|
||||
cm_halt_motion(); // halt motors (may have already been done from GPIO)
|
||||
spindle_reset(); // stop spindle immediately and set speed to 0 RPM
|
||||
coolant_reset(); // stop coolant immediately
|
||||
temperature_reset(); // turn off heaters and fans
|
||||
cm_queue_flush(&cm1); // flush all queues and reset positions
|
||||
cm_request_feedhold(FEEDHOLD_TYPE_SCRAM, FEEDHOLD_FINAL_SHUTDOWN); // fast stop and shutdown
|
||||
|
||||
// cm_halt_motion(); // halt motors (may have already been done from GPIO)
|
||||
// spindle_reset(); // stop spindle immediately and set speed to 0 RPM
|
||||
// coolant_reset(); // stop coolant immediately
|
||||
// temperature_reset(); // turn off heaters and fans
|
||||
// cm_queue_flush(&cm1); // flush all queues and reset positions
|
||||
|
||||
for (uint8_t i = 0; i < HOMING_AXES; i++) { // unhome axes and the machine
|
||||
cm->homed[i] = false;
|
||||
}
|
||||
cm->homing_state = HOMING_NOT_HOMED;
|
||||
|
||||
cm1.machine_state = MACHINE_SHUTDOWN; // shut down both machines...
|
||||
cm2.machine_state = MACHINE_SHUTDOWN; //...do this after all other activity
|
||||
// cm1.machine_state = MACHINE_SHUTDOWN; // shut down both machines...
|
||||
// cm2.machine_state = MACHINE_SHUTDOWN; //...do this after all other activity
|
||||
rpt_exception(status, msg); // send exception report
|
||||
sr_request_status_report(SR_REQUEST_TIMED);
|
||||
return (status);
|
||||
}
|
||||
|
||||
@@ -256,12 +249,5 @@ stat_t cm_panic(const stat_t status, const char *msg)
|
||||
|
||||
void cm_job_kill()
|
||||
{
|
||||
cm1.hold_abort_requested = true;
|
||||
cm_program_end();
|
||||
|
||||
// if (cm->machine_state == MACHINE_ALARM) {
|
||||
// cm->machine_state = MACHINE_PROGRAM_STOP;
|
||||
// } else if (cm->machine_state == MACHINE_SHUTDOWN) {
|
||||
// cm->machine_state = MACHINE_READY;
|
||||
// }
|
||||
cm1.request_job_kill = true;
|
||||
}
|
||||
|
||||
@@ -192,12 +192,15 @@ void canonical_machine_reset(cmMachine_t *_cm)
|
||||
|
||||
// reset request flags
|
||||
_cm->flush_state = FLUSH_OFF;
|
||||
_cm->hold_exit_requested = false;
|
||||
_cm->limit_requested = 0; // resets switch closures that occurred during initialization
|
||||
_cm->safety_interlock_disengaged = 0; // ditto
|
||||
_cm->safety_interlock_reengaged = 0; // ditto
|
||||
_cm->shutdown_requested = 0; // ditto
|
||||
|
||||
_cm->request_interlock = false;
|
||||
_cm->request_interlock_exit = false;
|
||||
_cm->request_job_kill = false;
|
||||
|
||||
// set initial state and signal that the machine is ready for action
|
||||
_cm->cycle_type = CYCLE_NONE;
|
||||
_cm->motion_state = MOTION_STOP;
|
||||
@@ -1731,12 +1734,13 @@ char cm_get_axis_char(const int8_t axis)
|
||||
* cm_run_qf() - flush planner queue
|
||||
* cm_run_home() - run homing sequence
|
||||
*/
|
||||
|
||||
/*
|
||||
stat_t cm_run_qf(nvObj_t *nv)
|
||||
{
|
||||
cm_request_queue_flush();
|
||||
return (STAT_OK);
|
||||
}
|
||||
*/
|
||||
|
||||
stat_t cm_run_home(nvObj_t *nv)
|
||||
{
|
||||
|
||||
+50
-42
@@ -98,6 +98,12 @@ typedef enum {
|
||||
MOTION_RUN // machine is in motion: set when the steppers execute an ALINE segment
|
||||
} cmMotionState;
|
||||
|
||||
typedef enum { // state machine for cycle start
|
||||
CYCLE_START_NONE = 0, // not in a cycle
|
||||
CYCLE_START_REQUESTED,
|
||||
CYCLE_START_COMPLETE
|
||||
} cmCycleState;
|
||||
|
||||
typedef enum {
|
||||
CYCLE_NONE = 0, // not in a cycle
|
||||
CYCLE_MACHINING, // in normal machining cycle
|
||||
@@ -108,33 +114,27 @@ typedef enum {
|
||||
// ...
|
||||
} cmCycleType;
|
||||
|
||||
typedef enum { // cycle start and feedhold requests
|
||||
OPERATION_NULL = 0, // no operation; reverts here when complete
|
||||
OPERATION_CYCLE_START, // perform a cycle start with no other actions
|
||||
OPERATION_HOLD, // feedhold in p1 or p2 with no entry actions
|
||||
// OPERATION_HOLD_WITH_ACTIONS,// feedhold into p2 with entry actions
|
||||
// OPERATION_P1_FAST_HOLD, // perform a fast hold in p1
|
||||
// OPERATION_HOLD_TO_SYNC, // hold in p1 or p2, skip remainder of move; exec SYNC command or flush
|
||||
OPERATION_EXIT_HOLD_RESUME, // exit p1 or p2 hold and resume motion in p1 planner
|
||||
OPERATION_EXIT_HOLD_FLUSH, // exit p1 or p2 hold and flush p1 planner
|
||||
OPERATION_JOB_KILL, // fast hold followed by queue flush and program end
|
||||
OPERATION_END_JOG, // fast hold followed by program stop
|
||||
OPERATION_SOFT_LIMIT_HIT, // actions to run when a soft limit is hit
|
||||
OPERATION_HARD_LIMIT_HIT, // actions to run when a hard limit is hit
|
||||
OPERATION_SHUTDOWN, // actions to run when a shutdown is received
|
||||
OPERATION_PANIC, // actions to run when a panic is received
|
||||
OPERATION_INTERLOCK_START, // enter an interlock state
|
||||
OPERATION_INTERLOCK_END, // exit interlocked state
|
||||
OPERATION_DI_FUNC_STOP, // run digital input STOP function
|
||||
OPERATION_DI_FUNC_FAST_STOP,// run digital input FAST_STOP function
|
||||
OPERATION_DI_FUNC_HALT, // run digital input HALT function
|
||||
OPERATION_TOOL_CHANGE // run a tool change sequence
|
||||
} cmOperationType;
|
||||
typedef enum { // feedhold type parameter
|
||||
FEEDHOLD_TYPE_ACTIONS = 0, // feedhold at max jerk with actions
|
||||
FEEDHOLD_TYPE_NO_ACTIONS, // feedhold at max jerk with no actions
|
||||
FEEDHOLD_TYPE_SYNC, // feedhold at max jerk with queue flush and sync command
|
||||
FEEDHOLD_TYPE_FAST, // feedhold at high jerk with no actions. Can resume
|
||||
FEEDHOLD_TYPE_SCRAM // feedhold at high jerk and stop all active devices
|
||||
} cmFeedholdType;
|
||||
|
||||
typedef enum { // feedhold final operation
|
||||
FEEDHOLD_FINAL_NONE = 0, // normal final state - HOLD or STOP, depending on type
|
||||
FEEDHOLD_FINAL_STOP, // perform program stop
|
||||
FEEDHOLD_FINAL_END, // perform program end
|
||||
FEEDHOLD_FINAL_ALARM, // perform alarm
|
||||
FEEDHOLD_FINAL_SHUTDOWN, // perform shutdown
|
||||
FEEDHOLD_FINAL_INTERLOCK // report as interlock
|
||||
} cmFeedholdFinal;
|
||||
|
||||
typedef enum { // feedhold state machine
|
||||
FEEDHOLD_P1_EXIT = -1, // set when p1 feedhold is due to exit
|
||||
// FEEDHOLD_P1_EXIT = -1, // set when p1 feedhold is due to exit
|
||||
FEEDHOLD_OFF = 0, // no feedhold in effect
|
||||
// FEEDHOLD_INITIATED, // feedhold has been requested but not started yet
|
||||
FEEDHOLD_REQUESTED, // feedhold has been requested but not started yet
|
||||
FEEDHOLD_SYNC, // start hold - sync to latest aline segment
|
||||
FEEDHOLD_DECEL_CONTINUE, // in deceleration that will not end at zero
|
||||
FEEDHOLD_DECEL_TO_ZERO, // in deceleration that will go to zero
|
||||
@@ -153,7 +153,7 @@ typedef enum { // feedhold state machine
|
||||
FEEDHOLD_HOLD_EXIT_PENDING, // performing exit actions
|
||||
FEEDHOLD_HOLD_EXIT_DONE, // completed exit actions
|
||||
|
||||
FEEDHOLD_P2_EXIT // set when p2 feedhold is finishing
|
||||
// FEEDHOLD_P2_EXIT // set when p2 feedhold is finishing
|
||||
} cmFeedholdState;
|
||||
|
||||
typedef enum { // applies to cm->homing_state
|
||||
@@ -273,24 +273,31 @@ typedef struct cmMachine { // struct to manage canonical machin
|
||||
cfgAxis_t a[AXES];
|
||||
|
||||
// gcode power-on default settings - defaults are not the same as the gm state
|
||||
cmCoordSystem default_coord_system; // G10 active coordinate system default
|
||||
cmCanonicalPlane default_select_plane; // G17,G18,G19 reset default
|
||||
cmUnitsMode default_units_mode; // G20,G21 reset default
|
||||
cmPathControl default_path_control; // G61,G61.1,G64 reset default
|
||||
cmDistanceMode default_distance_mode; // G90,G91 reset default
|
||||
cmCoordSystem default_coord_system; // G10 active coordinate system default
|
||||
cmCanonicalPlane default_select_plane; // G17,G18,G19 reset default
|
||||
cmUnitsMode default_units_mode; // G20,G21 reset default
|
||||
cmPathControl default_path_control; // G61,G61.1,G64 reset default
|
||||
cmDistanceMode default_distance_mode; // G90,G91 reset default
|
||||
|
||||
/**** Runtime variables (PRIVATE) ****/
|
||||
|
||||
// Global state variables and flags
|
||||
|
||||
cmMachineState machine_state; // macs: machine/cycle/motion is the actual machine state
|
||||
cmCycleType cycle_type; // cycs
|
||||
cmMotionState motion_state; // mots
|
||||
cmMachineState machine_state; // macs: machine/cycle/motion is the actual machine state
|
||||
cmCycleType cycle_type; // cycs
|
||||
cmMotionState motion_state; // mots
|
||||
cmCycleState cycle_state; // used to manage cycle start
|
||||
|
||||
cmFeedholdType hold_type; // hold: type of feedhold requested
|
||||
cmFeedholdFinal hold_final; // hold: final state of hold
|
||||
cmFeedholdState hold_state; // hold: feedhold state machine
|
||||
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)
|
||||
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)
|
||||
|
||||
bool request_interlock; // enter interlock
|
||||
bool request_interlock_exit; // exit interlock
|
||||
bool request_job_kill; // ^d - end hold, flush and alarm
|
||||
|
||||
cmOverrideState mfo_state; // feed override state machine
|
||||
|
||||
@@ -485,11 +492,12 @@ stat_t cm_json_wait(char *json_string); // M102
|
||||
|
||||
// Feedhold and related functions (cycle_feedhold.cpp)
|
||||
void cm_operation_init(void);
|
||||
stat_t cm_operation_callback(void); // operation action runner
|
||||
stat_t cm_request_operation(cmOperationType operation, float *param); // request an operation
|
||||
stat_t cm_operation_sequencing_callback(void); // operation action runner
|
||||
|
||||
void cm_request_feedhold(void);
|
||||
void cm_request_exit_hold(void);
|
||||
void cm_request_alarm(void);
|
||||
void cm_request_fasthold(void);
|
||||
void cm_request_cycle_start(void);
|
||||
void cm_request_feedhold(cmFeedholdType type, cmFeedholdFinal final);
|
||||
void cm_request_queue_flush(void);
|
||||
stat_t cm_feedhold_sequencing_callback(void); // process feedhold, cycle start and queue flush requests
|
||||
stat_t cm_feedhold_command_blocker(void);
|
||||
@@ -523,7 +531,7 @@ stat_t cm_clr(nvObj_t *nv); // clear alarm a
|
||||
void cm_clear(void); // raw clear command
|
||||
void cm_parse_clear(const char *s); // parse gcode for M30 or M2 clear condition
|
||||
stat_t cm_is_alarmed(void); // return non-zero status if alarm, shutdown or panic
|
||||
void cm_halt_all(void); // halt motion, spindle and coolant
|
||||
void cm_halt(void); // halt motion, spindle, coolant, heaters
|
||||
void cm_halt_motion(void); // halt motion (immediate stop) but not spindle & other IO
|
||||
stat_t cm_alarm(const stat_t status, const char *msg); // enter alarm state - preserve Gcode state
|
||||
stat_t cm_shutdown(const stat_t status, const char *msg); // enter shutdown state - dump all state
|
||||
@@ -574,7 +582,7 @@ stat_t cm_get_g92(nvObj_t *nv); // get g92 offset
|
||||
stat_t cm_get_g28(nvObj_t *nv); // get g28 offset
|
||||
stat_t cm_get_g30(nvObj_t *nv); // get g30 offset
|
||||
|
||||
stat_t cm_run_qf(nvObj_t *nv); // run queue flush
|
||||
//stat_t cm_run_qf(nvObj_t *nv); // run queue flush
|
||||
stat_t cm_run_home(nvObj_t *nv); // start homing cycle
|
||||
|
||||
//stat_t cm_dam(nvObj_t *nv); // dump active model (debugging command)
|
||||
|
||||
@@ -667,7 +667,7 @@ const cfgItem_t cfgArray[] = {
|
||||
{ "", "qi", _f0, 0, qr_print_qi, qi_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers added to queue
|
||||
{ "", "qo", _f0, 0, qr_print_qo, qo_get, set_nul, (float *)&cs.null, 0 }, // get queue value - buffers removed from queue
|
||||
{ "", "er", _f0, 0, tx_print_nul, rpt_er, set_nul, (float *)&cs.null, 0 }, // get bogus exception report for testing
|
||||
{ "", "qf", _f0, 0, tx_print_nul, get_nul, cm_run_qf, (float *)&cs.null, 0 }, // SET to invoke queue flush
|
||||
// { "", "qf", _f0, 0, tx_print_nul, get_nul, cm_run_qf, (float *)&cs.null, 0 }, // SET to invoke queue flush
|
||||
{ "", "rx", _f0, 0, tx_print_int, get_rx, set_nul, (float *)&cs.null, 0 }, // get RX buffer bytes or packets
|
||||
{ "", "dw", _f0, 0, tx_print_int, st_get_dw, set_noop, (float *)&cs.null, 0 }, // get dwell time remaining
|
||||
{ "", "msg", _f0, 0, tx_print_str, get_nul, set_noop, (float *)&cs.null, 0 }, // no operation on messages
|
||||
|
||||
@@ -159,10 +159,10 @@ static void _controller_HSM()
|
||||
DISPATCH(sr_status_report_callback()); // conditionally send status report
|
||||
DISPATCH(qr_queue_report_callback()); // conditionally send queue report
|
||||
|
||||
// DISPATCH(cm_feedhold_sequencing_callback());// feedhold state machine runner
|
||||
// DISPATCH(cm_feedhold_sequencing_callback());// feedhold state machine runner +++++
|
||||
DISPATCH(mp_planner_callback()); // motion planner
|
||||
DISPATCH(cm_arc_callback(cm)); // arc generation runs as a cycle above lines
|
||||
DISPATCH(cm_operation_callback()); // operation action runner
|
||||
DISPATCH(cm_operation_sequencing_callback());// operation action runner
|
||||
|
||||
DISPATCH(cm_homing_cycle_callback()); // homing cycle operation (G28.2)
|
||||
DISPATCH(cm_probing_cycle_callback()); // probing cycle operation (G38.2)
|
||||
@@ -238,9 +238,10 @@ static void _dispatch_kernel(const devflags_t flags)
|
||||
}
|
||||
|
||||
// trap single character commands
|
||||
if (*cs.bufp == '!') { cm_request_feedhold(); }
|
||||
if (*cs.bufp == '!') { cm_request_feedhold(FEEDHOLD_TYPE_ACTIONS, FEEDHOLD_FINAL_NONE); }
|
||||
else if (*cs.bufp == '%') { cm_request_queue_flush(); xio_flush_to_command(); }
|
||||
else if (*cs.bufp == '~') { cm_request_exit_hold(); }
|
||||
// else if (*cs.bufp == '~') { cm_request_exit_hold(); } +++++
|
||||
else if (*cs.bufp == '~') { cm_request_cycle_start(); }
|
||||
else if (*cs.bufp == EOT) { cm_job_kill(); }
|
||||
else if (*cs.bufp == ENQ) { controller_request_enquiry(); }
|
||||
else if (*cs.bufp == CAN) { hw_hard_reset(); } // reset immediately
|
||||
@@ -434,7 +435,7 @@ static stat_t _interlock_handler(void)
|
||||
if (cm->safety_interlock_disengaged != 0) {
|
||||
cm->safety_interlock_disengaged = 0;
|
||||
cm->safety_interlock_state = SAFETY_INTERLOCK_DISENGAGED;
|
||||
cm_request_feedhold(); // may have already requested STOP as INPUT_ACTION
|
||||
cm_request_feedhold(FEEDHOLD_TYPE_ACTIONS, FEEDHOLD_FINAL_INTERLOCK); // may have already requested STOP as INPUT_ACTION
|
||||
// feedhold was initiated by input action in gpio
|
||||
// pause spindle
|
||||
// pause coolant
|
||||
@@ -444,7 +445,8 @@ static stat_t _interlock_handler(void)
|
||||
if ((cm->safety_interlock_reengaged != 0) && (mp_runtime_is_idle())) {
|
||||
cm->safety_interlock_reengaged = 0;
|
||||
cm->safety_interlock_state = SAFETY_INTERLOCK_ENGAGED; // interlock restored
|
||||
cm_request_exit_hold(); // use cm_request_exit_hold() instead of just ending
|
||||
// cm_request_exit_hold(); // use cm_request_exit_hold() instead of just ending +++++
|
||||
cm_request_cycle_start(); // proper way to restart the cycle
|
||||
}
|
||||
}
|
||||
return(STAT_OK);
|
||||
|
||||
+583
-446
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -169,7 +169,7 @@ struct ioDigitalInputExt {
|
||||
cm_start_hold(); // for now is same as STOP
|
||||
}
|
||||
if (in->action == INPUT_ACTION_HALT) {
|
||||
cm_halt_all(); // hard stop, including spindle and coolant
|
||||
cm_halt(); // hard stop, including spindle, coolant and heaters
|
||||
}
|
||||
if (in->action == INPUT_ACTION_ALARM) {
|
||||
char msg[10];
|
||||
|
||||
@@ -1032,7 +1032,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf)
|
||||
|
||||
// If in a p2 hold, exit the p2 hold immediately set up a flush of the p2 planner queue
|
||||
if (cm == &cm2) {
|
||||
cm->hold_state = FEEDHOLD_P2_EXIT;
|
||||
cm->hold_state = FEEDHOLD_HOLD_EXIT_PENDING;
|
||||
return (STAT_OK); // will end this exec_aline() with no more movement
|
||||
}
|
||||
// At this point we know we are in a p1 hold
|
||||
|
||||
@@ -477,7 +477,6 @@ HeaterFan<kOutput3_PinNumber> heater_fan1;
|
||||
|
||||
/*
|
||||
* temperature_init()
|
||||
* temperature_init() - stop spindle, set speed to zero, and reset values
|
||||
*/
|
||||
void temperature_init()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user