Here is the last version of the patches.
Rotation now works somewhat better -- please see 3dtest.ngc
I'll take a look at your patch tomorrow, falling asleep right now...
Thanks,
Alex.
Jeff Epler пишет:
> On Fri, Mar 12, 2010 at 01:42:22AM +0300, Alexey Starikovskiy wrote:
>
>> @@ -50,6 +50,8 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
>> self.lo = (0,) * 9
>> self.first_move = True
>> self.offset_x = self.offset_y = self.offset_z = 0
>> + self.offset_a = self.offset_b = self.offset_c = 0
>> + self.offset_u = self.offset_v = self.offset_w = 0
>> self.geometry = geometry
>> self.min_extents = [9e99,9e99,9e99]
>> self.max_extents = [-9e99,-9e99,-9e99]
>>
>
> I know emc is far from consistent on this, but if you can please try to
> follow the surrounding style as far as spaces vs tabs goes. This file
> is all or almost all spaces, and few or no tabs.
>
>
>> diff --git a/nc_files/systems.ngc b/nc_files/systems.ngc
>> index 1594b66..6f49b61 100644
>> --- a/nc_files/systems.ngc
>> +++ b/nc_files/systems.ngc
>>
>
> This shouldn't be here
>
>
>> +#define max(a,b) (a)>(b)?(a):(b)
>>
>
> I know we don't use a lot of the C++ standard library, but consider
> using std::min instead.
>
>
>> void ARC_FEED(int line_number,
>>
> ...
> doesn't this change mean that *no* user of gcodemodule can get actual
> arc moves anymore, only offset and rotated straightened moves? This is
> a big change for the other, possibly hypothetical users of the gcode
> module.
>
>
>> + int steps = max(3, int(32 * abs(theta1 - theta2) / M_PI));
>>
>
> Please remember that changing the default number of arc segments is a
> different discussion.
>
>
>> + PyObject_CallMethod(callback, "straight_arcsegment",
>> "fffffffff",
>> + p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
>> p[8]);
>>
>
> In some changes I haven't shown yet, I found a nice speed bump from
> gathering up all the segments on an arc in a list, and passing them in a
> single call to a new method 'straight_arcsegments'.
>
>
>> void STRAIGHT_TRAVERSE(int line_number,
>> double x, double y, double z,
>> double a, double b, double c,
>>
> Again, by moving offsetting and rotation into here, you're making a big
> change for the other, possibly hypothetical users of the gcode module.
>
> Jeff
>
> ------------------------------------------------------------------------------
> Download Intel® 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
>
Remove LineCode class. The only used member 'plane' is available directly.
From: Alexey Starikovskiy <[email protected]>
Signed-off-by: Alexey Starikovskiy <[email protected]>
---
lib/python/rs274/glcanon.py | 11 ++--
src/emc/rs274ngc/gcodemodule.cc | 118 ---------------------------------------
2 files changed, 6 insertions(+), 123 deletions(-)
diff --git a/lib/python/rs274/glcanon.py b/lib/python/rs274/glcanon.py
index d28706a..8a629e1 100644
--- a/lib/python/rs274/glcanon.py
+++ b/lib/python/rs274/glcanon.py
@@ -60,6 +60,7 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
self.xo = self.yo = self.zo = self.ao = self.bo = self.co = self.uo = self.vo = self.wo = 0
self.dwell_time = 0
self.suppress = 0
+ self.plane = 1
def comment(self, arg):
if arg.startswith("AXIS,"):
@@ -73,9 +74,8 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def check_abort(self): pass
- def next_line(self, st):
- self.state = st
- self.lineno = self.state.sequence_number
+ def next_line(self, lineno):
+ self.lineno = lineno
def draw_lines(self, lines, for_selection, j=0):
return emc.draw_lines(self.geometry, lines, for_selection)
@@ -141,7 +141,6 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def set_spindle_rate(self, arg): pass
def set_feed_rate(self, arg): self.feedrate = arg / 60.
- def select_plane(self, arg): pass
def change_tool(self, arg):
self.first_move = True
@@ -200,13 +199,13 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def user_defined_function(self, i, p, q):
if self.suppress > 0: return
color = self.colors['m1xx']
- self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.state.plane/10-17))
+ self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.plane - 1))
def dwell(self, arg):
if self.suppress > 0: return
self.dwell_time += arg
color = self.colors['dwell']
- self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.state.plane/10-17))
+ self.dwells_append((self.lineno, color, self.lo[0], self.lo[1], self.lo[2], self.plane - 1))
def highlight(self, lineno, geometry):
diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc
index 80d2671..95c46af 100644
--- a/src/emc/rs274ngc/gcodemodule.cc
+++ b/src/emc/rs274ngc/gcodemodule.cc
@@ -27,113 +27,6 @@
char _parameter_file_name[LINELEN];
-
-/* This definition of offsetof avoids the g++ warning
- * 'invalid offsetof from non-POD type'.
- */
-#undef offsetof
-#define offsetof(T,x) (size_t)(-1+(char*)&(((T*)1)->x))
-
-
-static PyObject *int_array(int *arr, int sz) {
- PyObject *res = PyTuple_New(sz);
- for(int i = 0; i < sz; i++) {
- PyTuple_SET_ITEM(res, i, PyInt_FromLong(arr[i]));
- }
- return res;
-}
-
-typedef struct {
- PyObject_HEAD
- double settings[ACTIVE_SETTINGS];
- int gcodes[ACTIVE_G_CODES];
- int mcodes[ACTIVE_M_CODES];
-} LineCode;
-
-static PyObject *LineCode_gcodes(LineCode *l) {
- return int_array(l->gcodes, ACTIVE_G_CODES);
-}
-static PyObject *LineCode_mcodes(LineCode *l) {
- return int_array(l->mcodes, ACTIVE_M_CODES);
-}
-
-static PyGetSetDef LineCodeGetSet[] = {
- {"gcodes", (getter)LineCode_gcodes},
- {"mcodes", (getter)LineCode_mcodes},
- {NULL, NULL},
-};
-
-static PyMemberDef LineCodeMembers[] = {
- {"sequence_number", T_INT, offsetof(LineCode, gcodes[0]), READONLY},
-
- {"feed_rate", T_DOUBLE, offsetof(LineCode, settings[1]), READONLY},
- {"speed", T_DOUBLE, offsetof(LineCode, settings[2]), READONLY},
- {"motion_mode", T_INT, offsetof(LineCode, gcodes[1]), READONLY},
- {"block", T_INT, offsetof(LineCode, gcodes[2]), READONLY},
- {"plane", T_INT, offsetof(LineCode, gcodes[3]), READONLY},
- {"cutter_side", T_INT, offsetof(LineCode, gcodes[4]), READONLY},
- {"units", T_INT, offsetof(LineCode, gcodes[5]), READONLY},
- {"distance_mode", T_INT, offsetof(LineCode, gcodes[6]), READONLY},
- {"feed_mode", T_INT, offsetof(LineCode, gcodes[7]), READONLY},
- {"origin", T_INT, offsetof(LineCode, gcodes[8]), READONLY},
- {"tool_length_offset", T_INT, offsetof(LineCode, gcodes[9]), READONLY},
- {"retract_mode", T_INT, offsetof(LineCode, gcodes[10]), READONLY},
- {"path_mode", T_INT, offsetof(LineCode, gcodes[11]), READONLY},
-
- {"stopping", T_INT, offsetof(LineCode, mcodes[1]), READONLY},
- {"spindle", T_INT, offsetof(LineCode, mcodes[2]), READONLY},
- {"toolchange", T_INT, offsetof(LineCode, mcodes[3]), READONLY},
- {"mist", T_INT, offsetof(LineCode, mcodes[4]), READONLY},
- {"flood", T_INT, offsetof(LineCode, mcodes[5]), READONLY},
- {"overrides", T_INT, offsetof(LineCode, mcodes[6]), READONLY},
- {NULL}
-};
-
-static PyTypeObject LineCodeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "gcode.linecode", /*tp_name*/
- sizeof(LineCode), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- 0, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- 0, /*tp_doc*/
- 0, /*tp_traverse*/
- 0, /*tp_clear*/
- 0, /*tp_richcompare*/
- 0, /*tp_weaklistoffset*/
- 0, /*tp_iter*/
- 0, /*tp_iternext*/
- 0, /*tp_methods*/
- LineCodeMembers, /*tp_members*/
- LineCodeGetSet, /*tp_getset*/
- 0, /*tp_base*/
- 0, /*tp_dict*/
- 0, /*tp_descr_get*/
- 0, /*tp_descr_set*/
- 0, /*tp_dictoffset*/
- 0, /*tp_init*/
- 0, /*tp_alloc*/
- PyType_GenericNew, /*tp_new*/
- 0, /*tp_free*/
- 0, /*tp_is_gc*/
-};
-
static PyObject *callback;
static int interp_error;
static int last_sequence_number;
@@ -148,16 +41,9 @@ static void maybe_new_line(int sequence_number) {
if(interp_error) return;
if(sequence_number == last_sequence_number)
return;
- LineCode *new_line_code =
- (LineCode*)(PyObject_New(LineCode, &LineCodeType));
- interp_new.active_settings(new_line_code->settings);
- interp_new.active_g_codes(new_line_code->gcodes);
- interp_new.active_m_codes(new_line_code->mcodes);
- new_line_code->gcodes[0] = sequence_number;
last_sequence_number = sequence_number;
PyObject *result =
- PyObject_CallMethod(callback, "next_line", "O", new_line_code);
- Py_DECREF(new_line_code);
+ PyObject_CallMethod(callback, "next_line", "i", sequence_number);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
}
@@ -761,8 +647,6 @@ PyMODINIT_FUNC
initgcode(void) {
PyObject *m = Py_InitModule3("gcode", gcode_methods,
"Interface to EMC rs274ngc interpreter");
- PyType_Ready(&LineCodeType);
- PyModule_AddObject(m, "linecode", (PyObject*)&LineCodeType);
PyObject_SetAttrString(m, "MAX_ERROR", PyInt_FromLong(maxerror));
PyObject_SetAttrString(m, "MIN_ERROR",
PyInt_FromLong(INTERP_MIN_ERROR));
Move Translate and ArcsSegments into C
From: Alexey Starikovskiy <[email protected]>
Signed-off-by: Alexey Starikovskiy <[email protected]>
---
lib/python/rs274/__init__.py | 18 ---
lib/python/rs274/glcanon.py | 26 ++--
lib/python/rs274/interpret.py | 99 ----------------
src/emc/rs274ngc/gcodemodule.cc | 204 +++++++++++++++++++++++++--------
src/emc/usr_intf/axis/scripts/axis.py | 1
5 files changed, 169 insertions(+), 179 deletions(-)
diff --git a/lib/python/rs274/__init__.py b/lib/python/rs274/__init__.py
index 1f513f2..e69de29 100644
--- a/lib/python/rs274/__init__.py
+++ b/lib/python/rs274/__init__.py
@@ -1,18 +0,0 @@
-# This is a component of AXIS, a front-end for emc
-# Copyright 2004, 2005, 2006 Jeff Epler <[email protected]>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-from interpret import Translated, ArcsToSegmentsMixin
diff --git a/lib/python/rs274/glcanon.py b/lib/python/rs274/glcanon.py
index 8a629e1..aa820e9 100644
--- a/lib/python/rs274/glcanon.py
+++ b/lib/python/rs274/glcanon.py
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from rs274 import Translated, ArcsToSegmentsMixin, OpenGLTk
+from rs274 import OpenGLTk
from minigl import *
import math
import glnav
@@ -35,7 +35,7 @@ limiticon = array.array('B',
255, 255, 176, 0, 152, 0, 140, 0, 134, 0, 128, 0, 0, 0,
0, 0, 0, 0])
-class GLCanon(Translated, ArcsToSegmentsMixin):
+class GLCanon:
def __init__(self, colors, geometry):
# traverse list - [line number, [start position], [end position], [tlo x, tlo y, tlo z]]
self.traverse = []; self.traverse_append = self.traverse.append
@@ -50,6 +50,8 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
self.lo = (0,) * 9
self.first_move = True
self.offset_x = self.offset_y = self.offset_z = 0
+ self.offset_a = self.offset_b = self.offset_c = 0
+ self.offset_u = self.offset_v = self.offset_w = 0
self.geometry = geometry
self.min_extents = [9e99,9e99,9e99]
self.max_extents = [-9e99,-9e99,-9e99]
@@ -77,6 +79,9 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def next_line(self, lineno):
self.lineno = lineno
+ def set_plane(self, plane):
+ self.plane = plane
+
def draw_lines(self, lines, for_selection, j=0):
return emc.draw_lines(self.geometry, lines, for_selection)
@@ -145,6 +150,9 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def change_tool(self, arg):
self.first_move = True
+ def set_xy_rotation(self, theta):
+ self.rotation_xy = theta
+
def set_origin_offsets(self, offset_x, offset_y, offset_z, offset_a, offset_b, offset_c, offset_u, offset_v, offset_w):
self.offset_x = offset_x
self.offset_y = offset_y
@@ -158,7 +166,7 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def straight_traverse(self, x,y,z, a,b,c, u, v, w):
if self.suppress > 0: return
- l = self.rotate_and_translate(x,y,z,a,b,c,u,v,w)
+ l = (x,y,z,a,b,c,u,v,w)
if not self.first_move:
self.traverse_append((self.lineno, self.lo, l, [self.xo, self.yo, self.zo]))
self.lo = l
@@ -166,21 +174,13 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def rigid_tap(self, x, y, z):
if self.suppress > 0: return
self.first_move = False
- l = self.rotate_and_translate(x,y,z,0,0,0,0,0,0)[:3]
- l += [self.lo[3], self.lo[4], self.lo[5],
- self.lo[6], self.lo[7], self.lo[8]]
+ l = [x, y, z, self.lo[3], self.lo[4], self.lo[5], self.lo[6], self.lo[7], self.lo[8]]
self.feed_append((self.lineno, self.lo, l, self.feedrate, [self.xo, self.yo, self.zo]))
self.dwells_append((self.lineno, self.colors['dwell'], x + self.offset_x, y + self.offset_y, z + self.offset_z, 0))
self.feed_append((self.lineno, l, self.lo, self.feedrate, [self.xo, self.yo, self.zo]))
def arc_feed(self, *args):
- if self.suppress > 0: return
self.first_move = False
- self.in_arc = True
- try:
- ArcsToSegmentsMixin.arc_feed(self, *args)
- finally:
- self.in_arc = False
def straight_arcsegment(self, x,y,z, a,b,c, u, v, w):
self.first_move = False
@@ -191,7 +191,7 @@ class GLCanon(Translated, ArcsToSegmentsMixin):
def straight_feed(self, x,y,z, a,b,c, u, v, w):
if self.suppress > 0: return
self.first_move = False
- l = self.rotate_and_translate(x,y,z,a,b,c,u,v,w)
+ l = (x,y,z,a,b,c,u,v,w)
self.feed_append((self.lineno, self.lo, l, self.feedrate, [self.xo, self.yo, self.zo]))
self.lo = l
straight_probe = straight_feed
diff --git a/lib/python/rs274/interpret.py b/lib/python/rs274/interpret.py
index 7c0fb26..56d0f78 100644
--- a/lib/python/rs274/interpret.py
+++ b/lib/python/rs274/interpret.py
@@ -16,105 +16,6 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import math
-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
- if t:
- 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]
-
- def straight_traverse(self, *args):
- self.straight_traverse_translated(*self.rotate_and_translate(*args))
- def straight_feed(self, *args):
- self.straight_feed_translated(*self.rotate_and_translate(*args))
- def set_origin_offsets(self, offset_x, offset_y, offset_z, offset_a, offset_b, offset_c, offset_u=None, offset_v=None, offset_w=None):
- self.offset_x = offset_x
- self.offset_y = offset_y
- self.offset_z = offset_z
- self.offset_a = offset_a
- self.offset_b = offset_b
- self.offset_c = offset_c
- self.offset_u = offset_u
- self.offset_v = offset_v
- self.offset_w = offset_w
- def set_xy_rotation(self, theta):
- self.rotation_xy = theta
-
-class ArcsToSegmentsMixin:
- plane = 1
-
- def set_plane(self, plane):
- self.plane = plane
-
- def arc_feed(self, x1, y1, cx, cy, rot, z1, a, b, c, u, v, w):
- if self.plane == 1:
- t = self.rotation_xy
- if t:
- 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]
- if t:
- 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]
- elif self.plane == 3:
- f = n = [y1+self.offset_x,z1+self.offset_y,x1+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]
- cx=cx+self.offset_z
- cy=cy+self.offset_x
- xyz = [2,0,1]
- else:
- f = n = [z1+self.offset_x,x1+self.offset_y,y1+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]
- cx=cx+self.offset_y
- cy=cy+self.offset_z
- xyz = [1,2,0]
- o = self.lo[:]
- theta1 = math.atan2(o[xyz[1]]-cy, o[xyz[0]]-cx)
- theta2 = math.atan2(n[xyz[1]]-cy, n[xyz[0]]-cx)
-
- # these ought to be the same, but go ahead and display them if not, for debugging
- rad1 = math.hypot(o[xyz[0]]-cx, o[xyz[1]]-cy)
- rad2 = math.hypot(n[xyz[0]]-cx, n[xyz[1]]-cy)
-
- if rot < 0:
- if theta2 >= theta1: theta2 -= math.pi * 2
- else:
- if theta2 <= theta1: theta2 += math.pi * 2
-
- def interp(low, high):
- return low + (high-low) * i / steps
-
- steps = max(8, int(128 * abs(theta1 - theta2) / math.pi))
- p = [0] * 9
- for i in range(1, steps):
- theta = interp(theta1, theta2)
- rad = interp(rad1, rad2)
- p[xyz[0]] = math.cos(theta) * rad + cx
- p[xyz[1]] = math.sin(theta) * rad + cy
- p[xyz[2]] = interp(o[xyz[2]], n[xyz[2]])
- p[3] = interp(o[3], n[3])
- p[4] = interp(o[4], n[4])
- p[5] = interp(o[5], n[5])
- p[6] = interp(o[6], n[6])
- p[7] = interp(o[7], n[7])
- p[8] = interp(o[8], n[8])
- self.straight_arcsegment(*p)
- self.straight_arcsegment(*n)
-
class PrintCanon:
def set_origin_offsets(self, *args):
print "set_origin_offsets", args
diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc
index 95c46af..793fff6 100644
--- a/src/emc/rs274ngc/gcodemodule.cc
+++ b/src/emc/rs274ngc/gcodemodule.cc
@@ -32,10 +32,36 @@ static int interp_error;
static int last_sequence_number;
static bool metric;
static double _pos_x, _pos_y, _pos_z, _pos_a, _pos_b, _pos_c, _pos_u, _pos_v, _pos_w;
+static int plane = 1;
+static double offset[9] = {0};
+static double lo[9] = {0};
+static double rotation_xy = 0, rotation_sin = 0, rotation_cos = 1;
+
EmcPose tool_offset;
static Interp interp_new;
+static void rotate_and_translate(double p[9])
+{
+ if (rotation_xy) {
+ double rotx = p[0] * rotation_cos - p[1] * rotation_sin;
+ p[1] = p[0] * rotation_sin + p[1] * rotation_cos;
+ p[0] = rotx;
+ }
+ for (int i = 0; i < 9; ++i)
+ p[i] += offset[i];
+}
+static void reverse_rot(double p[9])
+{
+ for (int i = 0; i < 9; ++i)
+ p[i] -= offset[i];
+ if (rotation_xy) {
+ double rotx = p[0] * rotation_cos + p[1] * rotation_sin;
+ p[1] = -p[0] * rotation_sin + p[1] * rotation_cos;
+ p[0] = rotx;
+ }
+}
+
static void maybe_new_line(int sequence_number=interp_new.sequence_number());
static void maybe_new_line(int sequence_number) {
if(interp_error) return;
@@ -108,86 +134,150 @@ void SPLINE_FEED(double x1, double y1, double x2, double y2, double x3, double y
}
}
+inline double interp(double low, double high, double ratio) {
+ return low + (high - low) * ratio;
+}
+
void ARC_FEED(int line_number,
- double first_end, double second_end, double first_axis,
- double second_axis, int rotation, double axis_end_point,
- double a_position, double b_position, double c_position,
- double u_position, double v_position, double w_position) {
- // XXX: set _pos_*
- if(metric) {
- first_end /= 25.4;
- second_end /= 25.4;
- first_axis /= 25.4;
- second_axis /= 25.4;
- axis_end_point /= 25.4;
- u_position /= 25.4;
- v_position /= 25.4;
- w_position /= 25.4;
+ double e1, double e2, double c1, double c2, int rot, double e3,
+ double a, double b, double c, double u, double v, double w) {
+ if (metric) {
+ e1 /= 25.4; e2 /= 25.4; c1 /= 25.4; c2 /= 25.4; e3 /= 25.4;
+ u /= 25.4; v /= 25.4; w /= 25.4;
}
maybe_new_line(line_number);
if(interp_error) return;
- PyObject *result =
- PyObject_CallMethod(callback, "arc_feed", "ffffifffffff",
- first_end, second_end, first_axis, second_axis,
- rotation, axis_end_point,
- a_position, b_position, c_position,
- u_position, v_position, w_position);
- if(result == NULL) interp_error ++;
- Py_XDECREF(result);
+ int xyz[3];
+ double n[9];
+ if (plane == 1) {
+ xyz[0] = 0; xyz[1] = 1; xyz[2] = 2;
+ } else if (plane == 3) {
+ xyz[0] = 2; xyz[1] = 0; xyz[2] = 1;
+ } else {
+ xyz[0] = 1; xyz[1] = 2; xyz[2] = 0;
+ }
+ n[xyz[0]] = e1;
+ n[xyz[1]] = e2;
+ n[xyz[2]] = e3;
+ n[3] = a;
+ n[4] = b;
+ n[5] = c;
+ n[6] = u;
+ n[7] = v;
+ n[8] = w;
+ double old[9];
+ for (int i = 0; i < 9; ++i) old[i] = lo[i];
+ reverse_rot(old);
+ double theta1 = atan2(old[xyz[1]] - c2, old[xyz[0]] - c1);
+ double theta2 = atan2(n[xyz[1]] - c2, n[xyz[0]] - c1);
+ if (rot < 0) {
+ if (theta2 >= theta1)
+ theta2 -= M_PI * 2;
+ } else {
+ if (theta2 <= theta1)
+ theta2 += M_PI * 2;
+ }
+
+ int steps = std::max(8, int(128 * abs(theta1 - theta2) / M_PI));
+ double theta = (theta2 - theta1)/(steps - 1);
+ double t1 = old[xyz[0]] - c1;
+ double t2 = old[xyz[1]] - c2;
+ double cos_t = cos(theta);
+ double sin_t = sin(theta);
+ double p[9];
+ for (int i = 0; i < steps; ++i) {
+ double ratio = double(i)/(steps - 1);
+ double t = cos_t * t1 - sin_t * t2;
+ t2 = sin_t * t1 + cos_t * t2;
+ t1 = t;
+ p[xyz[0]] = t1 + c1;
+ p[xyz[1]] = t2 + c2;
+ p[xyz[2]] = interp(old[xyz[2]], n[xyz[2]], ratio);
+ for (int j = 3; j < 9; ++j)
+ p[j] = interp(old[j], n[j], ratio);
+ rotate_and_translate(p);
+ PyObject *result =
+ PyObject_CallMethod(callback, "straight_arcsegment", "fffffffff",
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);
+ if(result == NULL) interp_error ++;
+ Py_XDECREF(result);
+ }
+ for (int i = 0; i < 9; ++i) lo[i] = p[i];
}
void STRAIGHT_FEED(int line_number,
double x, double y, double z,
double a, double b, double c,
- double u, double v, double w) {
- _pos_x=x; _pos_y=y; _pos_z=z;
+ double u, double v, double w)
+{
+ _pos_x=x; _pos_y=y; _pos_z=z;
_pos_a=a; _pos_b=b; _pos_c=c;
_pos_u=u; _pos_v=v; _pos_w=w;
- if(metric) { x /= 25.4; y /= 25.4; z /= 25.4; u /= 25.4; v /= 25.4; w /= 25.4; }
+
+ double p[9] = {x,y,z,a,b,c,u,v,w};
+ if (metric) {
+ for (int i = 0; i < 3; ++i) p[i] /= 25.4;
+ for (int i = 6; i < 9; ++i) p[i] /= 25.4;
+ }
maybe_new_line(line_number);
if(interp_error) return;
+ rotate_and_translate(p);
PyObject *result =
PyObject_CallMethod(callback, "straight_feed", "fffffffff",
- x, y, z, a, b, c, u, v, w);
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
+ for (int i = 0; i < 9; ++i) lo[i] = p[i];
}
void STRAIGHT_TRAVERSE(int line_number,
double x, double y, double z,
double a, double b, double c,
- double u, double v, double w) {
- _pos_x=x; _pos_y=y; _pos_z=z;
+ double u, double v, double w)
+{
+ _pos_x=x; _pos_y=y; _pos_z=z;
_pos_a=a; _pos_b=b; _pos_c=c;
_pos_u=u; _pos_v=v; _pos_w=w;
- if(metric) { x /= 25.4; y /= 25.4; z /= 25.4; u /= 25.4; v /= 25.4; w /= 25.4; }
+
+ double p[9] = {x,y,z,a,b,c,u,v,w};
+ if (metric) {
+ for (int i = 0; i < 3; ++i) p[i] /= 25.4;
+ for (int i = 6; i < 9; ++i) p[i] /= 25.4;
+ }
maybe_new_line(line_number);
if(interp_error) return;
+ rotate_and_translate(p);
PyObject *result =
PyObject_CallMethod(callback, "straight_traverse", "fffffffff",
- x, y, z, a, b, c, u, v, w);
+ p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
+ for (int i = 0; i < 9; ++i) lo[i] = p[i];
}
void SET_ORIGIN_OFFSETS(double x, double y, double z,
double a, double b, double c,
double u, double v, double w) {
- if(metric) { x /= 25.4; y /= 25.4; z /= 25.4; u /= 25.4; v /= 25.4; w /= 25.4; }
+ if (metric) {
+ x /= 25.4; y /= 25.4; z /= 25.4; u /= 25.4; v /= 25.4; w /= 25.4;
+ }
+ offset[0] = x; offset[1] = y; offset[2] = z; offset[3] = a, offset[4] = b, offset[5] = c, offset[6] = u, offset[7] = v, offset[8] = w;
maybe_new_line();
- if(interp_error) return;
+ if (interp_error) return;
PyObject *result =
- PyObject_CallMethod(callback, "set_origin_offsets", "fffffffff",
+ PyObject_CallMethod(callback, "set_origin_offsets", "fffffffff",
x, y, z, a, b, c, u, v, w);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
}
void SET_XY_ROTATION(double t) {
+ rotation_xy = t * M_PI / 180;
+ rotation_sin = sin(rotation_xy);
+ rotation_cos = cos(rotation_xy);
maybe_new_line();
if(interp_error) return;
- PyObject *result =
- PyObject_CallMethod(callback, "set_xy_rotation", "f", t);
+ PyObject *result = PyObject_CallMethod(callback, "set_xy_rotation", "f", t);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
};
@@ -195,8 +285,10 @@ 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();
+ plane = pl;
+ maybe_new_line();
if(interp_error) return;
+
PyObject *result =
PyObject_CallMethod(callback, "set_plane", "i", pl);
if(result == NULL) interp_error ++;
@@ -243,7 +335,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 =
@@ -253,7 +345,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);
@@ -262,7 +354,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);
@@ -275,7 +367,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);
@@ -287,17 +379,26 @@ void SET_TOOL_TABLE_ENTRY(int pocket, int toolno, EmcPose offset, double diamete
double frontangle, double backangle, int orientation) {
}
-void USE_TOOL_LENGTH_OFFSET(EmcPose offset) {
- tool_offset = offset;
+void USE_TOOL_LENGTH_OFFSET(EmcPose o) {
maybe_new_line();
if(interp_error) return;
if(metric) {
- offset.tran.x /= 25.4; offset.tran.y /= 25.4; offset.tran.z /= 25.4;
- offset.u /= 25.4; offset.v /= 25.4; offset.w /= 25.4; }
- PyObject *result = PyObject_CallMethod(callback, "tool_offset", "ddddddddd", offset.tran.x, offset.tran.y, offset.tran.z,
- offset.a, offset.b, offset.c, offset.u, offset.v, offset.w);
+ o.tran.x /= 25.4; o.tran.y /= 25.4; o.tran.z /= 25.4;
+ o.u /= 25.4; o.v /= 25.4; o.w /= 25.4; }
+ PyObject *result = PyObject_CallMethod(callback, "tool_offset", "ddddddddd", o.tran.x, o.tran.y, o.tran.z,
+ o.a, o.b, o.c, o.u, o.v, o.w);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
+ lo[0] -= tool_offset.tran.x - o.tran.x;
+ lo[1] -= tool_offset.tran.y - o.tran.y;
+ lo[2] -= tool_offset.tran.z - o.tran.z;
+ lo[3] -= tool_offset.a - o.a;
+ lo[4] -= tool_offset.b - o.b;
+ lo[5] -= tool_offset.c - o.c;
+ lo[6] -= tool_offset.u - o.u;
+ lo[7] -= tool_offset.v - o.v;
+ lo[8] -= tool_offset.w - o.w;
+ tool_offset = o;
}
void SET_FEED_REFERENCE(double reference) { }
@@ -374,11 +475,14 @@ void RIGID_TAP(int line_number,
if(metric) { x /= 25.4; y /= 25.4; z /= 25.4; }
maybe_new_line(line_number);
if(interp_error) return;
+ double p[9] = {x, y, z, 0, 0, 0, 0, 0, 0};
+ rotate_and_translate(p);
PyObject *result =
PyObject_CallMethod(callback, "rigid_tap", "fff",
- x, y, z);
+ p[0], p[1], p[2]);
if(result == NULL) interp_error ++;
Py_XDECREF(result);
+ for (int i = 0; i < 3; ++i) lo[i] = p[i];
}
double GET_EXTERNAL_MOTION_CONTROL_TOLERANCE() { return 0.1; }
double GET_EXTERNAL_PROBE_POSITION_X() { return _pos_x; }
@@ -401,7 +505,11 @@ double GET_EXTERNAL_POSITION_C() { return _pos_c; }
double GET_EXTERNAL_POSITION_U() { return _pos_u; }
double GET_EXTERNAL_POSITION_V() { return _pos_v; }
double GET_EXTERNAL_POSITION_W() { return _pos_w; }
-void INIT_CANON() {}
+void INIT_CANON() {
+ rotation_xy = 0;
+ rotation_cos = 1;
+ rotation_sin = 0;
+}
void GET_EXTERNAL_PARAMETER_FILE_NAME(char *name, int max_size) {
PyObject *result = PyObject_GetAttrString(callback, "parameter_file");
if(!result) { name[0] = 0; return; }
diff --git a/src/emc/usr_intf/axis/scripts/axis.py b/src/emc/usr_intf/axis/scripts/axis.py
index 107839b..a62d4d0 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -62,7 +62,6 @@ import gcode
import locale
import bwidget
from math import hypot, atan2, sin, cos, pi, sqrt
-from rs274 import ArcsToSegmentsMixin
import emc
from glnav import *
------------------------------------------------------------------------------
Download Intel® 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