Machine encapsulation
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Sat, 10 Sep 2016 12:36:43 +0000 (05:36 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Sat, 10 Sep 2016 12:36:43 +0000 (05:36 -0700)
14 files changed:
src/coolant.c
src/coolant.h
src/gcode_parser.c
src/gcode_parser.h
src/homing.c
src/machine.c
src/machine.h
src/main.c
src/pins.h
src/plan/arc.c
src/plan/planner.c
src/plan/planner.h
src/probing.c
src/varcb.c

index b023c1cb59ebca398f8badf0a37d80ff6bb7b14c..29cac8104317732b283aa3f6f025b1691f38ae45 100644 (file)
@@ -49,3 +49,7 @@ void coolant_set_flood(bool x) {
   if (x) OUTCLR_PIN(SWITCH_2_PIN);
   else OUTSET_PIN(SWITCH_2_PIN);
 }
+
+
+bool coolant_get_mist() {return OUT_PIN(SWITCH_1_PIN);}
+bool coolant_get_flood() {return OUT_PIN(SWITCH_2_PIN);}
index 6ac70ff8782f9d7693e909b897fd8b839bd553fc..f29166f5a62ae32606a1a9f346683091d0b27e33 100644 (file)
@@ -33,3 +33,5 @@
 void coolant_init();
 void coolant_set_mist(bool x);
 void coolant_set_flood(bool x);
+bool coolant_get_mist();
+bool coolant_get_flood();
index e96ec8ab2a9fd5d4e34abd3a6f38055975556492..c6982e966d590539d484cec36e39588ac65eab03 100644 (file)
 #include <math.h>
 
 
+parser_t parser = {{0}};
+
+
 #define SET_MODAL(m, parm, val) \
-  {mach.gn.parm = val; mach.gf.parm = 1; modals[m] += 1; break;}
-#define SET_NON_MODAL(parm, val) {mach.gn.parm = val; mach.gf.parm = 1; break;}
-#define EXEC_FUNC(f, v) if ((uint8_t)mach.gf.v) f(mach.gn.v)
+  {parser.gn.parm = val; parser.gf.parm = 1; modals[m] += 1; break;}
+#define SET_NON_MODAL(parm, val) \
+  {parser.gn.parm = val; parser.gf.parm = 1; break;}
+#define EXEC_FUNC(f, v) if ((uint8_t)parser.gf.v) f(parser.gn.v)
 
 
 static uint8_t modals[MODAL_GROUP_COUNT]; // collects modal groups in a block
@@ -232,7 +236,7 @@ static stat_t _validate_gcode_block() {
 static stat_t _execute_gcode_block() {
   stat_t status = STAT_OK;
 
-  mach_set_model_line(mach.gn.line);
+  mach_set_model_line(parser.gn.line);
   EXEC_FUNC(mach_set_feed_mode, feed_mode);
   EXEC_FUNC(mach_set_feed_rate, feed_rate);
   EXEC_FUNC(mach_feed_override_factor, feed_override_factor);
@@ -247,8 +251,8 @@ static stat_t _execute_gcode_block() {
   EXEC_FUNC(mach_spindle_override_enable, spindle_override_enable);
   EXEC_FUNC(mach_override_enables, override_enables);
 
-  if (mach.gn.next_action == NEXT_ACTION_DWELL) // G4 - dwell
-    RITORNO(mach_dwell(mach.gn.parameter));
+  if (parser.gn.next_action == NEXT_ACTION_DWELL) // G4 - dwell
+    RITORNO(mach_dwell(parser.gn.parameter));
 
   EXEC_FUNC(mach_set_plane, plane);
   EXEC_FUNC(mach_set_units, units);
@@ -259,36 +263,37 @@ static stat_t _execute_gcode_block() {
   EXEC_FUNC(mach_set_distance_mode, distance_mode);
   //--> set retract mode goes here
 
-  switch (mach.gn.next_action) {
+  switch (parser.gn.next_action) {
   case NEXT_ACTION_SET_G28_POSITION: // G28.1
     mach_set_g28_position();
     break;
   case NEXT_ACTION_GOTO_G28_POSITION: // G28
-    status = mach_goto_g28_position(mach.gn.target, mach.gf.target);
+    status = mach_goto_g28_position(parser.gn.target, parser.gf.target);
     break;
   case NEXT_ACTION_SET_G30_POSITION: // G30.1
     mach_set_g30_position();
     break;
   case NEXT_ACTION_GOTO_G30_POSITION: // G30
-    status = mach_goto_g30_position(mach.gn.target, mach.gf.target);
+    status = mach_goto_g30_position(parser.gn.target, parser.gf.target);
     break;
   case NEXT_ACTION_SEARCH_HOME: // G28.2
     mach_homing_cycle_start();
     break;
   case NEXT_ACTION_SET_ABSOLUTE_ORIGIN: // G28.3
-    mach_set_absolute_origin(mach.gn.target, mach.gf.target);
+    mach_set_absolute_origin(parser.gn.target, parser.gf.target);
     break;
   case NEXT_ACTION_HOMING_NO_SET: // G28.4
     mach_homing_cycle_start_no_set();
     break;
   case NEXT_ACTION_STRAIGHT_PROBE: // G38.2
-    status = mach_probe(mach.gn.target, mach.gf.target);
+    status = mach_probe(parser.gn.target, parser.gf.target);
     break;
   case NEXT_ACTION_SET_COORD_DATA:
-    mach_set_coord_offsets(mach.gn.parameter, mach.gn.target, mach.gf.target);
+    mach_set_coord_offsets(parser.gn.parameter, parser.gn.target,
+                           parser.gf.target);
     break;
   case NEXT_ACTION_SET_ORIGIN_OFFSETS:
-    mach_set_origin_offsets(mach.gn.target, mach.gf.target);
+    mach_set_origin_offsets(parser.gn.target, parser.gf.target);
     break;
   case NEXT_ACTION_RESET_ORIGIN_OFFSETS:
     mach_reset_origin_offsets();
@@ -303,24 +308,24 @@ static stat_t _execute_gcode_block() {
 
   case NEXT_ACTION_DEFAULT:
     // apply override setting to gm struct
-    mach_set_absolute_mode(mach.gn.absolute_mode);
+    mach_set_absolute_mode(parser.gn.absolute_mode);
 
-    switch (mach.gn.motion_mode) {
+    switch (parser.gn.motion_mode) {
     case MOTION_MODE_CANCEL_MOTION_MODE:
-      mach.gm.motion_mode = mach.gn.motion_mode;
+      mach_set_motion_mode(parser.gn.motion_mode);
       break;
     case MOTION_MODE_RAPID:
-      status = mach_rapid(mach.gn.target, mach.gf.target);
+      status = mach_rapid(parser.gn.target, parser.gf.target);
       break;
     case MOTION_MODE_FEED:
-      status = mach_feed(mach.gn.target, mach.gf.target);
+      status = mach_feed(parser.gn.target, parser.gf.target);
       break;
     case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC:
       // gf.radius sets radius mode if radius was collected in gn
-      status = mach_arc_feed(mach.gn.target, mach.gf.target,
-                             mach.gn.arc_offset[0], mach.gn.arc_offset[1],
-                             mach.gn.arc_offset[2], mach.gn.arc_radius,
-                             mach.gn.motion_mode);
+      status = mach_arc_feed(parser.gn.target, parser.gf.target,
+                             parser.gn.arc_offset[0], parser.gn.arc_offset[1],
+                             parser.gn.arc_offset[2], parser.gn.arc_radius,
+                             parser.gn.motion_mode);
       break;
     default: break; // Should not get here
     }
@@ -329,8 +334,8 @@ static stat_t _execute_gcode_block() {
   mach_set_absolute_mode(false);
 
   // do the program stops and ends : M0, M1, M2, M30, M60
-  if (mach.gf.program_flow)
-    switch (mach.gn.program_flow) {
+  if (parser.gf.program_flow)
+    switch (parser.gn.program_flow) {
     case PROGRAM_STOP: mach_program_stop(); break;
     case PROGRAM_OPTIONAL_STOP: mach_optional_program_stop(); break;
     case PROGRAM_PALLET_CHANGE_STOP: mach_pallet_change_stop(); break;
@@ -359,11 +364,11 @@ static stat_t _parse_gcode_block(char *buf) {
 
   // set initial state for new move
   memset(modals, 0, sizeof(modals));              // clear all parser values
-  memset(&mach.gf, 0, sizeof(gcode_state_t));     // clear all next-state flags
-  memset(&mach.gn, 0, sizeof(gcode_state_t));     // clear all next-state values
+  memset(&parser.gf, 0, sizeof(gcode_state_t));   // clear all next-state flags
+  memset(&parser.gn, 0, sizeof(gcode_state_t));   // clear all next-state values
 
   // get motion mode from previous block
-  mach.gn.motion_mode = mach_get_motion_mode();
+  parser.gn.motion_mode = mach_get_motion_mode();
 
   // extract commands and parameters
   while ((status = _get_next_gcode_word(&pstr, &letter, &value)) == STAT_OK) {
index 2a7184d43e20a313085bf419b40d88f6170fbd51..4901866103ac05845831a90a070370f1f57787ef 100644 (file)
 
 
 #include "status.h"
+#include "machine.h"
+
+
+typedef struct {
+  gcode_state_t gn;                    // gcode input values
+  gcode_state_t gf;                    // gcode input flags
+} parser_t;
+
+
+extern parser_t parser;
+
 
 stat_t gc_gcode_parser(char *block);
index 70766fd7415850ff13f0c341889fe5d50d7e6e06..4dd4ed6c4826dda4fd7b062a8093a43723add4b9 100644 (file)
@@ -29,6 +29,7 @@
 #include "homing.h"
 #include "machine.h"
 #include "switch.h"
+#include "gcode_parser.h"
 #include "util.h"
 #include "report.h"
 
@@ -168,12 +169,12 @@ static homing_t hm = {0};
  */
 static int8_t _get_next_axis(int8_t axis) {
   switch (axis) {
-  case     -1: if (fp_TRUE(mach.gf.target[AXIS_Z])) return AXIS_Z;
-  case AXIS_Z: if (fp_TRUE(mach.gf.target[AXIS_X])) return AXIS_X;
-  case AXIS_X: if (fp_TRUE(mach.gf.target[AXIS_Y])) return AXIS_Y;
-  case AXIS_Y: if (fp_TRUE(mach.gf.target[AXIS_A])) return AXIS_A;
-  case AXIS_A: if (fp_TRUE(mach.gf.target[AXIS_B])) return AXIS_B;
-  case AXIS_B: if (fp_TRUE(mach.gf.target[AXIS_C])) return AXIS_C;
+  case     -1: if (fp_TRUE(parser.gf.target[AXIS_Z])) return AXIS_Z;
+  case AXIS_Z: if (fp_TRUE(parser.gf.target[AXIS_X])) return AXIS_X;
+  case AXIS_X: if (fp_TRUE(parser.gf.target[AXIS_Y])) return AXIS_Y;
+  case AXIS_Y: if (fp_TRUE(parser.gf.target[AXIS_A])) return AXIS_A;
+  case AXIS_A: if (fp_TRUE(parser.gf.target[AXIS_B])) return AXIS_B;
+  case AXIS_B: if (fp_TRUE(parser.gf.target[AXIS_C])) return AXIS_C;
   }
 
   return axis == -1 ? -2 : -1; // error or done
@@ -189,7 +190,7 @@ static void _homing_finalize_exit() {
   mach_set_units(hm.saved_units);
   mach_set_distance_mode(hm.saved_distance_mode);
   mach_set_feed_mode(hm.saved_feed_mode);
-  mach.gm.feed_rate = hm.saved_feed_rate;
+  mach_set_feed_rate(hm.saved_feed_rate);
   mach_set_motion_mode(MOTION_MODE_CANCEL_MOTION_MODE);
 }
 
@@ -207,7 +208,7 @@ static void _homing_axis_move(int8_t axis, float target, float velocity) {
 
   vect[axis] = target;
   flags[axis] = true;
-  mach.gm.feed_rate = velocity;
+  mach_set_feed_rate(velocity);
   mp_flush_planner(); // don't use mp_request_flush() here
 
   stat_t status = mach_feed(vect, flags);
index 4aa5455ae7393583908e4875fcab6c3269666513..cfb687ff4ea24ac8177becc1d5458e7d3abab52f 100644 (file)
@@ -64,7 +64,7 @@
 #include "machine.h"
 
 #include "config.h"
-#include "stepper.h"
+#include "gcode_parser.h"
 #include "spindle.h"
 #include "coolant.h"
 #include "switch.h"
@@ -182,25 +182,37 @@ machine_t mach = {
 
   // State
   .gm = {.motion_mode = MOTION_MODE_CANCEL_MOTION_MODE},
-  .gn = {0},
-  .gf = {0},
 };
 
 
 // Machine State functions
 uint32_t mach_get_line() {return mach.gm.line;}
+uint8_t mach_get_tool() {return mach.gm.tool;}
+float mach_get_feed_rate() {return mach.gm.feed_rate;}
+feed_mode_t mach_get_feed_mode() {return mach.gm.feed_mode;}
+
+
+float mach_get_feed_override() {
+  return mach.gm.feed_override_enable ? mach.gm.feed_override_factor : 0;
+}
+
+
+float mach_get_spindle_override() {
+  return mach.gm.spindle_override_enable ? mach.gm.spindle_override_factor : 0;
+}
+
+
 motion_mode_t mach_get_motion_mode() {return mach.gm.motion_mode;}
-coord_system_t mach_get_coord_system() {return mach.gm.coord_system;}
-units_t mach_get_units() {return mach.gm.units;}
 plane_t mach_get_plane() {return mach.gm.plane;}
+units_t mach_get_units() {return mach.gm.units;}
+coord_system_t mach_get_coord_system() {return mach.gm.coord_system;}
+bool mach_get_absolute_mode() {return mach.gm.absolute_mode;}
 path_mode_t mach_get_path_mode() {return mach.gm.path_mode;}
 distance_mode_t mach_get_distance_mode() {return mach.gm.distance_mode;}
-feed_mode_t mach_get_feed_mode() {return mach.gm.feed_mode;}
-uint8_t mach_get_tool() {return mach.gm.tool;}
-float mach_get_feed_rate() {return mach.gm.feed_rate;}
+distance_mode_t mach_get_arc_distance_mode() {return mach.gm.arc_distance_mode;}
 
 
-PGM_P mp_get_units_pgmstr(units_t mode) {
+PGM_P mach_get_units_pgmstr(units_t mode) {
   switch (mode) {
   case INCHES:      return PSTR("IN");
   case MILLIMETERS: return PSTR("MM");
@@ -211,7 +223,7 @@ PGM_P mp_get_units_pgmstr(units_t mode) {
 }
 
 
-PGM_P mp_get_feed_mode_pgmstr(feed_mode_t mode) {
+PGM_P mach_get_feed_mode_pgmstr(feed_mode_t mode) {
   switch (mode) {
   case INVERSE_TIME_MODE:         return PSTR("INVERSE TIME");
   case UNITS_PER_MINUTE_MODE:     return PSTR("PER MIN");
@@ -222,7 +234,7 @@ PGM_P mp_get_feed_mode_pgmstr(feed_mode_t mode) {
 }
 
 
-PGM_P mp_get_plane_pgmstr(plane_t plane) {
+PGM_P mach_get_plane_pgmstr(plane_t plane) {
   switch (plane) {
   case PLANE_XY: return PSTR("XY");
   case PLANE_XZ: return PSTR("XZ");
@@ -233,7 +245,7 @@ PGM_P mp_get_plane_pgmstr(plane_t plane) {
 }
 
 
-PGM_P mp_get_coord_system_pgmstr(coord_system_t cs) {
+PGM_P mach_get_coord_system_pgmstr(coord_system_t cs) {
   switch (cs) {
   case ABSOLUTE_COORDS: return PSTR("ABS");
   case G54: return PSTR("G54");
@@ -248,7 +260,7 @@ PGM_P mp_get_coord_system_pgmstr(coord_system_t cs) {
 }
 
 
-PGM_P mp_get_path_mode_pgmstr(path_mode_t mode) {
+PGM_P mach_get_path_mode_pgmstr(path_mode_t mode) {
   switch (mode) {
   case PATH_EXACT_PATH: return PSTR("EXACT PATH");
   case PATH_EXACT_STOP: return PSTR("EXACT STOP");
@@ -259,7 +271,7 @@ PGM_P mp_get_path_mode_pgmstr(path_mode_t mode) {
 }
 
 
-PGM_P mp_get_distance_mode_pgmstr(distance_mode_t mode) {
+PGM_P mach_get_distance_mode_pgmstr(distance_mode_t mode) {
   switch (mode) {
   case ABSOLUTE_MODE:    return PSTR("ABSOLUTE");
   case INCREMENTAL_MODE: return PSTR("INCREMENTAL");
@@ -913,7 +925,7 @@ stat_t mach_dwell(float seconds) {
 stat_t mach_feed(float target[], float flags[]) {
   // trap zero feed rate condition
   if (fp_ZERO(mach.gm.feed_rate) ||
-      (mach.gm.feed_mode == INVERSE_TIME_MODE && !mach.gf.feed_rate))
+      (mach.gm.feed_mode == INVERSE_TIME_MODE && !parser.gf.feed_rate))
     return STAT_GCODE_FEEDRATE_NOT_SPECIFIED;
 
   mach.gm.motion_mode = MOTION_MODE_FEED;
@@ -952,7 +964,6 @@ static void _exec_mist_coolant_control(float *value, float *flag) {
 
 /// M7
 void mach_mist_coolant_control(bool mist_coolant) {
-  mach.gm.mist_coolant = mist_coolant;
   float value[AXES] = {mist_coolant};
   mp_command_queue(_exec_mist_coolant_control, value, value);
 }
@@ -966,7 +977,6 @@ static void _exec_flood_coolant_control(float *value, float *flag) {
 
 /// M8, M9
 void mach_flood_coolant_control(bool flood_coolant) {
-  mach.gm.flood_coolant = flood_coolant;
   float value[AXES] = {flood_coolant};
   mp_command_queue(_exec_flood_coolant_control, value, value);
 }
@@ -986,7 +996,7 @@ void mach_override_enables(bool flag) {
 
 /// M50
 void mach_feed_override_enable(bool flag) {
-  if (fp_TRUE(mach.gf.parameter) && fp_ZERO(mach.gn.parameter))
+  if (fp_TRUE(parser.gf.parameter) && fp_ZERO(parser.gn.parameter))
     mach.gm.feed_override_enable = false;
   else mach.gm.feed_override_enable = true;
 }
@@ -995,13 +1005,13 @@ void mach_feed_override_enable(bool flag) {
 /// M50
 void mach_feed_override_factor(bool flag) {
   mach.gm.feed_override_enable = flag;
-  mach.gm.feed_override_factor = mach.gn.parameter;
+  mach.gm.feed_override_factor = parser.gn.parameter;
 }
 
 
 /// M51
 void mach_spindle_override_enable(bool flag) {
-  if (fp_TRUE(mach.gf.parameter) && fp_ZERO(mach.gn.parameter))
+  if (fp_TRUE(parser.gf.parameter) && fp_ZERO(parser.gn.parameter))
     mach.gm.spindle_override_enable = false;
   else mach.gm.spindle_override_enable = true;
 }
@@ -1010,7 +1020,7 @@ void mach_spindle_override_enable(bool flag) {
 /// M51
 void mach_spindle_override_factor(bool flag) {
   mach.gm.spindle_override_enable = flag;
-  mach.gm.spindle_override_factor = mach.gn.parameter;
+  mach.gm.spindle_override_factor = parser.gn.parameter;
 }
 
 
index 1014c55aaa83ebef7d3fe6aaef28ce473eb2241d..e4e7965ea3333bc50f39822b7208dae7361f59e3 100644 (file)
@@ -215,7 +215,7 @@ typedef enum {
  *     from gm.
  *
  * - gf is used by the gcode parser interpreter to hold flags for any
- *     data that has changed in gn during the parse. mach.gf.target[]
+ *     data that has changed in gn during the parse. parser.gf.target[]
  *     values are also used by the machine during
  *     set_target().
  */
@@ -248,7 +248,7 @@ typedef struct {
   distance_mode_t arc_distance_mode;  // G91.1
 
   bool mist_coolant;                  // true = mist on (M7), false = off (M9)
-  bool flood_coolant;                 // true = flood on (M8), false = off (M9)
+  bool flood_coolant;                 // true = mist on (M8), false = off (M9)
 
   next_action_t next_action;          // handles G group 1 moves & non-modals
   program_flow_t program_flow;        // used only by the gcode_parser
@@ -287,19 +287,16 @@ typedef struct {
 
 
 typedef struct { // struct to manage mach globals and cycles
-  // coordinate systems & offsets absolute (G53) + G54, G55, G56, G57, G58, G59
-  float offset[COORDS + 1][AXES];
+  float offset[COORDS + 1][AXES];      // coordinate systems & offsets G53-G59
   float origin_offset[AXES];           // G92 offsets
-  bool origin_offset_enable;           // G92 offsets enabled/disabled
+  bool origin_offset_enable;           // G92 offsets enabled / disabled
 
-  float position[AXES];                // model position (not used in gn or gf)
+  float position[AXES];                // model position
   float g28_position[AXES];            // stored machine position for G28
   float g30_position[AXES];            // stored machine position for G30
 
   axis_config_t a[AXES];               // settings for axes
   gcode_state_t gm;                    // core gcode model state
-  gcode_state_t gn;                    // gcode input values
-  gcode_state_t gf;                    // gcode input flags
 } machine_t;
 
 
@@ -308,22 +305,26 @@ extern machine_t mach;                 // machine controller singleton
 
 // Model state getters and setters
 uint32_t mach_get_line();
+uint8_t mach_get_tool();
+float mach_get_feed_rate();
+feed_mode_t mach_get_feed_mode();
+float mach_get_feed_override();
+float mach_get_spindle_override();
 motion_mode_t mach_get_motion_mode();
-coord_system_t mach_get_coord_system();
-units_t mach_get_units();
 plane_t mach_get_plane();
+units_t mach_get_units();
+coord_system_t mach_get_coord_system();
+bool mach_get_absolute_mode();
 path_mode_t mach_get_path_mode();
 distance_mode_t mach_get_distance_mode();
-feed_mode_t mach_get_feed_mode();
-uint8_t mach_get_tool();
-float mach_get_feed_rate();
-
-PGM_P mp_get_units_pgmstr(units_t mode);
-PGM_P mp_get_feed_mode_pgmstr(feed_mode_t mode);
-PGM_P mp_get_plane_pgmstr(plane_t plane);
-PGM_P mp_get_coord_system_pgmstr(coord_system_t cs);
-PGM_P mp_get_path_mode_pgmstr(path_mode_t mode);
-PGM_P mp_get_distance_mode_pgmstr(distance_mode_t mode);
+distance_mode_t mach_get_arc_distance_mode();
+
+PGM_P mach_get_units_pgmstr(units_t mode);
+PGM_P mach_get_feed_mode_pgmstr(feed_mode_t mode);
+PGM_P mach_get_plane_pgmstr(plane_t plane);
+PGM_P mach_get_coord_system_pgmstr(coord_system_t cs);
+PGM_P mach_get_path_mode_pgmstr(path_mode_t mode);
+PGM_P mach_get_distance_mode_pgmstr(distance_mode_t mode);
 
 void mach_set_motion_mode(motion_mode_t motion_mode);
 void mach_set_spindle_mode(spindle_mode_t spindle_mode);
index 59aa05e0951a10a782001281e1f300340fef273e..90521deae0819d1f619d582f20e01ef1784da2d7 100644 (file)
@@ -67,7 +67,7 @@ int main() {
   stepper_init();                 // steppers
   motor_init();                   // motors
   switch_init();                  // switches
-  planner_init();                 // motion planning
+  mp_init();                 // motion planning
   machine_init();                 // gcode machine
   vars_init();                    // configuration variables
   estop_init();                   // emergency stop handler
index 75a4fc10d1aee67e413f9381f392db17e2f0dca7..b4ce92fad6c456289f64d49380383e69dd1ad780 100644 (file)
@@ -42,5 +42,6 @@ extern PORT_t *pin_ports[];
 #define OUTCLR_PIN(PIN) PORT(PIN)->OUTCLR = BM(PIN)
 #define OUTSET_PIN(PIN) PORT(PIN)->OUTSET = BM(PIN)
 #define OUTTGL_PIN(PIN) PORT(PIN)->OUTTGL = BM(PIN)
+#define OUT_PIN(PIN) (!!(PORT(PIN)->OUT & BM(PIN)))
 #define IN_PIN(PIN) (!!(PORT(PIN)->IN & BM(PIN)))
 #define PINCTRL_PIN(PIN) ((&PORT(PIN)->PIN0CTRL)[PIN & 7])
index 21147aa91dc9c1144bb17a4dc0cf90627343b5f3..aa50a3fe504ae3622886c96a2fff6104f5f2e65f 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "buffer.h"
 #include "line.h"
+#include "gcode_parser.h"
 #include "config.h"
 #include "util.h"
 
@@ -80,8 +81,8 @@ static float _estimate_arc_time(float length, float linear_travel,
                                 float planar_travel) {
   // Determine move time at requested feed rate
   // Inverse feed rate is normalized to minutes
-  float time = mach.gm.feed_mode == INVERSE_TIME_MODE ?
-    mach.gm.feed_rate : length / mach.gm.feed_rate;
+  float time = mach_get_feed_mode() == INVERSE_TIME_MODE ?
+    mach_get_feed_rate() : length / mach_get_feed_rate();
 
   // Downgrade the time if there is a rate-limiting axis
   return max4(time, planar_travel / mach.a[arc.plane_axis_0].feedrate_max,
@@ -188,7 +189,7 @@ static stat_t _compute_arc_offsets_from_radius(float offset[]) {
   float h_x2_div_d = disc > 0 ? -sqrt(disc) / hypotf(x, y) : 0;
 
   // Invert sign of h_x2_div_d if circle is counter clockwise (see header notes)
-  if (mach.gm.motion_mode == MOTION_MODE_CCW_ARC) h_x2_div_d = -h_x2_div_d;
+  if (mach_get_motion_mode() == MOTION_MODE_CCW_ARC) h_x2_div_d = -h_x2_div_d;
 
   // Negative R is g-code-alese for "I want a circle with more than 180 degrees
   // of travel" (go figure!), even though it is advised against ever generating
@@ -258,7 +259,7 @@ static stat_t _compute_arc(const float position[], float offset[],
 
   // g18_correction is used to invert G18 XZ plane arcs for proper CW
   // orientation
-  float g18_correction = mach.gm.plane == PLANE_XZ ? -1 : 1;
+  float g18_correction = mach_get_plane() == PLANE_XZ ? -1 : 1;
   float angular_travel = 0;
 
   if (full_circle) {
@@ -284,13 +285,13 @@ static stat_t _compute_arc(const float position[], float offset[],
       angular_travel = theta_end - arc.theta;
 
       // reverse travel direction if it's CCW arc
-      if (mach.gm.motion_mode == MOTION_MODE_CCW_ARC)
+      if (mach_get_motion_mode() == MOTION_MODE_CCW_ARC)
         angular_travel -= 2 * M_PI * g18_correction;
     }
   }
 
   // Add in travel for rotations
-  if (mach.gm.motion_mode == MOTION_MODE_CW_ARC)
+  if (mach_get_motion_mode() == MOTION_MODE_CW_ARC)
     angular_travel += 2 * M_PI * rotations * g18_correction;
   else angular_travel -= 2 * M_PI * rotations * g18_correction;
 
@@ -343,15 +344,15 @@ stat_t mach_arc_feed(float target[], float flags[], // arc endpoints
                      float radius,  // non-zero radius implies radius mode
                      uint8_t motion_mode) { // defined motion mode
   // trap missing feed rate
-  if (fp_ZERO(mach.gm.feed_rate) ||
-      (mach.gm.feed_mode == INVERSE_TIME_MODE && !mach.gf.feed_rate))
+  if (fp_ZERO(mach_get_feed_rate()) ||
+      (mach_get_feed_mode() == INVERSE_TIME_MODE && !parser.gf.feed_rate))
     return STAT_GCODE_FEEDRATE_NOT_SPECIFIED;
 
   // set radius mode flag and do simple test(s)
-  bool radius_f = fp_NOT_ZERO(mach.gf.arc_radius);  // set true if radius arc
+  bool radius_f = fp_NOT_ZERO(parser.gf.arc_radius);  // set true if radius arc
 
   // radius value must be + and > minimum radius
-  if (radius_f && mach.gn.arc_radius < MIN_ARC_RADIUS)
+  if (radius_f && parser.gn.arc_radius < MIN_ARC_RADIUS)
     return STAT_ARC_RADIUS_OUT_OF_TOLERANCE;
 
   // setup some flags
@@ -359,15 +360,15 @@ stat_t mach_arc_feed(float target[], float flags[], // arc endpoints
   bool target_y = fp_NOT_ZERO(flags[AXIS_Y]);
   bool target_z = fp_NOT_ZERO(flags[AXIS_Z]);
 
-  bool offset_i = fp_NOT_ZERO(mach.gf.arc_offset[0]); // is offset I specified
-  bool offset_j = fp_NOT_ZERO(mach.gf.arc_offset[1]); // J
-  bool offset_k = fp_NOT_ZERO(mach.gf.arc_offset[2]); // K
+  bool offset_i = fp_NOT_ZERO(parser.gf.arc_offset[0]); // is offset I specified
+  bool offset_j = fp_NOT_ZERO(parser.gf.arc_offset[1]); // J
+  bool offset_k = fp_NOT_ZERO(parser.gf.arc_offset[2]); // K
 
   // Set the arc plane for the current G17/G18/G19 setting and test arc
   // specification Plane axis 0 and 1 are the arc plane, the linear axis is
   // normal to the arc plane.
   // G17 - the vast majority of arcs are in the G17 (XY) plane
-  switch (mach.gm.plane) {
+  switch (mach_get_plane()) {
   case PLANE_XY:
     arc.plane_axis_0 = AXIS_X;
     arc.plane_axis_1 = AXIS_Y;
@@ -417,14 +418,14 @@ stat_t mach_arc_feed(float target[], float flags[], // arc endpoints
     return STAT_ARC_ENDPOINT_IS_STARTING_POINT;
 
   // now get down to the rest of the work setting up the arc for execution
-  mach.gm.motion_mode = motion_mode;
+  mach_set_motion_mode(motion_mode);
   mach_update_work_offsets();                      // Update resolved offsets
-  arc.line = mach.gm.line;                         // copy line number
+  arc.line = mach_get_line();                      // copy line number
   copy_vector(arc.target, mach.gm.target);         // copy move target
   arc.radius = TO_MILLIMETERS(radius);             // set arc radius or zero
 
   float offset[3] = {TO_MILLIMETERS(i), TO_MILLIMETERS(j), TO_MILLIMETERS(k)};
-  float rotations = floor(fabs(mach.gn.parameter)); // P must be positive int
+  float rotations = floor(fabs(parser.gn.parameter)); // P must be positive int
 
   // determine if this is a full circle arc. Evaluates true if no target is set
   bool full_circle =
index 7498430e80cf4795c157c45cc069ded72a4d808b..9e626606ad669b7f61e13daa19427b868f57c682 100644 (file)
@@ -72,7 +72,7 @@
 static float mp_position[AXES]; // final move position for planning purposes
 
 
-void planner_init() {mp_queue_init();}
+void mp_init() {mp_queue_init();}
 
 
 /// Set planner position for a single axis
index 6e32c9226e0e6420e86f31293989bcff2c0a6a7e..f6adb485af3c921f838a86bb7a3c200d91327fa8 100644 (file)
@@ -72,7 +72,7 @@ typedef enum {
 } move_section_t;
 
 
-void planner_init();
+void mp_init();
 void mp_set_axis_position(int axis, float position);
 float mp_get_axis_position(int axis);
 void mp_set_position(const float position[]);
index 3850d297c2e7ac1767b4d1cf28a6350093399341..afb852c2a0e48e61ba710ea456ac50ab1764a795 100644 (file)
@@ -192,7 +192,8 @@ bool mach_is_probing() {
 /// G38.2 homing cycle using limit switches
 stat_t mach_probe(float target[], float flags[]) {
   // trap zero feed rate condition
-  if (mach.gm.feed_mode != INVERSE_TIME_MODE && fp_ZERO(mach.gm.feed_rate))
+  if (mach_get_feed_mode() != INVERSE_TIME_MODE &&
+      fp_ZERO(mach_get_feed_rate()))
     return STAT_GCODE_FEEDRATE_NOT_SPECIFIED;
 
   // trap no axes specified
index e81fd4fe70c26f3fa2061e1e0eeb8b323df19731..4a339da47021d37ea2e6b22a2abde72b91fdb95f 100644 (file)
@@ -29,6 +29,7 @@
 #include "usart.h"
 #include "machine.h"
 #include "spindle.h"
+#include "coolant.h"
 #include "plan/runtime.h"
 #include "plan/state.h"
 
@@ -37,51 +38,43 @@ float get_position(int index) {return mp_runtime_get_axis_position(index);}
 
 // GCode
 int32_t get_line() {return mp_runtime_get_line();}
-PGM_P get_unit() {return mp_get_units_pgmstr(mach_get_units());}
+PGM_P get_unit() {return mach_get_units_pgmstr(mach_get_units());}
 float get_speed() {return spindle_get_speed();}
 float get_feed() {return mach_get_feed_rate();}
 uint8_t get_tool() {return mach_get_tool();}
 
 
 PGM_P get_feed_mode() {
-  return mp_get_feed_mode_pgmstr(mach.gm.feed_mode);
+  return mach_get_feed_mode_pgmstr(mach_get_feed_mode());
 }
 
 
-PGM_P get_plane() {return mp_get_plane_pgmstr(mach.gm.plane);}
+PGM_P get_plane() {return mach_get_plane_pgmstr(mach_get_plane());}
 
 
 PGM_P get_coord_system() {
-  return mp_get_coord_system_pgmstr(mach.gm.coord_system);
+  return mach_get_coord_system_pgmstr(mach_get_coord_system());
 }
 
 
-bool get_abs_override() {return mach.gm.absolute_mode;}
-PGM_P get_path_mode() {return mp_get_path_mode_pgmstr(mach.gm.path_mode);}
+bool get_abs_override() {return mach_get_absolute_mode();}
+PGM_P get_path_mode() {return mach_get_path_mode_pgmstr(mach_get_path_mode());}
 
 
 PGM_P get_distance_mode() {
-  return mp_get_distance_mode_pgmstr(mach.gm.distance_mode);
+  return mach_get_distance_mode_pgmstr(mach_get_distance_mode());
 }
 
 
 PGM_P get_arc_dist_mode() {
-  return mp_get_distance_mode_pgmstr(mach.gm.arc_distance_mode);
+  return mach_get_distance_mode_pgmstr(mach_get_arc_distance_mode());
 }
 
 
-float get_feed_override() {
-  return mach.gm.feed_override_enable ? mach.gm.feed_override_factor : 0;
-}
-
-
-float get_speed_override() {
-  return mach.gm.spindle_override_enable ? mach.gm.spindle_override_factor : 0;
-}
-
-
-bool get_mist_coolant() {return mach.gm.mist_coolant;}
-bool get_flood_coolant() {return mach.gm.flood_coolant;}
+float get_feed_override() {return mach_get_feed_override();}
+float get_speed_override() {return mach_get_spindle_override();}
+bool get_mist_coolant() {return coolant_get_mist();}
+bool get_flood_coolant() {return coolant_get_flood();}
 
 // System
 float get_velocity() {return mp_runtime_get_velocity();}