Can I gets/sets a signal state from G-code?

More
04 Jan 2023 16:17 #260936 by clunc
I'd like to check and set the value of signal 'compensation-on' (defined as a result of installation of scotta's compensation component) with a G-code statement.

DEBUG perhaps?

Thank you.

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

More
04 Jan 2023 16:41 #260938 by PCW
check out M codes 62..65

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

More
04 Jan 2023 16:42 #260939 by andypugh
You can't write to HAL from G-code except via the motion.digital-out-NN and motion.analog-out-NN pins.
You can potentially read HAL values in G-code, but you only get their status at the point that the G-code program was started.
linuxcnc.org/docs/stable/html/gcode/over...gcode:ini-hal-params

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

More
04 Jan 2023 17:10 #260941 by roland

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

More
04 Jan 2023 18:32 #260944 by tommylight

A user defined command can write to hal
linuxcnc.org/docs/html/gcode/m-code.html#mcode:m100-m199

Probably translation, but that is not writing to hal.
Those are custom commands that may or may not use hal.

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

More
04 Jan 2023 19:00 - 04 Jan 2023 19:00 #260950 by roland
@clunc wants to set the value of a signal (or a pin?) with a G-Code statement.
With user defined commands you can do this. That's what I meant 
Last edit: 04 Jan 2023 19:00 by roland.

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

More
04 Jan 2023 19:23 #260953 by clunc
Thank you all.

[Like the Wind in the Willows' Mr. Toad, something else already caught my attention. I'm looking at adding a button in a PyVCP panel in AXIS to toggle the state of Z-compensation.

And it's working. ...except for that Toggling part, which I can't figure out. I've got the button and a working LED both showing in the PyVCP panel. The LED goes off and on when I toggle the 'compensation-on' signal with 'sets' in halshow, but I haven't worked out how to connect the button defined in pyvcp-panel.xml to the proper compensation entity in the proper .hal file.]

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

More
04 Jan 2023 20:36 - 04 Jan 2023 20:40 #260959 by Todd Zuercher
Your pyvcp button, simply connect its hal pin output to the hal input pin you want it to change, the exact same way as you connected it to the pyvcp LED's hal input pin.  You can do that with the net command in any of your hal files with just the signal name or on the same line as the net for the pyvcp output pin in your post gui hal file.  If you were wanting a true "toggle" function (click on, click again off) you will have to use a pyvcp radio button.  Those create two hal pins per button, the output pin "name" and an input pin "name.changepin".  Use the input pin "name.changepin" to toggle the check button's setting from an other hal pin output (same as clicking the button on the screen.)  If you want a button with toggle function that looks different than a check button you will need to use another VCP such as Gladevcp to do it.

Maybe the way I configured the GladeVCP for one of my machines might help you.  In it I have a pair of toggle buttons for turning on and off the vacuum clamping for the router table.  There are also two custom M-codes that can turn the vacuum on and off (M111 and M112) automatically withing a G-code program.  The custom M-codes use bash scripted hal commands to setp (sets it true for tenth of a sec then back to false) the value of a hal pin created in the Glade pannel's handler file.  I did it this way so that changing the clamping with the M-codes changes the button indicator status in the pannel so they match on/off same as pressing the buttons.

I've posted the entire config previously to other threads here is a link to it.
forum.linuxcnc.org/media/kunena/attachments/3190/2PID.zip
 
Attached below are just the glade and handler files. (They aren't stellar examples of programming but they fuction.)
Attachments:
Last edit: 04 Jan 2023 20:40 by Todd Zuercher.

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

More
04 Jan 2023 23:54 - 04 Jan 2023 23:56 #260974 by clunc
Thanks, Todd.  I got a "checkbutton" working (which is essentially a toggle) by adding this to AXIS's existing 'custom_postgui.hal' file in the machine's config/ folder:
        net compensation-on     pyvcp.zcomp-chkbtn

after having added this to the existing 'pyvcp-panel.xml' file there, just before the closing '</pyvcp>' tag:
        <labelframe text="Z-COMPENSATION">
        <vbox>
        <relief>RIDGE</relief>
        <bd>6</bd>
                <checkbutton>
                        <font>;("Helvetica",30)</font>
                        <width>3</width>
                        <halpin>"zcomp-chkbtn"</halpin>
                        <text>"Z-comp ON"</text>
                </checkbutton>
                <label>
                        <text>"Z-comp state:"</text>
                        <font>;("Helvetica",20)</font>
                </label>
                <hbox>
                    <label>
                            <text>"             "</text>
                            <font>;("Helvetica",20)</font>
                    </label>
                    <led>
                        <halpin>"compensation-on-led"</halpin>
                        <size>30</size>
                        <on_color>"green"</on_color>
                        <off_color>"red"</off_color>
                    </led>
                </hbox>
        </vbox>
        </labelframe>

From the documentation, I gather I connected pin 'zcomp-chkbtn' to signal 'compensation-on'. (At one point I was getting an error from trying to connect the pin to another pin, 'compensation.enable-in', and it was the documentation that suggested to me I should be looking for a signal to connect to.)
 
Last edit: 04 Jan 2023 23:56 by clunc.

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

More
05 Jan 2023 19:04 #261019 by Todd Zuercher
Some basic hal tutoring, net statement contains at least 3 things and can have more.
1st the "net" command, 2nd a signal name. ALL net commands in your hal file must have and begin with these two items. The signal name is an arbitrary name that you make up. It can quite literally be almost anything. Multiple hal commands in the same and other hal files can reference the same signal name connecting more hal pins to the same signal.  So be descriptive with your signal names.  (There are some character limitations for signal names, no spaces...)

If you try to create a net command that doesn't have a signal name, connecting two hal pins, the first hal pin name will be used as the signal name and you won't connect the two hal pins. You will end up with a signal named with the same name as your first hal pin with the 2nd hal pin connect to that, and your first hal pin will not be connected to anything. 

After the "net" and "signal name" you start listing hal pins that will be connected to the signal name.  There is no required order of connecting the hal pins, the only requirements is that only one output pin can be connected to a signal, and a hal pin can never be connected to more than one signal.   You may connect as many input pins as you like to a signal.  Be careful some hal pin names are a little deceiving as to their hal input or output status, for example parport.0.pin-01-out is actually a hal input pin. 

Hal net statements can also be punctuated with ==> or <==.  (I like to use them) but they are for human readability only and have no effect on a signal's or halpin's direction or status as an input or output, leaving them out or putting them in wrong has no effect.

Post the snipbits of hal code you are trying to write.  That is almost certainly where your problem lies.

And remember if the hal pin you want to use is already in use elsewhere in this or another hal file it will cause an error and Linuxcnc won't start.  You may still be able to use it by connecting to that signal, or there are other work arounds that may be possible with hal logic.
The following user(s) said Thank You: tommylight, Unlogic

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

Time to create page: 0.115 seconds
Powered by Kunena Forum