Hi,

I've noticed some non-optimal paths during loading of G-code into AXIS,
which are easy to fix...
Please review/apply.

Regards,
Alex.
Optimize G-code loading path

From: Alexey Starikovskiy <[email protected]>

Signed-off-by: Alexey Starikovskiy <[email protected]>
---

 lib/python/rs274/interpret.py   |   36 +++++++++-------
 src/emc/rs274ngc/gcodemodule.cc |   86 ++++++++++++++++-----------------------
 2 files changed, 54 insertions(+), 68 deletions(-)


diff --git a/lib/python/rs274/interpret.py b/lib/python/rs274/interpret.py
index 12fe081..b11636e 100644
--- a/lib/python/rs274/interpret.py
+++ b/lib/python/rs274/interpret.py
@@ -20,13 +20,13 @@ class Translated:
     offset_x = offset_y = offset_z = offset_a = offset_b = offset_c = 0
     rotation_xy = 0
     def rotate_and_translate(self, x,y,z,a,b,c,u,v,w):
-        t = self.rotation_xy
-        t = math.radians(t)
-        rotx = x * math.cos(t) - y * math.sin(t)
-        roty = x * math.sin(t) + y * math.cos(t)
-        rotx += self.offset_x
-        roty += self.offset_y
-        return [rotx, roty, z+self.offset_z,
+	if (self.rotation_xy):
+		t = self.rotation_xy
+		t = math.radians(t)
+		rotx = x * math.cos(t) - y * math.sin(t)
+		y = x * math.sin(t) + y * math.cos(t)
+		x = rotx
+        return [x + self.offset_x, y + self.offset_y, z+self.offset_z,
                 a+self.offset_a, b+self.offset_b, c+self.offset_c,
                 u+self.offset_u, v+self.offset_v, w+self.offset_w]
 
@@ -55,17 +55,19 @@ class ArcsToSegmentsMixin:
 
     def arc_feed(self, x1, y1, cx, cy, rot, z1, a, b, c, u, v, w):
         if self.plane == 1:
-            t = self.rotation_xy
-            t = math.radians(t)
-            rotx = x1 * math.cos(t) - y1 * math.sin(t)
-            roty = x1 * math.sin(t) + y1 * math.cos(t)
-            x1 = rotx
-            y1 = roty
+	    if self.rotation_xy:
+		t = self.rotation_xy
+		t = math.radians(t)
+		rotx = x1 * math.cos(t) - y1 * math.sin(t)
+		roty = x1 * math.sin(t) + y1 * math.cos(t)
+		x1 = rotx
+		y1 = roty
             f = n = [x1+self.offset_x,y1+self.offset_y,z1+self.offset_z, a+self.offset_a, b+self.offset_b, c+self.offset_c, u+self.offset_u, v+self.offset_v, w+self.offset_w]
-            rotcx = cx * math.cos(t) - cy * math.sin(t)
-            rotcy = cx * math.sin(t) + cy * math.cos(t)
-            cx = rotcx
-            cy = rotcy
+	    if self.rotation_xy:
+		rotcx = cx * math.cos(t) - cy * math.sin(t)
+		rotcy = cx * math.sin(t) + cy * math.cos(t)
+		cx = rotcx
+		cy = rotcy
             cx += self.offset_x
             cy += self.offset_y
             xyz = [0,1,2]
diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc
index 04cdec4..3aee4f8 100644
--- a/src/emc/rs274ngc/gcodemodule.cc
+++ b/src/emc/rs274ngc/gcodemodule.cc
@@ -25,14 +25,6 @@
 #include "canon.hh"
 #include "config.h"		// LINELEN
 
-#define active_settings  interp_new.active_settings
-#define active_g_codes   interp_new.active_g_codes
-#define active_m_codes   interp_new.active_m_codes
-#define interp_init	 interp_new.init
-#define interp_open      interp_new.open
-#define interp_close     interp_new.close
-#define interp_read	 interp_new.read
-#define interp_execute	 interp_new.execute
 char _parameter_file_name[LINELEN];
 
 
@@ -153,22 +145,18 @@ bool metric;
 double _pos_x, _pos_y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w;
 EmcPose tool_offset;
 
-Interp interp_new;
+Interp interp;
 
 void maybe_new_line(int line_number) {
-    if(interp_error) return;
+    if(interp_error || line_number == last_sequence_number)
+	    return;
+    last_sequence_number = line_number;
     LineCode *new_line_code =
         (LineCode*)(PyObject_New(LineCode, &LineCodeType));
-    active_settings(new_line_code->settings);
-    active_g_codes(new_line_code->gcodes);
-    active_m_codes(new_line_code->mcodes);
-    int sequence_number = line_number == -1? interp_new.sequence_number(): line_number;
-    new_line_code->gcodes[0] = sequence_number;
-    if(sequence_number == last_sequence_number) {
-        Py_DECREF(new_line_code);
-        return;
-    }
-    last_sequence_number = sequence_number;
+    interp.active_settings(new_line_code->settings);
+    interp.active_g_codes(new_line_code->gcodes);
+    new_line_code->gcodes[0] = line_number;
+    interp.active_m_codes(new_line_code->mcodes);
     PyObject *result = 
         PyObject_CallMethod(callback, "next_line", "O", new_line_code);
     Py_DECREF(new_line_code);
@@ -176,6 +164,10 @@ void maybe_new_line(int line_number) {
     Py_XDECREF(result);
 }
 
+void maybe_new_line(void) {
+	maybe_new_line(interp.sequence_number());
+}
+
 static double TO_PROG_LEN(double p) {
     if(metric) return p*25.4;
     return p;
@@ -185,19 +177,18 @@ void NURBS_FEED(std::vector<CONTROL_POINT> nurbs_control_points, unsigned int k)
     double u = 0.0;
     unsigned int n = nurbs_control_points.size() - 1;
     double umax = n - k + 2;
+    int line_number = interp.sequence_number();
     unsigned int div = nurbs_control_points.size()*15;
-    std::vector<unsigned int> knot_vector = knot_vector_creator(n, k);	
+    std::vector<unsigned int> knot_vector = knot_vector_creator(n, k);
     PLANE_POINT P1;
     while (u+umax/div < umax) {
         PLANE_POINT P1 = nurbs_point(u+umax/div,k,nurbs_control_points,knot_vector);
-        // EBo -- replace 12345 with *whatever* gives us the line_number
-        STRAIGHT_FEED(12345, P1.X,P1.Y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
+        STRAIGHT_FEED(line_number, P1.X,P1.Y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
         u = u + umax/div;
     } 
     P1.X = nurbs_control_points[n].X;
     P1.Y = nurbs_control_points[n].Y;
-    // EBo -- replace 12345 with *whatever* gives us the line_number
-    STRAIGHT_FEED(12345, P1.X,P1.Y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
+    STRAIGHT_FEED(line_number, P1.X,P1.Y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
     knot_vector.clear();
 }
 
@@ -215,8 +206,7 @@ void SPLINE_FEED(double x1, double y1, double x2, double y2) {
       double t0 = (1-t)*(1-t);
       double x = x0*t0 + x1*t1 + x2*t2;
       double y = y0*t0 + y1*t1 + y2*t2;
-      // EBo -- replace 12345 with *whatever* gives us the line_number
-      STRAIGHT_FEED(12345, x,y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
+      STRAIGHT_FEED(interp.sequence_number(), x,y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
     }
 }
 
@@ -232,16 +222,10 @@ void SPLINE_FEED(double x1, double y1, double x2, double y2, double x3, double y
       double x = x0*t0 + x1*t1 + x2*t2 + x3*t3;
       double y = y0*t0 + y1*t1 + y2*t2 + y3*t3;
       // EBo -- replace 12345 with *whatever* gives us the line_number
-      STRAIGHT_FEED(12345, x,y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
+      STRAIGHT_FEED(interp.sequence_number(), x,y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w);
     }
 }
 
-
-void maybe_new_line(void) {
-    maybe_new_line(-1);
-}
-
-
 void ARC_FEED(int line_number,
               double first_end, double second_end, double first_axis,
               double second_axis, int rotation, double axis_end_point,
@@ -329,7 +313,7 @@ void SET_XY_ROTATION(double t) {
 void USE_LENGTH_UNITS(CANON_UNITS u) { metric = u == CANON_UNITS_MM; }
 
 void SELECT_PLANE(CANON_PLANE pl) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "set_plane", "i", pl);
@@ -338,7 +322,7 @@ void SELECT_PLANE(CANON_PLANE pl) {
 }
 
 void SET_TRAVERSE_RATE(double rate) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "set_traverse_rate", "f", rate);
@@ -348,7 +332,7 @@ void SET_TRAVERSE_RATE(double rate) {
 
 void SET_FEED_MODE(int mode) {
 #if 0
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "set_feed_mode", "i", mode);
@@ -377,7 +361,7 @@ void CHANGE_TOOL_NUMBER(int pocket) {
  * time feed wrong anyway..
  */
 void SET_FEED_RATE(double rate) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     if(metric) rate /= 25.4;
     PyObject *result =
@@ -387,7 +371,7 @@ void SET_FEED_RATE(double rate) {
 }
 
 void DWELL(double time) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "dwell", "f", time);
@@ -396,7 +380,7 @@ void DWELL(double time) {
 }
 
 void MESSAGE(char *comment) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "message", "s", comment);
@@ -409,7 +393,7 @@ void LOGOPEN(char *f) {}
 void LOGCLOSE() {}
 
 void COMMENT(char *comment) {
-    maybe_new_line();   
+    maybe_new_line();
     if(interp_error) return;
     PyObject *result =
         PyObject_CallMethod(callback, "comment", "s", comment);
@@ -714,25 +698,25 @@ PyObject *parse_file(PyObject *self, PyObject *args) {
     _pos_x = _pos_y = _pos_z = _pos_a = _pos_b = _pos_c = 0;
     _pos_u = _pos_v = _pos_w = 0;
 
-    interp_init();
-    interp_open(f);
+    interp.init();
+    interp.open(f);
 
     maybe_new_line();
 
     int result = INTERP_OK;
     if(unitcode) {
-        result = interp_read(unitcode);
+        result = interp.read(unitcode);
         if(!RESULT_OK) goto out_error;
-        result = interp_execute();
+        result = interp.execute();
     }
     if(initcode && RESULT_OK) {
-        result = interp_read(initcode);
+        result = interp.read(initcode);
         if(!RESULT_OK) goto out_error;
-        result = interp_execute();
+        result = interp.execute();
     }
     while(!interp_error && RESULT_OK) {
         error_line_offset = 1;
-        result = interp_read();
+        result = interp.read();
         gettimeofday(&t1, NULL);
         if(t1.tv_sec > t0.tv_sec + wait) {
             if(check_abort()) return NULL;
@@ -740,10 +724,10 @@ PyObject *parse_file(PyObject *self, PyObject *args) {
         }
         if(!RESULT_OK) break;
         error_line_offset = 0;
-        result = interp_execute();
+        result = interp.execute();
     }
 out_error:
-    interp_close();
+    interp.close();
     if(interp_error) {
         if(!PyErr_Occurred()) {
             PyErr_Format(PyExc_RuntimeError,
@@ -767,7 +751,7 @@ static char savedError[LINELEN+1];
 static PyObject *rs274_strerror(PyObject *s, PyObject *o) {
     int err;
     if(!PyArg_ParseTuple(o, "i", &err)) return NULL;
-    interp_new.error_text(err, savedError, LINELEN);
+    interp.error_text(err, savedError, LINELEN);
     return PyString_FromString(savedError);
 }
 
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to