- GCode and Part Programs
- G&M Codes
- Change work offset values in a Pure Python remap w/o self.execute()
Change work offset values in a Pure Python remap w/o self.execute()
- Aciera
- Topic Author
- Offline
- Administrator
Less
More
- Posts: 3969
- Thank you received: 1717
09 Feb 2023 16:52 #264150
by Aciera
Change work offset values in a Pure Python remap w/o self.execute() was created by Aciera
I'm working on a pure python remap for G68.2 and affiliated Gcodes and I have fallen down the 'yield INTERP_EXECUTE_FINISH' hole.
I needed 'yield INTERP_EXECUTE_FINISH' because I have to wait for a joint move to finish before I can continue with replacing the active work offset values (ie G54 or whatever is active). The line I used for this was
'self.execute("G10 L2 P0 X%f Y%f Z%f " % (P[0],P[1],P[2]) ,lineno())'
with P holding the new offset values.
Now however I cannot use any 'self.execute(...)' because of the preceeding 'yield INTERP_EXECUTE_FINISH'. So I came up with this to write the new offset values directly into the numbered parameters:
This works and it writes the values into the parameters but they aren't actually read and used unless I reload them with an mdi command like 'G54' which I can't do from the remap because I can't use 'self.execute(..)'.
So if anybody knows of a way to do this from a remap without using 'self.execute(..)' let me know please.
I needed 'yield INTERP_EXECUTE_FINISH' because I have to wait for a joint move to finish before I can continue with replacing the active work offset values (ie G54 or whatever is active). The line I used for this was
'self.execute("G10 L2 P0 X%f Y%f Z%f " % (P[0],P[1],P[2]) ,lineno())'
with P holding the new offset values.
Now however I cannot use any 'self.execute(...)' because of the preceeding 'yield INTERP_EXECUTE_FINISH'. So I came up with this to write the new offset values directly into the numbered parameters:
# get which offset is active (g54=1 .. g59.3=9)
active_offset = int(self.params[5220])
# set the relevant parameter numbers that hold the active offset values
# (G54_x: #5221, G55_x:#[5221+20], G56_x:#[5221+40] ....)
work_offset_x = (active_offset-1)*20 + 5221
work_offset_y = work_offset_x + 1
work_offset_z = work_offset_x + 2
self.params[work_offset_x] = P[0]
self.params[work_offset_y] = P[1]
self.params[work_offset_z] = P[2]
This works and it writes the values into the parameters but they aren't actually read and used unless I reload them with an mdi command like 'G54' which I can't do from the remap because I can't use 'self.execute(..)'.
So if anybody knows of a way to do this from a remap without using 'self.execute(..)' let me know please.
Warning: Spoiler!
# orient the tool to the current twp (with TCP)
# some mfgs offer an optional P-word to give preferred rotation directions
def g536(self):
global saved_work_offset
global twp_flag
# reset the twp build
twp_flag = [0, 'empty']
# switch to identity kins
hal.set_p("motion.switchkins-type",str(0))
# calculate the required rotary joint positions and
# pre_rotation for the requested tool-orientation
a_j, b_j, pre_rot = twp_calc_jnts_pos_and_pre_rot(self)
gui_update_twp(self)
# switch to tcp kins
print("G53.6: Activating TCP kins")
hal.set_p("motion.switchkins-type",str(1))
kins_comp_set_pre_rot(self, pre_rot)
print(" mdi moving joints A, B: ", a_j, b_j)
# build and send the gcode command to move to the new joint positions
#self.execute("G0 A%f B%f " % (a, b), lineno())
# read and remember coordiantes in the begining of the operation
# you may have more or less coords - syntax and logic are the same
x_pos = round(emccanon.GET_EXTERNAL_POSITION_X(), 3)
y_pos = round(emccanon.GET_EXTERNAL_POSITION_Y(), 3)
z_pos = round(emccanon.GET_EXTERNAL_POSITION_Z(), 3)
c_pos = round(emccanon.GET_EXTERNAL_POSITION_C(), 3)
emccanon.STRAIGHT_TRAVERSE(2, x_pos, y_pos, z_pos, a_j*(180/pi), b_j*(180/pi), c_pos, 0,0,0)
yield INTERP_EXECUTE_FINISH
# calculate the offsets in tool-coords
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(saved_work_offset)))
print("Setting transformed work-offsets in tool-kins: ", P)
# put the calcualted offset values into the relevant parameters
#self.execute("G10 L2 P0 X%f Y%f Z%f " % (P[0],P[1],P[2]) ,lineno())
# get which offset is active (g54=1 .. g59.3=9)
active_offset = int(self.params[5220])
# set the relevant parameter numbers that hold the active offset values
# (G54_x: #5221, G55_x:#[5221+20], G56_x:#[5221+40] ....)
work_offset_x = (active_offset-1)*20 + 5221
work_offset_y = work_offset_x + 1
work_offset_z = work_offset_x + 2
self.params[work_offset_x] = P[0]
self.params[work_offset_y] = P[1]
self.params[work_offset_z] = P[2]
# same as above but for twp-offsets used for twp origin as set by g68.2 (x,y,z)-words
# g69 will set the twp-offsets to zero.
current_twp_offset = params_get_current_twp_offset(self)
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(current_twp_offset)))
print("Setting transformed twp-offset in tool-kins: ", P)
hal.set_p("gen_xyzabc_trsrn_kins.twp-x",str(P[0]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-y",str(P[1]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-z",str(P[2]))
# switch to tool kins
hal.set_p("motion.switchkins-type",str(3))
# we only want to update the offsets as those get rotated by rotary-joint positions
# while the twp is rotated using the method chosen by the g68.2 p-word
gui_update_offsets(self)
return INTERP_OK
# some mfgs offer an optional P-word to give preferred rotation directions
def g536(self):
global saved_work_offset
global twp_flag
# reset the twp build
twp_flag = [0, 'empty']
# switch to identity kins
hal.set_p("motion.switchkins-type",str(0))
# calculate the required rotary joint positions and
# pre_rotation for the requested tool-orientation
a_j, b_j, pre_rot = twp_calc_jnts_pos_and_pre_rot(self)
gui_update_twp(self)
# switch to tcp kins
print("G53.6: Activating TCP kins")
hal.set_p("motion.switchkins-type",str(1))
kins_comp_set_pre_rot(self, pre_rot)
print(" mdi moving joints A, B: ", a_j, b_j)
# build and send the gcode command to move to the new joint positions
#self.execute("G0 A%f B%f " % (a, b), lineno())
# read and remember coordiantes in the begining of the operation
# you may have more or less coords - syntax and logic are the same
x_pos = round(emccanon.GET_EXTERNAL_POSITION_X(), 3)
y_pos = round(emccanon.GET_EXTERNAL_POSITION_Y(), 3)
z_pos = round(emccanon.GET_EXTERNAL_POSITION_Z(), 3)
c_pos = round(emccanon.GET_EXTERNAL_POSITION_C(), 3)
emccanon.STRAIGHT_TRAVERSE(2, x_pos, y_pos, z_pos, a_j*(180/pi), b_j*(180/pi), c_pos, 0,0,0)
yield INTERP_EXECUTE_FINISH
# calculate the offsets in tool-coords
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(saved_work_offset)))
print("Setting transformed work-offsets in tool-kins: ", P)
# put the calcualted offset values into the relevant parameters
#self.execute("G10 L2 P0 X%f Y%f Z%f " % (P[0],P[1],P[2]) ,lineno())
# get which offset is active (g54=1 .. g59.3=9)
active_offset = int(self.params[5220])
# set the relevant parameter numbers that hold the active offset values
# (G54_x: #5221, G55_x:#[5221+20], G56_x:#[5221+40] ....)
work_offset_x = (active_offset-1)*20 + 5221
work_offset_y = work_offset_x + 1
work_offset_z = work_offset_x + 2
self.params[work_offset_x] = P[0]
self.params[work_offset_y] = P[1]
self.params[work_offset_z] = P[2]
# same as above but for twp-offsets used for twp origin as set by g68.2 (x,y,z)-words
# g69 will set the twp-offsets to zero.
current_twp_offset = params_get_current_twp_offset(self)
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(current_twp_offset)))
print("Setting transformed twp-offset in tool-kins: ", P)
hal.set_p("gen_xyzabc_trsrn_kins.twp-x",str(P[0]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-y",str(P[1]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-z",str(P[2]))
# switch to tool kins
hal.set_p("motion.switchkins-type",str(3))
# we only want to update the offsets as those get rotated by rotary-joint positions
# while the twp is rotated using the method chosen by the g68.2 p-word
gui_update_offsets(self)
return INTERP_OK
Please Log in or Create an account to join the conversation.
- Aciera
- Topic Author
- Offline
- Administrator
Less
More
- Posts: 3969
- Thank you received: 1717
09 Feb 2023 17:09 #264154
by Aciera
Replied by Aciera on topic Change work offset values in a Pure Python remap w/o self.execute()
Ok, never mind I just found it:
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- Aciera
- Topic Author
- Offline
- Administrator
Less
More
- Posts: 3969
- Thank you received: 1717
10 Feb 2023 15:25 #264227
by Aciera
Replied by Aciera on topic Change work offset values in a Pure Python remap w/o self.execute()
Just an update in case somebody comes across this in the future as there are some odd thing with this:
1.
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
With index '0' seems to write to G53 and the axis DRO is then stuck at G53
A 'G53 X0Y0Z0' ignores the new values and uses the old offset (x100y0z0 in my case)
2.
emccanon.SET_G5X_OFFSET(1, P[0], P[1], P[2], 0,0,0,0,0,0)
With index '1' seems to write to G54 just fine but also doesn't seem to update G53 properly.
So a 'G53 G0 X0 Y0 Z0' will ignore the offset-change with the above emccanon.SET_G5X_OFFSET(...)
If anybody has an idea I could get this to work please let me know.
This is the code I'm using:
1.
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
With index '0' seems to write to G53 and the axis DRO is then stuck at G53
A 'G53 X0Y0Z0' ignores the new values and uses the old offset (x100y0z0 in my case)
2.
emccanon.SET_G5X_OFFSET(1, P[0], P[1], P[2], 0,0,0,0,0,0)
With index '1' seems to write to G54 just fine but also doesn't seem to update G53 properly.
So a 'G53 G0 X0 Y0 Z0' will ignore the offset-change with the above emccanon.SET_G5X_OFFSET(...)
If anybody has an idea I could get this to work please let me know.
This is the code I'm using:
Warning: Spoiler!
# orient the tool to the current twp (with TCP)
# some mfgs offer an optional P-word to give preferred rotation directions
def g536(self):
global saved_work_offset
global twp_flag
# reset the twp build
twp_flag = [0, 'empty']
# switch to identity kins
hal.set_p("motion.switchkins-type",str(0))
yield INTERP_EXECUTE_FINISH
# calculate the required rotary joint positions and
# pre_rotation for the requested tool-orientation
a_j, b_j, pre_rot = twp_calc_jnts_pos_and_pre_rot(self)
gui_update_twp(self)
# switch to tcp kins
print("G53.6: Activating TCP kins")
hal.set_p("motion.switchkins-type",str(1))
kins_comp_set_pre_rot(self, pre_rot)
yield INTERP_EXECUTE_FINISH
print(" mdi moving joints A, B: ", a_j, b_j)
# store current coordiantes because emccanon wants values for all nine axes
x_pos = emccanon.GET_EXTERNAL_POSITION_X()
y_pos = emccanon.GET_EXTERNAL_POSITION_Y()
z_pos = emccanon.GET_EXTERNAL_POSITION_Z()
c_pos = emccanon.GET_EXTERNAL_POSITION_C()
emccanon.STRAIGHT_TRAVERSE(2, x_pos, y_pos, z_pos, a_j*(180/pi), b_j*(180/pi), c_pos, 0,0,0)
yield INTERP_EXECUTE_FINISH
# calculate the work offset in tool-coords
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(saved_work_offset)))
print("Setting transformed work-offsets in tool-kins: ", P)
# note: index 0=g53, 1=g54 etc
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
emccanon.SET_G5X_OFFSET(1, P[0], P[1], P[2], 0,0,0,0,0,0)
# same as above but for twp-offsets used for twp origin as set by g68.2 (x,y,z)-words
# g69 will set the twp-offsets to zero.
current_twp_offset = params_get_current_twp_offset(self)
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(current_twp_offset)))
print("Setting transformed twp-offset in tool-kins: ", P)
hal.set_p("gen_xyzabc_trsrn_kins.twp-x",str(P[0]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-y",str(P[1]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-z",str(P[2]))
yield INTERP_EXECUTE_FINISH
# switch to tool kins
hal.set_p("motion.switchkins-type",str(3))
yield INTERP_EXECUTE_FINISH
# we only want to update the offsets as those get rotated by rotary-joint positions
# while the twp is rotated using the method chosen by the g68.2 p-word
gui_update_offsets(self)
yield INTERP_OK
# some mfgs offer an optional P-word to give preferred rotation directions
def g536(self):
global saved_work_offset
global twp_flag
# reset the twp build
twp_flag = [0, 'empty']
# switch to identity kins
hal.set_p("motion.switchkins-type",str(0))
yield INTERP_EXECUTE_FINISH
# calculate the required rotary joint positions and
# pre_rotation for the requested tool-orientation
a_j, b_j, pre_rot = twp_calc_jnts_pos_and_pre_rot(self)
gui_update_twp(self)
# switch to tcp kins
print("G53.6: Activating TCP kins")
hal.set_p("motion.switchkins-type",str(1))
kins_comp_set_pre_rot(self, pre_rot)
yield INTERP_EXECUTE_FINISH
print(" mdi moving joints A, B: ", a_j, b_j)
# store current coordiantes because emccanon wants values for all nine axes
x_pos = emccanon.GET_EXTERNAL_POSITION_X()
y_pos = emccanon.GET_EXTERNAL_POSITION_Y()
z_pos = emccanon.GET_EXTERNAL_POSITION_Z()
c_pos = emccanon.GET_EXTERNAL_POSITION_C()
emccanon.STRAIGHT_TRAVERSE(2, x_pos, y_pos, z_pos, a_j*(180/pi), b_j*(180/pi), c_pos, 0,0,0)
yield INTERP_EXECUTE_FINISH
# calculate the work offset in tool-coords
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(saved_work_offset)))
print("Setting transformed work-offsets in tool-kins: ", P)
# note: index 0=g53, 1=g54 etc
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0)
emccanon.SET_G5X_OFFSET(1, P[0], P[1], P[2], 0,0,0,0,0,0)
# same as above but for twp-offsets used for twp origin as set by g68.2 (x,y,z)-words
# g69 will set the twp-offsets to zero.
current_twp_offset = params_get_current_twp_offset(self)
P = matrix_to_point(kins_calc_tool_transformation(self, point_to_matrix(current_twp_offset)))
print("Setting transformed twp-offset in tool-kins: ", P)
hal.set_p("gen_xyzabc_trsrn_kins.twp-x",str(P[0]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-y",str(P[1]))
hal.set_p("gen_xyzabc_trsrn_kins.twp-z",str(P[2]))
yield INTERP_EXECUTE_FINISH
# switch to tool kins
hal.set_p("motion.switchkins-type",str(3))
yield INTERP_EXECUTE_FINISH
# we only want to update the offsets as those get rotated by rotary-joint positions
# while the twp is rotated using the method chosen by the g68.2 p-word
gui_update_offsets(self)
yield INTERP_OK
Attachments:
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
Less
More
- Posts: 7766
- Thank you received: 2055
11 Feb 2023 08:14 #264276
by cmorley
Replied by cmorley on topic Change work offset values in a Pure Python remap w/o self.execute()
AFAIU G53 should be set by homing and never be changed - that is the machines base offsets.
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0) index '0' could very well be 'set the current user system' - that is what it does in the higher gcode level. But that is not reliable in gcode programs as read-ahead can mess it up.
emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0) index '0' could very well be 'set the current user system' - that is what it does in the higher gcode level. But that is not reliable in gcode programs as read-ahead can mess it up.
Please Log in or Create an account to join the conversation.
- Aciera
- Topic Author
- Offline
- Administrator
Less
More
- Posts: 3969
- Thank you received: 1717
11 Feb 2023 10:31 - 11 Feb 2023 10:35 #264284
by Aciera
Replied by Aciera on topic Change work offset values in a Pure Python remap w/o self.execute()
For some reason I used to think that 'G93 x0y0z0' would take the machine to the position where all joint positions are zero.AFAIU G53 should be set by homing and never be changed - that is the machines base offsets.
It seems a bit odd, neither here nor there:emccanon.SET_G5X_OFFSET(0, P[0], P[1], P[2], 0,0,0,0,0,0) index '0' could very well be 'set the current user system' - that is what it does in the higher gcode level.
Attachments:
Last edit: 11 Feb 2023 10:35 by Aciera.
Please Log in or Create an account to join the conversation.
- Aciera
- Topic Author
- Offline
- Administrator
Less
More
- Posts: 3969
- Thank you received: 1717
11 Feb 2023 10:39 #264285
by Aciera
Replied by Aciera on topic Change work offset values in a Pure Python remap w/o self.execute()
I start the config, home the machine and in MDI I set G54 and command to go to machine home:
g10 l2 p0 x100 y100 z100 a0 b0
g53 g0 x0 y0 z0
Nothing moves since we are already in home position and the DRO (as expected) reads:
Now I call a G69.9 remap that looks like this:
def g699(self):
emccanon.SET_G5X_OFFSET(0, 11, 22, 33, 0,0,0,0,0,0)
yield INTERP_OK
and the DRO changes to this:
then do an MDI call to go to machine home position: g53 g0 x0 y0 z0
and I get this:
and a follow MDI command: g54 g0 x0 y0 z0
gives me this:
l don't get it.
Anyway I decided to leave that alone and I manged to do the offset transformation before calling 'yield INTERP_EXECUTE_FINISH' so I could use 'self.execute(..)'
g10 l2 p0 x100 y100 z100 a0 b0
g53 g0 x0 y0 z0
Nothing moves since we are already in home position and the DRO (as expected) reads:
Now I call a G69.9 remap that looks like this:
Warning: Spoiler!
def g699(self):
emccanon.SET_G5X_OFFSET(0, 11, 22, 33, 0,0,0,0,0,0)
yield INTERP_OK
and the DRO changes to this:
then do an MDI call to go to machine home position: g53 g0 x0 y0 z0
and I get this:
and a follow MDI command: g54 g0 x0 y0 z0
gives me this:
l don't get it.
Anyway I decided to leave that alone and I manged to do the offset transformation before calling 'yield INTERP_EXECUTE_FINISH' so I could use 'self.execute(..)'
Attachments:
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23314
- Thank you received: 4861
20 Feb 2023 22:50 #264913
by andypugh
Replied by andypugh on topic Change work offset values in a Pure Python remap w/o self.execute()
I think that it is probably better to use emccanon commands in general.
Rather than self.execute("G53 G0...") try using emccanon.STRAIGHT_TRAVERSE()
github.com/LinuxCNC/linuxcnc/blob/master...l_intf/canon.hh#L245
Reading through the code in interp_convert.cc it seems like G53 is achieved by subtracting all the offsets from the commanded position and making the move in program coordinates, but I am not entirely clear about that.
Rather than self.execute("G53 G0...") try using emccanon.STRAIGHT_TRAVERSE()
github.com/LinuxCNC/linuxcnc/blob/master...l_intf/canon.hh#L245
Reading through the code in interp_convert.cc it seems like G53 is achieved by subtracting all the offsets from the commanded position and making the move in program coordinates, but I am not entirely clear about that.
Please Log in or Create an account to join the conversation.
- GCode and Part Programs
- G&M Codes
- Change work offset values in a Pure Python remap w/o self.execute()
Time to create page: 0.161 seconds