* Synchronizing command execution:
*
* "Synchronous commands" are commands that affect the runtime need
- * to be synchronized with movement. Examples include G4 dwells,
+ * to be synchronized with movement. Examples include G4 dwells,
* program stops and ends, and most M commands. These are queued
- * into the planner queue and execute from the queue. Synchronous
+ * into the planner queue and execute from the queue. Synchronous
* commands work like this:
*
* - Call the mach_xxx_xxx() function which will do any input
};
-// Command execution callbacks from planner queue
-static void _exec_offset(float *value, float *flag);
-static void _exec_change_tool(float *value, float *flag);
-static void _exec_select_tool(float *value, float *flag);
-static void _exec_mist_coolant_control(float *value, float *flag);
-static void _exec_flood_coolant_control(float *value, float *flag);
-static void _exec_absolute_origin(float *value, float *flag);
-
// Machine State functions
uint32_t mach_get_line() {return mach.gm.line;}
-
machMotionMode_t mach_get_motion_mode() {return mach.gm.motion_mode;}
machCoordSystem_t mach_get_coord_system() {return mach.gm.coord_system;}
machUnitsMode_t mach_get_units_mode() {return mach.gm.units_mode;}
}
-// Representation functions that affect gcode model and are queued to planner
-// (synchronous)
-
/// G54-G59
void mach_set_coord_system(machCoordSystem_t coord_system) {
mach.gm.coord_system = coord_system;
-
- // pass coordinate system in value[0] element
- float value[AXES] = {coord_system};
- // second vector (flags) is not used, so fake it
- mp_queue_command(_exec_offset, value, value);
-}
-
-
-static void _exec_offset(float *value, float *flag) {
- // coordinate system is passed in value[0] element
- uint8_t coord_system = value[0];
- float offsets[AXES];
-
- for (int axis = 0; axis < AXES; axis++)
- offsets[axis] = mach.offset[coord_system][axis] +
- mach.origin_offset[axis] * (mach.origin_offset_enable ? 1 : 0);
-
- mp_runtime_set_work_offsets(offsets);
mach_set_work_offsets(); // set work offsets in the Gcode model
}
// G28.3 functions and support
+static void _exec_absolute_origin(float *value, float *flag) {
+ for (int axis = 0; axis < AXES; axis++)
+ if (fp_TRUE(flag[axis])) {
+ mp_runtime_set_position(axis, value[axis]);
+ mach_set_homed(axis, true); // G28.3 is not considered homed until here
+ }
+
+ mp_runtime_set_steps_from_position();
+}
+
/* G28.3 - model, planner and queue to runtime
*
* applies them to all axes where the corresponding position in the
* flag vector is true (1).
*
- * This is a 2 step process. The model and planner contexts are set
+ * This is a 2 step process. The model and planner contexts are set
* immediately, the runtime command is queued and synchronized with
- * the planner queue. This includes the runtime position and the step
- * recording done by the encoders. At that point any axis that is set
+ * the planner queue. This includes the runtime position and the step
+ * recording done by the encoders. At that point any axis that is set
* is also marked as homed.
*/
void mach_set_absolute_origin(float origin[], float flag[]) {
}
-static void _exec_absolute_origin(float *value, float *flag) {
- for (int axis = 0; axis < AXES; axis++)
- if (fp_TRUE(flag[axis])) {
- mp_runtime_set_position(axis, value[axis]);
- mach_set_homed(axis, true); // G28.3 is not considered homed until here
- }
-
- mp_runtime_set_steps_from_position();
-}
-
-
/* G92's behave according to NIST 3.5.18 & LinuxCNC G92
* http://linuxcnc.org/docs/html/gcode/gcode.html#sec:G92-G92.1-G92.2-G92.3
*/
mach.origin_offset[axis] = mach.position[axis] -
mach.offset[mach.gm.coord_system][axis] - TO_MILLIMETERS(offset[axis]);
- // now pass the offset to the callback - setting the coordinate system also
- // applies the offsets
- // pass coordinate system in value[0] element
- float value[AXES] = {mach.gm.coord_system};
- mp_queue_command(_exec_offset, value, value); // second vector is not used
+ mach_set_work_offsets(); // set work offsets in the Gcode model
}
for (int axis = 0; axis < AXES; axis++)
mach.origin_offset[axis] = 0;
- float value[AXES] = {mach.gm.coord_system};
- mp_queue_command(_exec_offset, value, value);
+ mach_set_work_offsets(); // set work offsets in the Gcode model
}
/// G92.2
void mach_suspend_origin_offsets() {
mach.origin_offset_enable = false;
- float value[AXES] = {mach.gm.coord_system};
- mp_queue_command(_exec_offset, value, value);
+ mach_set_work_offsets(); // set work offsets in the Gcode model
}
/// G92.3
void mach_resume_origin_offsets() {
mach.origin_offset_enable = true;
- float value[AXES] = {mach.gm.coord_system};
- mp_queue_command(_exec_offset, value, value);
+ mach_set_work_offsets(); // set work offsets in the Gcode model
}
// prep and plan the move
mach_set_work_offsets(); // capture fully resolved offsets to state
mach.ms.line = mach.gm.line; // copy line number
- mp_aline(&mach.ms); // send the move to the planner
+ status = mp_aline(&mach.ms); // send the move to the planner
mach_finalize_move();
- return STAT_OK;
+ return status;
}
/// G4, P parameter (seconds)
stat_t mach_dwell(float seconds) {
- return mp_dwell(seconds);
+ return mp_dwell(seconds, mach.gm.line);
}
// Spindle Functions (4.3.7) see spindle.c, spindle.h
-/* Tool Functions (4.3.8)
- *
- * Note: These functions don't actually do anything for now, and there's a bug
- * where T and M in different blocks don't work correctly
- */
+// Tool Functions (4.3.8)
/// T parameter
-void mach_select_tool(uint8_t tool_select) {
- float value[AXES] = {tool_select};
- mp_queue_command(_exec_select_tool, value, value);
-}
-
-
-static void _exec_select_tool(float *value, float *flag) {
- mach.gm.tool_select = value[0];
-}
+void mach_select_tool(uint8_t tool_select) {mach.gm.tool_select = tool_select;}
/// M6 This might become a complete tool change cycle
-void mach_change_tool(uint8_t tool_change) {
- float value[AXES] = {mach.gm.tool_select};
- mp_queue_command(_exec_change_tool, value, value);
-}
+void mach_change_tool(uint8_t tool) {mach.gm.tool = tool;}
-static void _exec_change_tool(float *value, float *flag) {
- mach.gm.tool = (uint8_t)value[0];
+// Miscellaneous Functions (4.3.9)
+static void _exec_mist_coolant_control(float *value, float *flag) {
+ coolant_set_mist(value[0]);
}
-// Miscellaneous Functions (4.3.9)
/// M7
void mach_mist_coolant_control(bool mist_coolant) {
+ mach.gm.mist_coolant = mist_coolant;
float value[AXES] = {mist_coolant};
mp_queue_command(_exec_mist_coolant_control, value, value);
}
-static void _exec_mist_coolant_control(float *value, float *flag) {
- coolant_set_mist(mach.gm.mist_coolant = value[0]);
+static void _exec_flood_coolant_control(float *value, float *flag) {
+ coolant_set_flood(value[0]);
+ if (!value[0]) coolant_set_mist(false); // M9 special function
}
/// M8, M9
void mach_flood_coolant_control(bool flood_coolant) {
+ mach.gm.flood_coolant = flood_coolant;
float value[AXES] = {flood_coolant};
mp_queue_command(_exec_flood_coolant_control, value, value);
}
-static void _exec_flood_coolant_control(float *value, float *flag) {
- mach.gm.flood_coolant = value[0];
-
- coolant_set_flood(value[0]);
- if (!value[0]) coolant_set_mist(false); // M9 special function
-}
-
-
/* Override enables are kind of a mess in Gcode. This is an attempt to sort
* them out. See
* http://www.linuxcnc.org/docs/2.4/html/gcode_main.html#sec:M50:-Feed-Override
* It is extended beyond the NIST spec to handle various situations.
*
* mach_program_stop and mach_optional_program_stop are synchronous Gcode
- * commands that are received through the interpreter. They cause all motion
+ * commands that are received through the interpreter. They cause all motion
* to stop at the end of the current command, including spindle motion.
*
* Note that the stop occurs at the end of the immediately preceding command
*/
-/*** _exec_program_end() implements M2 and M30. End behaviors are defined by
+static void _exec_program_stop(float *value, float *flag) {
+ // Machine should be stopped at this point. Go into hold so that a start is
+ // needed before executing further instructions.
+ mp_state_holding();
+}
+
+
+/// M0 Queue a program stop
+void mach_program_stop() {
+ float value[AXES] = {0};
+ mp_queue_command(_exec_program_stop, value, value);
+}
+
+
+/// M1
+void mach_optional_program_stop() {
+ // TODO Check for user stop signal
+ mach_program_stop();
+}
+
+
+/// M60
+void mach_pallet_change_stop() {
+ // TODO Emit pallet change signal
+ mach_program_stop();
+}
+
+
+/*** mach_program_end() implements M2 and M30. End behaviors are defined by
* NIST 3.6.1 are:
*
* 1. Axis offsets are set to zero (like G92.2) and origin offsets are set
* 8. The current motion mode is set to G_1 (like G1)
* 9. Coolant is turned off (like M9)
*
- * _exec_program_end() implements things slightly differently:
+ * mach_program_end() implements things slightly differently:
*
* 1. Axis offsets are set to G92.1 CANCEL offsets
* (instead of using G92.2 SUSPEND Offsets)
* 9. Coolant is turned off (like M9)
* + Default INCHES or MM units mode is restored
*/
-static void _exec_program_end(float *value, float *flag) {
+
+
+/// M2, M30
+void mach_program_end() {
mach_reset_origin_offsets(); // G92.1 - we do G91.1 instead of G92.2
mach_set_coord_system(GCODE_DEFAULT_COORD_SYSTEM);
mach_set_plane(GCODE_DEFAULT_PLANE);
}
-static void _exec_program_stop(float *value, float *flag) {
- // This is ok because we should be already stopped at this point
- mp_state_holding();
-}
-
-
-/// M0 Queue a program stop
-void mach_program_stop() {
- float value[AXES] = {0};
- mp_queue_command(_exec_program_stop, value, value);
-}
-
-
-/// M1
-void mach_optional_program_stop() {
- // TODO Check for user stop signal
- mach_program_stop();
-}
-
-
-/// M60
-void mach_pallet_change_stop() {
- // TODO Emit pallet change signal
- mach_program_stop();
-}
-
-
-/// M2, M30
-void mach_program_end() {
- float value[AXES] = {0};
- mp_queue_command(_exec_program_end, value, value);
-}
-
-
/// return ASCII char for axis given the axis number
char mach_get_axis_char(int8_t axis) {
char axis_char[] = "XYZABC";