Hal Standalone. some trouble..

More
7 years 1 month ago #145067 by dab77
Hi, my project of a Hal standalone Gui to control a couple of motor is going on.
Working with python, I finally managed how to write it.
First I had to change from python3 to python2, because it seems to me that hal module cannot be imported in python3 (if I'm wrong please, tell me)
Than I choose Gtk, which is more natural in LinuxMint, and should be also cross-platform.

Till now I could create a hal file in-place based on the number of motors choosed (at the moment from 1 to 8, because using stepgen) and the buttons and scales in the gui also are created according to that number.

I've set all the stepgen in position mode, and it works ok, also the position feedback going back to the gui is perfectly shown.

The first big problem I cannot resolve, is deceleration in case the 'GO' button is released in the middle of a movement.
If I set stepgen.x.enable 0, the stepgen stops instantly. So I've tried to set stepgen.x.maxvel to 0, but that doesn't stop the current movement.

So here's my question:
Do you know how does it work in Axis when in jog-mode you have decelerations when stop jogging? are the stepgen temporarly set in velocity mode?

thanks, Davide.

Please Log in to join the conversation.

More
7 years 1 month ago #145071 by BigJohnT
Did you set the stepgen.N.maxaccel for each axis.

JT

Please Log in to join the conversation.

More
7 years 1 month ago #145072 by dab77
Thanks John for your fast answer.
Yes I did.
this is the GO release code:
Code:
def on_jog_go_released(self, button, name): .... for i in range(n_mot): try: os.system("halcmd setp stepgen.%d.maxvel %d" % (i, 0)) print("vel %d changed to 0" % (i)) except KeyboardInterrupt: print("Vel set error..") ...

But I just discovered that if instead of '0', i set stepgen.x.maxvel to 1 it works as expected, meaning that it decelerates as soon as I release th GO button, but unfortunately it goes at 1-speed, doesn't stop.

In the meantime I also want to ask: instead of calling "os.system("command")", is there a way to directly change a Hal Parameter in python? I've looked in the code, but didn't find anything about that..

Please Log in to join the conversation.

More
7 years 1 month ago #145086 by Tower

dab77 wrote: (...)
In the meantime I also want to ask: instead of calling "os.system("command")", is there a way to directly change a Hal Parameter in python? I've looked in the code, but didn't find anything about that..


Well, there are few ways how to solve this, you can create HAL Python Userspace component which will create the HAL pins which you will be changing in your Python written program. And then you connect these pins inside the HAL layer to actual pins you need to change. That is described here: linuxcnc.org/docs/html/hal/halmodule.html .

Or you can create Python wrappers around the C hallib functions. That is probably quite a bit of work, but you can find the inspiration here: github.com/machinekit/machinekit-hal/tre...al/cython/machinekit

Or you can create direct connector to the HAL shared memory space and change values here. This is the most hard-core option and I would not recommend this.

Please Log in to join the conversation.

More
7 years 1 month ago #145091 by cmorley

Well, there are few ways how to solve this, you can create HAL Python Userspace component which will create the HAL pins which you will be changing in your Python written program. And then you connect these pins inside the HAL layer to actual pins you need to change. That is described here: linuxcnc.org/docs/html/hal/halmodule.html .


You don't have to connect pins. There are some functions to do direct commands - depends on the version of linuxcnc.
in 2.7 fairly limited:
linuxcnc.org/docs/2.7/html/hal/halmodule...l#_helpful_functions
in 2.8 + a fair bit better (get_value is very useful):
linuxcnc.org/docs/2.8/html/hal/halmodule...l#_helpful_functions

Chris

Please Log in to join the conversation.

More
7 years 1 month ago #145096 by Tower

cmorley wrote: You don't have to connect pins. There are some functions to do direct commands - depends on the version of linuxcnc.
in 2.7 fairly limited:
(...)


Interesting, I didn't know about it. I presume there is no chance for some push notification pattern without major HAL rework, right?
(I am not Python developer, so I don't know what you are calling it in parseltongue.)

Please Log in to join the conversation.

More
7 years 1 month ago #145098 by cmorley
push notification?

Please Log in to join the conversation.

More
7 years 1 month ago #145121 by dab77

Tower wrote:

dab77 wrote: (...)
In the meantime I also want to ask: instead of calling "os.system("command")", is there a way to directly change a Hal Parameter in python? I've looked in the code, but didn't find anything about that..


Well, there are few ways how to solve this, you can create HAL Python Userspace component which will create the HAL pins which you will be changing in your Python written program. And then you connect these pins inside the HAL layer to actual pins you need to change. That is described here: linuxcnc.org/docs/html/hal/halmodule.html .

no, i need to change a parameter, not a pin, so i cannot link a signal to a parameter..

Or you can create Python wrappers around the C hallib functions. That is probably quite a bit of work, but you can find the inspiration here: github.com/machinekit/machinekit-hal/tre...al/cython/machinekit

Or you can create direct connector to the HAL shared memory space and change values here. This is the most hard-core option and I would not recommend this.

Please Log in to join the conversation.

More
7 years 1 month ago #145122 by dab77

cmorley wrote:

Well, there are few ways how to solve this, you can create HAL Python Userspace component which will create the HAL pins which you will be changing in your Python written program. And then you connect these pins inside the HAL layer to actual pins you need to change. That is described here: linuxcnc.org/docs/html/hal/halmodule.html .


You don't have to connect pins. There are some functions to do direct commands - depends on the version of linuxcnc.
in 2.7 fairly limited:
linuxcnc.org/docs/2.7/html/hal/halmodule...l#_helpful_functions
in 2.8 + a fair bit better (get_value is very useful):
linuxcnc.org/docs/2.8/html/hal/halmodule...l#_helpful_functions

Chris

really, i couldn't find those functions anywhere!
thank you.
i think what i need is hal.set_p() wishing it can change parameters too.

than i still don't understand if i can toggle the stepgen command mode between velocity and position, to solve the deceleration problem.

Please Log in to join the conversation.

More
7 years 1 month ago #145129 by dab77
the problem is this:
Code:
>>> import hal >>> hal.set_p("stepgen.0.maxaccel", "22") Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: Cannot call before creating component >>>
I don't know how to refer to hal components.

I have also tried what is suggested in that page, while running linuxcnc, but without success:
Code:
>>> os.system("halcmd show comp") Loaded HAL Components: ID Type Name PID State 82 User halcmd4120 4120 ready 76 User axisui 4108 ready 74 User inihal 4104 ready 65 RT match8 ready 62 RT wcomp ready 57 RT comp ready 54 RT or2 ready 49 User hal_manualtoolchange 4088 ready 43 RT scale ready 40 RT near ready 37 RT lowpass ready 34 RT limit2 ready 31 RT sim_spindle ready 26 RT hypot ready 23 RT ddt ready 20 RT __servo-thread ready 19 RT motmod ready 16 RT trivkins ready 10 User halui 4065 ready 4 User iocontrol 4063 ready 0 >>> value = hal.get_value("iocontrol.0.emc-enable-in") Traceback (most recent call last): File "<stdin>", line 1, in <module> RuntimeError: Can't set value: pin / param iocontrol.0.emc-enable-in not found >>>
..and obviously the pin was there:
Code:
.... 4 bit OUT FALSE iocontrol.0.coolant-flood 4 bit OUT FALSE iocontrol.0.coolant-mist 4 bit IN TRUE iocontrol.0.emc-enable-in <== estop-loop 4 bit OUT TRUE iocontrol.0.lube 4 bit IN FALSE iocontrol.0.lube_level ....

I've forgot to say that I have Linuxcnc 2.9.0 on..

Please Log in to join the conversation.

Time to create page: 0.360 seconds
Powered by Kunena Forum