Read the S-Command in the HAL

More
28 Mar 2025 20:05 #325187 by Wiesi-94
Read the S-Command in the HAL was created by Wiesi-94
Hello,
I'm currently implementing a retrofit for our SHW UF31. So far, progress is pretty good. But I have a small problem with the gear selection.
I'm using Classic Ladder to shift the three gears. It works quite well so far. I have a float input for the spindle speed, which is used to select and engage the correct gear.

The plan is to use the S command to set the gear. But I don't know which HAL pin I can use to query the set speed without the spindle running.

So what I need is a way to read this system parameter in the HAL / Classic Ladder:
#<_rpm> - Return the current value of S, not the actual spindle speed.

Best regards, Stefan

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

More
29 Mar 2025 05:11 #325225 by cmorley
Replied by cmorley on topic Read the S-Command in the HAL
you could try something this:
linuxcnc.org/docs/devel/html/gui/gstat.h...mponent_code_pattern

but use the message 's-code-changed'

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

More
31 Mar 2025 16:35 #325411 by Wiesi-94
Replied by Wiesi-94 on topic Read the S-Command in the HAL
That works, thanks!!
The following user(s) said Thank You: cmorley

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

More
21 May 2025 22:28 #328879 by Doc_emmet
Replied by Doc_emmet on topic Read the S-Command in the HAL
Hello, can you show me how to read the S command and what you changed.   

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

More
22 May 2025 11:26 #328906 by Todd Zuercher
Replied by Todd Zuercher on topic Read the S-Command in the HAL
To do the above suggestion to get a hal pin that shows the commanded S speed even when the spindle is stopped. The link gives instructions for creating a python script that reads what the commanded S speed settinging is from the Gstat python module and then creates a hal pin and writes the value to it.

You will need to create at python script with the following, and save it as a file in your config directory named "spindle.py" and make that file executable.
#!/usr/bin/env python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GObject
from gi.repository import GLib
import hal
from hal_glib import GStat
GSTAT = GStat()

# callback to change HAL pin state
def mode_changed(obj, data):
        h['speed'] = data

# Make a component and pins
h = hal.component("spindle_setting")
h.newpin("speed", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()

# connect a GSTAT message to a callback function
GSTAT.connect("s-code-changed",mode_changed)

# force GSTAT to initialize states
GSTAT.forced_update()

# loop till exit
try:
    GLib.MainLoop().run()
except KeyboardInterrupt:
    raise SystemExit

Then load/run that python script when you start Linuxcnc by adding this line to your hal file for your config. (Replacing YOUR_CONFIG with the name of your config dir.)
loadusr python3 ~/linuxcnc/configs/YOUR_CONFIG/spindle.py

You can even test this before adding it to your hal file by simply running the python script from command line while Linuxcnc is running. Just type "python3 ~/linuxcnc/configs/YOUR_CONFIG/spindle.py" and hit enter. (After first creating the spindle.py file, saving it to your config dir.)
The following user(s) said Thank You: Benb

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

More
22 May 2025 22:01 #328946 by Doc_emmet
Replied by Doc_emmet on topic Read the S-Command in the HAL
Thanks, it works

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

Time to create page: 0.122 seconds
Powered by Kunena Forum