How to move a variable value with G-code

More
1 year 11 months ago #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 to join the conversation.

More
1 year 11 months ago #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
Code:
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:

Code:
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:

Code:
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:

Code:
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

Please Log in to join the conversation.

More
More
1 year 11 months ago #314709 by shaying526
Thank you for your reply. It's very clear and I will read it carefully

Please Log in to join the conversation.

Time to create page: 0.094 seconds
Powered by Kunena Forum