Running HAL commands from python?

More
4 years 3 months ago #247116 by thadwald
Hi
I am working on a custom UI with gscreen. Is it possible to run arbitrary HAL commands from python?

If so, how? Examples?

Thanks!
 

Please Log in to join the conversation.

More
4 years 3 months ago #247127 by phillc54
There are some examples using the Hal module and hal_glib module here:
linuxcnc.org/docs/2.8/html/hal/halmodule.html

Please Log in to join the conversation.

More
4 years 3 months ago #247231 by thadwald
Thanks for the reply.

I looked this over and I don’t think that “creating a user space component” is what I need to do.

I need to somehow start and stop a realtime thread, among other things. Is this possible?

Please Log in to join the conversation.

More
4 years 3 months ago #247493 by andypugh
import os
os.system("halcmd start")

Not super satisfying, but works.

Please Log in to join the conversation.

More
4 years 3 months ago #247583 by thadwald
Thank you.

Actually, what I think I want is:
os.system("halcmd -kf")

This appears to work but then it doesn't return and my program is stuck. I can't find an "exit" command for halcmd. Does it have one?
Otherwise, is there a way to send a ctrl-c as part of a script?


Edit: my bad; I was under the impression that I need to provide the -f option to interact with the current instance ...
 

Please Log in to join the conversation.

More
4 years 3 months ago #247593 by andypugh
To get out of the halcmd prompt you normally do use "exit"

But I have no idea where you are if you have done that from inside Python.

Please Log in to join the conversation.

More
4 years 3 months ago #247595 by thadwald
My mistake was to use the -f option. When I run each line with halcmd, the commands work.

I have another issue now.
When I run the following command:
Code:
halcmd loadrt threads name1=cmm-thread period1=10000000000

The command works; it adds the thread. but it causes the hm2 watchdog to time out. 
Is there a good way around this issue? Can I temporarily disable the hm2 watchdog?
It is easy enough to reset the watchdog but then I need to re-home the machine. For this specific use case, re-homing isn't a showstopper but it is not preferable.

More generally, what I am trying to accomplish is to create a cmm using sampler. It is important for this application to set the sample frequency to an arbitrary value, so I want to run it in a separate thread.

Should I abandon this approach and just parse and cull the sampler output instead?  



 

Please Log in to join the conversation.

More
4 years 3 months ago #247603 by andypugh
Do you really want a 1 second thread? That seems to be more than the usual number of zeros.

Please Log in to join the conversation.

More
4 years 3 months ago #247604 by thadwald
No, I fat-fingered a few too many in there. The actual period is calculated from scan speed and point interval specified by the user.

Please Log in to join the conversation.

More
4 years 3 months ago #247921 by andypugh
There is, I think, some sort of limitation that threads have to be added in order, though I am not sure i it is slow to fast or vice-versa.

I would try experimenting in a bare halcmd prompt and see what happens.

Code:
halcmd -kf loadrt threads name1=thread1 period1=200000 unload threads loadrt threads name2=thread2 period=1000000 exit

ie, see what you are allowed to do without the rest o LinuxCNC interfering.

Please Log in to join the conversation.

Time to create page: 0.105 seconds
Powered by Kunena Forum