Running HAL commands from python?

More
12 Jul 2022 04:47 #247116 by thadwald
Running HAL commands from python? was created 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 or Create an account to join the conversation.

More
12 Jul 2022 09:19 #247127 by phillc54
Replied by phillc54 on topic Running HAL commands from python?
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 or Create an account to join the conversation.

More
13 Jul 2022 12:43 #247231 by thadwald
Replied by thadwald on topic Running HAL commands from python?
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 or Create an account to join the conversation.

More
16 Jul 2022 19:12 #247493 by andypugh
Replied by andypugh on topic Running HAL commands from python?
import os
os.system("halcmd start")

Not super satisfying, but works.
The following user(s) said Thank You: thadwald

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

More
17 Jul 2022 19:28 - 17 Jul 2022 20:06 #247583 by thadwald
Replied by thadwald on topic Running HAL commands from python?
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 ...
 
Last edit: 17 Jul 2022 20:06 by thadwald.

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

More
17 Jul 2022 20:47 #247593 by andypugh
Replied by andypugh on topic Running HAL commands from python?
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 or Create an account to join the conversation.

More
17 Jul 2022 21:17 #247595 by thadwald
Replied by thadwald on topic Running HAL commands from python?
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:
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 or Create an account to join the conversation.

More
17 Jul 2022 22:58 #247603 by andypugh
Replied by andypugh on topic Running HAL commands from python?
Do you really want a 1 second thread? That seems to be more than the usual number of zeros.

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

More
17 Jul 2022 23:07 #247604 by thadwald
Replied by thadwald on topic Running HAL commands from python?
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 or Create an account to join the conversation.

More
21 Jul 2022 09:13 - 21 Jul 2022 09:14 #247921 by andypugh
Replied by andypugh on topic Running HAL commands from python?
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.

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.
Last edit: 21 Jul 2022 09:14 by andypugh. Reason: The manpage mentions unloading and loading again to add a thread.

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

Time to create page: 0.069 seconds
Powered by Kunena Forum