METRIC / SAE Indicator for pyVCP

More
26 Nov 2016 04:18 #83326 by Askjerry
Is there some kind of a hal pin that I can look at and point to a graphic so that I have a quick indication if the machine is in SAE or METRIC mode?

I want to make a pyVCP graphic... yellow with "METRIC" or blue with "INCH" that is pretty easy to see... I know how to make graphos. net them... etc... just looking for something like halui.mode.is-mm or similar that will give me a true/false.

Exists???

Jerry

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

More
26 Nov 2016 14:57 #83342 by Todd Zuercher
No there isn't a hal pin that I know of. If you use a GladeVCP though it is fairly simple to uses a Linuxcnc Stat object to get it. Another option would be a custom hal component to get it.

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

More
26 Nov 2016 15:56 #83345 by Askjerry
Yeah... I haven't figured out custom HAL yet... I know there is a list of active G-Codes shown in the MDI section... if I could find out where that variable was and look for G20 or G21... but I don't have the time to dig into that quite yet. I was looking for a quick indicator... guess it's going to turn into a "project" instead.

Thanks,
Jerry

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

More
28 Nov 2016 01:15 #83386 by screwtop
Interesting question. I found a couple of pertinent global variables, but don't know that you can access these from pyVCP:
#<_metric> - Return 1 if G21 is on, else 0.
#<_imperial> - Return 1 if G20 is on, else 0.
I had a rummage around in the source and couldn't find a HAL pin for this. It would be useful, though, and I think probably should exist for completeness. I found the following possibly useful leads in src/emc/task/emccanon.cc:
emcStatus->task.programUnits
emcStatus->motion.traj.linearUnits
and also in src/emc/usr_intf/axis/extensions/emcmodule.cc:
    {(char*)"linear_units", T_DOUBLE, O(motion.traj.linearUnits), READONLY},
I haven't written a custom HAL component either, but maybe this would be a good one to start with... :)

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

More
28 Nov 2016 01:22 #83387 by screwtop
Also, it seems it's not just a question of mm or inches: in places the code has support for mm, cm, inches, custom, and auto! But the core EMC code seems to be limited to mm, cm or inches for the canonical units; this from src/emc/nml_intf/canon.hh:
typedef int CANON_UNITS;
#define CANON_UNITS_INCHES 1
#define CANON_UNITS_MM 2
#define CANON_UNITS_CM 3

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

More
28 Nov 2016 05:50 - 28 Nov 2016 05:51 #83389 by cmorley
Here is working sample code of a python component for metric (G20/21) status
The python component info is somewhat explained here:
www.linuxcnc.org/docs/2.7/html/hal/halmodule.html
name it metric_status , add it into an appropriate folder ($PATH in a terminal should show you)
and make it executable

One caveat, displayed Gode in a running linuxcnc program, can be wrong because of read ahead.
This one is fairly safe as not too many people change the units mid program.
#!/usr/bin/env python
import linuxcnc
import hal,time

metric = False

h = hal.component("metric_status")
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()

status = linuxcnc.stat()
try:
    while 1:
        # update once a second
        time.sleep(1)
        # poll current status
        status.poll()
        # search active G codes
        # only check whole numbered Gcodes
        for i in sorted(status.gcodes[1:]):
            if i == -1: continue
            if i % 10 == 0:
                if i == 210:
                    metric = True
                    break
                elif i == 200:
                    metric = False
                    break
        # Update pin
        h['out'] = metric
except KeyboardInterrupt:
    raise SystemExit

Hope that helps!
Chris M
Last edit: 28 Nov 2016 05:51 by cmorley.

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

More
28 Nov 2016 13:39 #83393 by Askjerry
Wow... I'll have to look into this.

Update of the display is not an issue... the main impetus for this was that I went to move the bit 10mm the other day during a job so I typed in G0 X10 expecting the bit to move slightly... as it continued way past where expected and scratched the surface... I realized by buddy had typed in G20 because he prefers inches.

I thought it would be good to have some obvious icon in the pyVCP panel to catch my eye... more than just the text in the little display box that is easily missed. I was hoping for a more "stock" solution... something I could just share with others like, "paste this into your pyVCP panel and you are good." But perhaps this is better... it may force me to learn new tools... new skills, and get a bit deeper into the system.

I'll give it a try sometime this week and report back.

Thanks!
Jerry

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

More
28 Nov 2016 16:37 #83398 by Todd Zuercher

Here is working sample code of a python component for metric (G20/21) status
The python component info is somewhat explained here:
www.linuxcnc.org/docs/2.7/html/hal/halmodule.html
name it metric_status , add it into an appropriate folder ($PATH in a terminal should show you)
and make it executable

One caveat, displayed Gode in a running linuxcnc program, can be wrong because of read ahead.
This one is fairly safe as not too many people change the units mid program.


Wouldn't it make more sense to pole the stat.program_units rather than trying to pick out the active g-code something like this?
#!/usr/bin/env python
import linuxcnc
import hal,time

metric = False

h = hal.component("unit_status")
h.newpin("out", hal.HAL_BIT, hal.HAL_OUT)
h.ready()

status = linuxcnc.stat()
try:
    while 1:
        # update once a second
        time.sleep(1)
        # poll current status
        status.poll()
        # check program units
        if status.program_units == 2:
                metric = True
        if status.program_units == 1:
                metric = False
        # Update pin
        h['out'] = metric
except KeyboardInterrupt:
    raise SystemExit

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

More
28 Nov 2016 18:05 - 28 Nov 2016 18:06 #83402 by Askjerry
Ultimately, it would be nice if this were a signal standard in HAL.

For example, there is a signal I use called halui.program.is-running which lights up a red bar where the jog buttons of my panel are... at a glance, I can tell that I have some background task running, and that I have to wait. Really simple to implement.

I was hoping there would have been something like halui.units.mm and/or halui.units.inch that I could look for and react to. Generally... to share my advanced pyVCP panels with others. (Doing a YouTube series on LinuxCNC currently.)

So mostly... looking for something a neophyte could easily do. Still wondering if I can somehow hook the #<_metric> variable.
Jerry
Last edit: 28 Nov 2016 18:06 by Askjerry.

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

More
29 Nov 2016 04:52 #83416 by cmorley

Ultimately, it would be nice if this were a signal standard in HAL.


I was hoping there would have been something like halui.units.mm and/or halui.units.inch that I could look for and react to.


I would assume that because of the read ahead problem - these type of signals were not made.
There is a branch in development that tries to fix the read ahead problem. If this gets merged in the future then pins with this kind of
info would make much more sense.

Chris M

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

Time to create page: 0.193 seconds
Powered by Kunena Forum