hi to all,
the problem:
in axis there is a signal " axis.0.joint-pos-fb" that it gives back the position of axis 0 (x in my case)
how I make to read the variable from a program python?
thanks
Alessandro
hi to all,
the problem:
in axis there is a signal " axis.0.joint-pos-fb" that it gives back the position of axis 0 (x in my case)
how I make to read the variable from a program python?
thanks
Alessandro
Hello
I have exactly the same question.
Did you find out how to proceed?
I will look at the emc2 and axis code to try to find the answer...
Thanks
Olivier
In your python code include python-HAL glue code.
your python program will create a HAL pin and then you connect the signal you want to read to it. (This will not be realtime though)
see:
Creating Userspace Python Components with the 'hal' module
By the way that signal name that was quoted is NOT from the AXIS display program.
see here:
EMC2's interface to HAL
Chris M
there is an example in the manual that i gave a link to.
you would need to change the pin type to s32 instead of float, as the pin you wish to connect to is an s32 pin.
then you would need to connect the pin you wish to read to the pin you made in the python program. You do that in a HAL file eg :
net signal_name motion.program-line passthrough.in
(using the example python program in the manual called passthrough)
#!/usr/bin/python
import hal, time
h = hal.component("passthrough")
h.newpin("in", hal.HAL_S32, hal.HAL_IN)
h.newpin("out", hal.HAL_S32, hal.HAL_OUT)
h.ready()
try:
while 1:
time.sleep(1)
h['out'] = h['in']
print h['in']
except KeyboardInterrupt:
raise SystemExit
try this version of passthrough...
Thanks for the quick reply!
But the question is slightly different. Here is my component pult.py :
[code]In the hal file:Code:#!/usr/bin/python import hal, time , serial h = hal.component("pult") h.newpin("out", hal.HAL_BIT, hal.HAL_OUT) h.newpin("a", hal.HAL_BIT, hal.HAL_OUT) h.newpin("b", hal.HAL_BIT, hal.HAL_OUT) h.newpin("c", hal.HAL_BIT, hal.HAL_OUT) h.newpin("numberin", hal.HAL_S32, hal.HAL_IN) h.newpin("numberout", hal.HAL_S32, hal.HAL_OUT) h.ready() h['a'] = False h['b'] = False h['c'] = False h['out'] = False try: while 1: time.sleep(1) ser = serial.Serial('/dev/ttyS0', 115200, timeout=1) x = ser.read() if x == '2' : h['out'] = True else : h['out'] = False if x == '3' : h['a'] = True h['b'] = False if x == '4' : h['b'] = True h['a'] = False if x == '5' : h['c'] = True ser.close() h['numberout'] = h['numberin'] n=h['numberout'] except KeyboardInterrupt: raise SystemExit
Now we are writing a new Python script:Code:loadusr -Wn pult python pult.py net numb motion.program-line pult.numberin
A variable "n" - from pult.py (n = h ['numberout'])Code:#!/usr/bin/python bla... bla...bla.. x=n
I have tried so:
The result of an error-Code:#!/usr/bin/python import pult x=n print n
The question is, how to use a value of "n" in any script?Code:>>> import pult HAL: ERROR: duplicate component name 'pult' Traceback (most recent call last): File "", line 1, in File "pult.py", line 4, in h = hal.component("pult") hal.error: Invalid argument >>> x=n Traceback (most recent call last): File " ", line 1, in NameError: name 'n' is not defined >>> print n Traceback (most recent call last): File " ", line 1, in NameError: name 'n' is not defined >>>
They here thus far prompted this method:
In the hal file:Code:from subprocess import Popen, PIPE a= Popen('halcmd getp minmax.0.max ', shell=True, stdout=PIPE).stdout.read() x=int(a) print x
Code:loadrt conv_s32_float addf conv-s32-float.0 servo-thread net numb motion.program-line conv-s32-float.0.in loadrt minmax addf minmax.0 servo-thread net numb1 conv-s32-float.0.out minmax.0.in