How to move a variable value with G-code

More
17 Nov 2024 09:23 #314648 by shaying526
I'm a beginner, I need to use G-code to move a value that may change.
This value comes from my vision camera, which is used to correct the positional deviation of my workpiece.
What I can currently think of is to write a Python script to generate G-code each time before it is called.
What is a more common method to achieve this?
Which chapter of the document should I read?

Please Log in or Create an account to join the conversation.

More
17 Nov 2024 10:37 - 17 Nov 2024 10:46 #314651 by Aciera
If you do not need to interact with a running gcode program then you could simply use the pyhton interface to send mdi commands
import linuxcnc
s = linuxcnc.stat()
c = linuxcnc.command()

def ok_for_mdi():
s.poll()
return not s.estop and s.enabled and (s.homed.count(1) == s.joints) and (s.interp_state == linuxcnc.INTERP_IDLE)


x = 1.23
y = 2.34
if ok_for_mdi():
   c.mode(linuxcnc.MODE_MDI)
   c.wait_complete() # wait until mode switch executed
   c.mdi("G0 X%s Y%s " % (x, y))


If you need to interact with running Gcode then use 'motion.*' pins.

1.  Get your python script to create hal pins. Example:

import hal
self.hal = hal.component("vision")
self.hal.newpin("enable", hal.HAL_BIT, hal.HAL_IN)
self.hal.newpin("done", hal.HAL_BIT, hal.HAL_OUT)
self.hal.newpin("input_value", hal.HAL_FLOAT, hal.HAL_IN)
self.hal.newpin("output_value", hal.HAL_FLOAT, hal.HAL_OUT)
self.hal.ready()

2.  Connect those hal pins to motion.* pins. Example:

net camera-enable <= motion.digital-out-00 => vision.enable
net camera-done <= vision.done => motion.digital-in-00
net camera-val-in <= motion.analog-out-00 => vision.input-value
net camera-val-out <= vision.output-value => motion.analog-in-00

3. in gcode read the motion.* pins and store in a variable:

m66 p0 l3 q2    ; wait for vision.done to go HIGH with 2 seconds timeout
o100 if [#5399 le 0]    ; timeout occured
    #1000 = 0
    (DEBUG, vision: timeout)
o100 else
    m66 e0 l0    ; read vision.output-value which is stored in #5399
    #1000 = [#5399]
o100 endif
Last edit: 17 Nov 2024 10:46 by Aciera.
The following user(s) said Thank You: shaying526

Please Log in or Create an account to join the conversation.

More
17 Nov 2024 10:40 #314652 by Aciera
The following user(s) said Thank You: shaying526

Please Log in or Create an account to join the conversation.

More
18 Nov 2024 01:23 #314709 by shaying526
Thank you for your reply. It's very clear and I will read it carefully

Please Log in or Create an account to join the conversation.

Time to create page: 0.074 seconds
Powered by Kunena Forum