problem for use remap
- mahdi2001h
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
18 Jun 2020 08:35 #171990
by mahdi2001h
problem for use remap was created by mahdi2001h
Hi
I tried to use remap for add my own G-code and run some python code by them
but when my CNC machine starting read G-codes just all remaped G-code run at start and not run in line that should run (but other lines run correctly)
for use remap I read linuxcnc.org/docs/html/remap/remap.html
my linuxcnc version is 2.7.15
I added this lines in my ini file :
and added in G-codes(inside other lines) :
regards
I tried to use remap for add my own G-code and run some python code by them
but when my CNC machine starting read G-codes just all remaped G-code run at start and not run in line that should run (but other lines run correctly)
for use remap I read linuxcnc.org/docs/html/remap/remap.html
my linuxcnc version is 2.7.15
I added this lines in my ini file :
[RS274NGC]
PARAMETER_FILE = linuxcnc.var
REMAP=G70 modalgroup=1 argspec=Pq py=g700
REMAP=G70.1 modalgroup=1 argspec=Pq py=g701
and added in G-codes(inside other lines) :
G70 P8
G70 P9
G70 P10
G70.1 P6
regards
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4031
- Thank you received: 1741
18 Jun 2020 09:46 #171995
by Aciera
Replied by Aciera on topic problem for use remap
Could you also show your python code?
Please Log in or Create an account to join the conversation.
- mahdi2001h
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
18 Jun 2020 09:49 - 18 Jun 2020 09:49 #171996
by mahdi2001h
Replied by mahdi2001h on topic problem for use remap
def g700(self, **words):
s.poll()
if s.estop == 0:
print "test p =" , words["p"]
return INTERP_OK
def g701(self, **words):
s.poll()
if s.estop == 0:
print "test1"
return INTERP_OK
Last edit: 18 Jun 2020 09:49 by mahdi2001h.
Please Log in or Create an account to join the conversation.
- rodw
- Away
- Platinum Member
Less
More
- Posts: 10816
- Thank you received: 3564
18 Jun 2020 09:50 #171997
by rodw
Replied by rodw on topic problem for use remap
There is a Sim with remapping setup. Have you looked at it. It is helpful as none of it is intuitive...
Please Log in or Create an account to join the conversation.
- mahdi2001h
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
18 Jun 2020 09:53 - 18 Jun 2020 09:56 #171998
by mahdi2001h
Replied by mahdi2001h on topic problem for use remap
where is that?!
How can I use it?
How can I use it?
Last edit: 18 Jun 2020 09:56 by mahdi2001h.
Please Log in or Create an account to join the conversation.
- rodw
- Away
- Platinum Member
Less
More
- Posts: 10816
- Thank you received: 3564
18 Jun 2020 10:00 #171999
by rodw
Replied by rodw on topic problem for use remap
From the main linuxcnc config chooser, there should be a whole list of simulations. One of them is called remap... so it will run without a machine and you can study how it works.
Please Log in or Create an account to join the conversation.
- mahdi2001h
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
18 Jun 2020 10:19 - 18 Jun 2020 10:20 #172000
by mahdi2001h
Replied by mahdi2001h on topic problem for use remap
oow
I've seen this before
It didn't help me
Because it did the same
But I'm reviewing it now
thanks
I've seen this before
It didn't help me
Because it did the same
But I'm reviewing it now
thanks
Last edit: 18 Jun 2020 10:20 by mahdi2001h.
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4031
- Thank you received: 1741
18 Jun 2020 17:18 #172020
by Aciera
Replied by Aciera on topic problem for use remap
Ok I've only done remaps with python script once before. My INI contains this:
Then my config folder contains a folder called python and inside that folder lives my remap.py (contains my python scripts for g912 and g913), toplevel.py, oword.py, stdglue.py and util.py.
toplevel.py contains
oword.py contains:
stdglue.py is an empty file
util.py contains:
REMAP=G91.2 modalgroup=1 argspec=xyzabc python=g912
REMAP=G91.3 modalgroup=1 argspec=xyzabc python=g913
Then my config folder contains a folder called python and inside that folder lives my remap.py (contains my python scripts for g912 and g913), toplevel.py, oword.py, stdglue.py and util.py.
toplevel.py contains
import oword
import remap
oword.py contains:
from util import call_pydevd
def foo(*args):
print "foo!"
# make debugger available as oword procedure
def pydevd(self,*args):
call_pydevd()
# this would be defined in the oword module
def mysub(self, *args):
print "number of parameters passed:", len(args)
for a in args:
print a
stdglue.py is an empty file
util.py contains:
import inspect
import emccanon
# O-word procedure to trap into the Pydevd debugger
# start debug server in Eclipse, then
# call as 'O<pydevd> call' from MDI
# example setup for debugging embedded Python code
# see http://pydev.org/manual_adv_remote_debugger.html
# if this points to a valid directory,
def call_pydevd():
""" trap into the pydevd debugger"""
import os,sys
pydevdir= '/home/mah/.eclipse/org.eclipse.platform_3.5.0_155965261/plugins/org.python.pydev.debug_2.0.0.2011040403/pysrc/'
# the 'emctask' module is present only in the milltask instance, otherwise both the UI and
# milltask would try to connect to the debug server.
if os.path.isdir(pydevdir) and 'emctask' in sys.builtin_module_names:
sys.path.append(pydevdir)
sys.path.insert(0,pydevdir)
try:
import pydevd
emccanon.MESSAGE("pydevd imported, connecting to Eclipse debug server...")
pydevd.settrace()
except:
emccanon.MESSAGE("no pydevd module found")
pass
def lineno():
""" return line number in the current Python script """
return inspect.currentframe().f_back.f_lineno
def error_stack(self):
""" print the Interpreters error stack (function names) """
print "error stack level=%d" % (self.stack_index)
for s in self.stack():
print "--'%s'" % (s)
def callstack(self):
""" print the O-Word call stack """
for i in range(self.call_level):
c = self.sub_context[i]
print "%d: pos=%d seq=%d filename=%s sub=%s" % (i,c.position, c.sequence_number,c.filename,c.subname)
The following user(s) said Thank You: mahdi2001h
Please Log in or Create an account to join the conversation.
- mahdi2001h
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 30
- Thank you received: 0
21 Jun 2020 05:45 #172220
by mahdi2001h
Replied by mahdi2001h on topic problem for use remap
Please also send your remap.py file
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4031
- Thank you received: 1741
21 Jun 2020 06:39 #172222
by Aciera
Replied by Aciera on topic problem for use remap
remap.py:
Warning: Spoiler!
import sys
import traceback
import numpy
#import pprint
from math import sin,cos,atan2,sqrt,pi,degrees
from interpreter import *
from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT
from util import lineno, call_pydevd
throw_exceptions = 1 # raises InterpreterException if execute() or read() fail
#Remap for Incremental moves in tool coordinates "G91.2 x y z a b c
def g912(self, **words):
#genserkins.c uses Rot[X,Y,Z] fixed angles rotation also called XYZ-Tait-Bryan angles
#First rotation: "c"-rotation is equal to rotation around z = Z-world-axis
#Second rotation: "b"-rotation is equal to rotation around the y'-axis
# "a"-rotation is always equal to rotation around x'' = X-tool-axis
#requested increments
c = self.blocks[self.remap_level]
dx = c.x_number if c.x_flag else 0
dy = c.y_number if c.y_flag else 0
dz = c.z_number if c.z_flag else 0
da = c.a_number if c.a_flag else 0
db = c.b_number if c.b_flag else 0
dc = c.c_number if c.c_flag else 0
#current position and orientation
old_x = self.current_x
old_y = self.current_y
old_z = self.current_z
old_a = self.AA_current
old_b = self.BB_current
old_c = self.CC_current
#calculate terms for rotation matrices
sa = sin(old_a*(pi/180))
sb = sin(old_b*(pi/180))
sc = sin(old_c*(pi/180))
ca = cos(old_a*(pi/180))
cb = cos(old_b*(pi/180))
cc = cos(old_c*(pi/180))
sda = sin(da*(pi/180))
sdb = sin(db*(pi/180))
sdc = sin(dc*(pi/180))
cda = cos(da*(pi/180))
cdb = cos(db*(pi/180))
cdc = cos(dc*(pi/180))
#---Calculation of the new position---:
#This is used to calculate the new POSITION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 x y z ...)
#Transformation matrix for the kinematics used in genserkins
A = [[ cb*cc , sa*sb*cc - ca*sc , ca*sb*cc + sa*sc ],
[ cb*sc , sa*sb*sc + ca*cc , ca*sb*sc - sa*cc ],
[ -sb , sa*cb , ca*cb ]]
#requested move in vector form
Pd = [[ dx ],
[ dy ],
[ dz ]]
#A*Pd - matrix multiplication (the order is important! A*Pd != Pd*A)
#'import numpy' is required for this
P = [[sum(a*b for a,b in zip(A_row,Pd_col)) for Pd_col in zip(*Pd)] for A_row in A]
#position in world coordinates is the sum of the old position and the rotated increments
x_new = old_x + P[0][0]
y_new = old_y + P[1][0]
z_new = old_z + P[2][0]
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(A)
#---Calculation of the new orientation---
#This is used to calculate the new ORIENTATION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 ... a b c)
#matrix for rotation by angle 'c' around z-axis
Rz = [[ cdc, -sdc, 0 ],
[ sdc, cdc, 0 ],
[ 0, 0 , 1 ]]
#matrix for rotation by angle 'b' around y-axis
Ry = [[ cdb , 0, sdb ],
[ 0 , 1, 0 ],
[-sdb , 0, cdb ]]
#matrix for rotation by angle 'a' around y-axis
Rx = [[ 1 , 0 , 0 ],
[ 0 , cda, -sda ],
[ 0 , sda, cda ]]
'''
#--Incremental rotation in WORLD-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the WORLD-coordinate-system
#Matrix multiplications Rx*Ry*Rz*A (starting from right to left)
#multiply Rz * A
A = [[sum(a*b for a,b in zip(Rz_row,A_col)) for A_col in zip(*A)] for Rz_row in Rz]
#multiply Ry * A
A = [[sum(a*b for a,b in zip(Ry_row,A_col)) for A_col in zip(*A)] for Ry_row in Ry]
#multiply Rx * A
A = [[sum(a*b for a,b in zip(Rx_row,A_col)) for A_col in zip(*A)] for Rx_row in Rx]
'''
#--Incremental rotation in TOOL-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the TOOL-coordinate-system
#Matrix multiplications A*Rx*Ry*Rz (starting from right to left)
#multiply Ry * Rz
C = [[sum(a*b for a,b in zip(Ry_row,Rz_col)) for Rz_col in zip(*Rz)] for Ry_row in Ry]
#multiply Rx * C
B = [[sum(a*b for a,b in zip(Rx_row,C_col)) for C_col in zip(*C)] for Rx_row in Rx]
#multiply A * B
A = [[sum(a*b for a,b in zip(A_row,B_col)) for B_col in zip(*] for A_row in A]
#now the required numerical results of all the elements of the transformation matrix have
#been calculated and we can solve the equations for the required angles a,b,c
#calculate new Euler angles a,b,c
c_new_r = atan2((A[1][0]),A[0][0])
c_new = degrees(c_new_r)
b_new_r = atan2(-A[2][0],sqrt(A[2][1]*A[2][1]+A[2][2]*A[2][2]))
b_new = degrees(b_new_r)
a_new_r = atan2((A[2][1]),A[2][2])
a_new = degrees(a_new_r)
#print(x_new,y_new,z_new,a_new,b_new,c_new)
#send new coordinates as G0 move to LinuxCNC
self.execute("G0 X%f Y%f Z%f A%f B%f C%f" % (x_new,y_new,z_new,a_new,b_new,c_new),lineno())
return INTERP_OK
#Remap for Incremental xyz-moves in TOOL coordinates , and incremental abc-moves in WORLD - coordinates
#"G91.2 x y z a b c
def g913(self, **words):
#genserkins.c uses Rot[X,Y,Z] fixed angles rotation also called XYZ-Tait-Bryan angles
#First rotation: "c"-rotation is equal to rotation around z = Z-world-axis
#Second rotation: "b"-rotation is equal to rotation around the y'-axis
# "a"-rotation is always equal to rotation around x'' = X-tool-axis
#requested increments
c = self.blocks[self.remap_level]
dx = c.x_number if c.x_flag else 0
dy = c.y_number if c.y_flag else 0
dz = c.z_number if c.z_flag else 0
da = c.a_number if c.a_flag else 0
db = c.b_number if c.b_flag else 0
dc = c.c_number if c.c_flag else 0
#current position and orientation
old_x = self.current_x
old_y = self.current_y
old_z = self.current_z
old_a = self.AA_current
old_b = self.BB_current
old_c = self.CC_current
#calculate terms for rotation matrices
sa = sin(old_a*(pi/180))
sb = sin(old_b*(pi/180))
sc = sin(old_c*(pi/180))
ca = cos(old_a*(pi/180))
cb = cos(old_b*(pi/180))
cc = cos(old_c*(pi/180))
sda = sin(da*(pi/180))
sdb = sin(db*(pi/180))
sdc = sin(dc*(pi/180))
cda = cos(da*(pi/180))
cdb = cos(db*(pi/180))
cdc = cos(dc*(pi/180))
#---Calculation of the new position---:
#This is used to calculate the new POSITION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 x y z ...)
#Transformation matrix for the kinematics used in genserkins
A = [[ cb*cc , sa*sb*cc - ca*sc , ca*sb*cc + sa*sc ],
[ cb*sc , sa*sb*sc + ca*cc , ca*sb*sc - sa*cc ],
[ -sb , sa*cb , ca*cb ]]
#requested move in vector form
Pd = [[ dx ],
[ dy ],
[ dz ]]
#A*Pd - matrix multiplication (the order is important! A*Pd != Pd*A)
#'import numpy' is required for this
P = [[sum(a*b for a,b in zip(A_row,Pd_col)) for Pd_col in zip(*Pd)] for A_row in A]
#position in world coordinates is the sum of the old position and the rotated increments
x_new = old_x + P[0][0]
y_new = old_y + P[1][0]
z_new = old_z + P[2][0]
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(A)
#---Calculation of the new orientation---
#This is used to calculate the new ORIENTATION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 ... a b c)
#matrix for rotation by angle 'c' around z-axis
Rz = [[ cdc, -sdc, 0 ],
[ sdc, cdc, 0 ],
[ 0, 0 , 1 ]]
#matrix for rotation by angle 'b' around y-axis
Ry = [[ cdb , 0, sdb ],
[ 0 , 1, 0 ],
[-sdb , 0, cdb ]]
#matrix for rotation by angle 'a' around y-axis
Rx = [[ 1 , 0 , 0 ],
[ 0 , cda, -sda ],
[ 0 , sda, cda ]]
#--Incremental rotation in WORLD-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the WORLD-coordinate-system
#Matrix multiplications Rx*Ry*Rz*A (starting from right to left)
#multiply Rz * A
A = [[sum(a*b for a,b in zip(Rz_row,A_col)) for A_col in zip(*A)] for Rz_row in Rz]
#multiply Ry * A
A = [[sum(a*b for a,b in zip(Ry_row,A_col)) for A_col in zip(*A)] for Ry_row in Ry]
#multiply Rx * A
A = [[sum(a*b for a,b in zip(Rx_row,A_col)) for A_col in zip(*A)] for Rx_row in Rx]
#now the required numerical results of all the elements of the transformation matrix have
#been calculated and we can solve the equations for the required angles a,b,c
#calculate new Euler angles a,b,c
c_new_r = atan2((A[1][0]),A[0][0])
c_new = degrees(c_new_r)
b_new_r = atan2(-A[2][0],sqrt(A[2][1]*A[2][1]+A[2][2]*A[2][2]))
b_new = degrees(b_new_r)
a_new_r = atan2((A[2][1]),A[2][2])
a_new = degrees(a_new_r)
#print(x_new,y_new,z_new,a_new,b_new,c_new)
#send new coordinates as G0 move to LinuxCNC
self.execute("G0 X%f Y%f Z%f A%f B%f C%f" % (x_new,y_new,z_new,a_new,b_new,c_new),lineno())
return INTERP_OK
import traceback
import numpy
#import pprint
from math import sin,cos,atan2,sqrt,pi,degrees
from interpreter import *
from emccanon import MESSAGE, SET_MOTION_OUTPUT_BIT, CLEAR_MOTION_OUTPUT_BIT,SET_AUX_OUTPUT_BIT,CLEAR_AUX_OUTPUT_BIT
from util import lineno, call_pydevd
throw_exceptions = 1 # raises InterpreterException if execute() or read() fail
#Remap for Incremental moves in tool coordinates "G91.2 x y z a b c
def g912(self, **words):
#genserkins.c uses Rot[X,Y,Z] fixed angles rotation also called XYZ-Tait-Bryan angles
#First rotation: "c"-rotation is equal to rotation around z = Z-world-axis
#Second rotation: "b"-rotation is equal to rotation around the y'-axis
# "a"-rotation is always equal to rotation around x'' = X-tool-axis
#requested increments
c = self.blocks[self.remap_level]
dx = c.x_number if c.x_flag else 0
dy = c.y_number if c.y_flag else 0
dz = c.z_number if c.z_flag else 0
da = c.a_number if c.a_flag else 0
db = c.b_number if c.b_flag else 0
dc = c.c_number if c.c_flag else 0
#current position and orientation
old_x = self.current_x
old_y = self.current_y
old_z = self.current_z
old_a = self.AA_current
old_b = self.BB_current
old_c = self.CC_current
#calculate terms for rotation matrices
sa = sin(old_a*(pi/180))
sb = sin(old_b*(pi/180))
sc = sin(old_c*(pi/180))
ca = cos(old_a*(pi/180))
cb = cos(old_b*(pi/180))
cc = cos(old_c*(pi/180))
sda = sin(da*(pi/180))
sdb = sin(db*(pi/180))
sdc = sin(dc*(pi/180))
cda = cos(da*(pi/180))
cdb = cos(db*(pi/180))
cdc = cos(dc*(pi/180))
#---Calculation of the new position---:
#This is used to calculate the new POSITION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 x y z ...)
#Transformation matrix for the kinematics used in genserkins
A = [[ cb*cc , sa*sb*cc - ca*sc , ca*sb*cc + sa*sc ],
[ cb*sc , sa*sb*sc + ca*cc , ca*sb*sc - sa*cc ],
[ -sb , sa*cb , ca*cb ]]
#requested move in vector form
Pd = [[ dx ],
[ dy ],
[ dz ]]
#A*Pd - matrix multiplication (the order is important! A*Pd != Pd*A)
#'import numpy' is required for this
P = [[sum(a*b for a,b in zip(A_row,Pd_col)) for Pd_col in zip(*Pd)] for A_row in A]
#position in world coordinates is the sum of the old position and the rotated increments
x_new = old_x + P[0][0]
y_new = old_y + P[1][0]
z_new = old_z + P[2][0]
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(A)
#---Calculation of the new orientation---
#This is used to calculate the new ORIENTATION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 ... a b c)
#matrix for rotation by angle 'c' around z-axis
Rz = [[ cdc, -sdc, 0 ],
[ sdc, cdc, 0 ],
[ 0, 0 , 1 ]]
#matrix for rotation by angle 'b' around y-axis
Ry = [[ cdb , 0, sdb ],
[ 0 , 1, 0 ],
[-sdb , 0, cdb ]]
#matrix for rotation by angle 'a' around y-axis
Rx = [[ 1 , 0 , 0 ],
[ 0 , cda, -sda ],
[ 0 , sda, cda ]]
'''
#--Incremental rotation in WORLD-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the WORLD-coordinate-system
#Matrix multiplications Rx*Ry*Rz*A (starting from right to left)
#multiply Rz * A
A = [[sum(a*b for a,b in zip(Rz_row,A_col)) for A_col in zip(*A)] for Rz_row in Rz]
#multiply Ry * A
A = [[sum(a*b for a,b in zip(Ry_row,A_col)) for A_col in zip(*A)] for Ry_row in Ry]
#multiply Rx * A
A = [[sum(a*b for a,b in zip(Rx_row,A_col)) for A_col in zip(*A)] for Rx_row in Rx]
'''
#--Incremental rotation in TOOL-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the TOOL-coordinate-system
#Matrix multiplications A*Rx*Ry*Rz (starting from right to left)
#multiply Ry * Rz
C = [[sum(a*b for a,b in zip(Ry_row,Rz_col)) for Rz_col in zip(*Rz)] for Ry_row in Ry]
#multiply Rx * C
B = [[sum(a*b for a,b in zip(Rx_row,C_col)) for C_col in zip(*C)] for Rx_row in Rx]
#multiply A * B
A = [[sum(a*b for a,b in zip(A_row,B_col)) for B_col in zip(*] for A_row in A]
#now the required numerical results of all the elements of the transformation matrix have
#been calculated and we can solve the equations for the required angles a,b,c
#calculate new Euler angles a,b,c
c_new_r = atan2((A[1][0]),A[0][0])
c_new = degrees(c_new_r)
b_new_r = atan2(-A[2][0],sqrt(A[2][1]*A[2][1]+A[2][2]*A[2][2]))
b_new = degrees(b_new_r)
a_new_r = atan2((A[2][1]),A[2][2])
a_new = degrees(a_new_r)
#print(x_new,y_new,z_new,a_new,b_new,c_new)
#send new coordinates as G0 move to LinuxCNC
self.execute("G0 X%f Y%f Z%f A%f B%f C%f" % (x_new,y_new,z_new,a_new,b_new,c_new),lineno())
return INTERP_OK
#Remap for Incremental xyz-moves in TOOL coordinates , and incremental abc-moves in WORLD - coordinates
#"G91.2 x y z a b c
def g913(self, **words):
#genserkins.c uses Rot[X,Y,Z] fixed angles rotation also called XYZ-Tait-Bryan angles
#First rotation: "c"-rotation is equal to rotation around z = Z-world-axis
#Second rotation: "b"-rotation is equal to rotation around the y'-axis
# "a"-rotation is always equal to rotation around x'' = X-tool-axis
#requested increments
c = self.blocks[self.remap_level]
dx = c.x_number if c.x_flag else 0
dy = c.y_number if c.y_flag else 0
dz = c.z_number if c.z_flag else 0
da = c.a_number if c.a_flag else 0
db = c.b_number if c.b_flag else 0
dc = c.c_number if c.c_flag else 0
#current position and orientation
old_x = self.current_x
old_y = self.current_y
old_z = self.current_z
old_a = self.AA_current
old_b = self.BB_current
old_c = self.CC_current
#calculate terms for rotation matrices
sa = sin(old_a*(pi/180))
sb = sin(old_b*(pi/180))
sc = sin(old_c*(pi/180))
ca = cos(old_a*(pi/180))
cb = cos(old_b*(pi/180))
cc = cos(old_c*(pi/180))
sda = sin(da*(pi/180))
sdb = sin(db*(pi/180))
sdc = sin(dc*(pi/180))
cda = cos(da*(pi/180))
cdb = cos(db*(pi/180))
cdc = cos(dc*(pi/180))
#---Calculation of the new position---:
#This is used to calculate the new POSITION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 x y z ...)
#Transformation matrix for the kinematics used in genserkins
A = [[ cb*cc , sa*sb*cc - ca*sc , ca*sb*cc + sa*sc ],
[ cb*sc , sa*sb*sc + ca*cc , ca*sb*sc - sa*cc ],
[ -sb , sa*cb , ca*cb ]]
#requested move in vector form
Pd = [[ dx ],
[ dy ],
[ dz ]]
#A*Pd - matrix multiplication (the order is important! A*Pd != Pd*A)
#'import numpy' is required for this
P = [[sum(a*b for a,b in zip(A_row,Pd_col)) for Pd_col in zip(*Pd)] for A_row in A]
#position in world coordinates is the sum of the old position and the rotated increments
x_new = old_x + P[0][0]
y_new = old_y + P[1][0]
z_new = old_z + P[2][0]
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(A)
#---Calculation of the new orientation---
#This is used to calculate the new ORIENTATION in world coordinates according to the
#requested incremental moves along the tool coordinate axis (G91.2 ... a b c)
#matrix for rotation by angle 'c' around z-axis
Rz = [[ cdc, -sdc, 0 ],
[ sdc, cdc, 0 ],
[ 0, 0 , 1 ]]
#matrix for rotation by angle 'b' around y-axis
Ry = [[ cdb , 0, sdb ],
[ 0 , 1, 0 ],
[-sdb , 0, cdb ]]
#matrix for rotation by angle 'a' around y-axis
Rx = [[ 1 , 0 , 0 ],
[ 0 , cda, -sda ],
[ 0 , sda, cda ]]
#--Incremental rotation in WORLD-coordinates--
#this rotates the Tool-center-point around the X-,Y-,Z-axis of the WORLD-coordinate-system
#Matrix multiplications Rx*Ry*Rz*A (starting from right to left)
#multiply Rz * A
A = [[sum(a*b for a,b in zip(Rz_row,A_col)) for A_col in zip(*A)] for Rz_row in Rz]
#multiply Ry * A
A = [[sum(a*b for a,b in zip(Ry_row,A_col)) for A_col in zip(*A)] for Ry_row in Ry]
#multiply Rx * A
A = [[sum(a*b for a,b in zip(Rx_row,A_col)) for A_col in zip(*A)] for Rx_row in Rx]
#now the required numerical results of all the elements of the transformation matrix have
#been calculated and we can solve the equations for the required angles a,b,c
#calculate new Euler angles a,b,c
c_new_r = atan2((A[1][0]),A[0][0])
c_new = degrees(c_new_r)
b_new_r = atan2(-A[2][0],sqrt(A[2][1]*A[2][1]+A[2][2]*A[2][2]))
b_new = degrees(b_new_r)
a_new_r = atan2((A[2][1]),A[2][2])
a_new = degrees(a_new_r)
#print(x_new,y_new,z_new,a_new,b_new,c_new)
#send new coordinates as G0 move to LinuxCNC
self.execute("G0 X%f Y%f Z%f A%f B%f C%f" % (x_new,y_new,z_new,a_new,b_new,c_new),lineno())
return INTERP_OK
The following user(s) said Thank You: mahdi2001h
Please Log in or Create an account to join the conversation.
Time to create page: 0.074 seconds