METRIC / SAE Indicator for pyVCP

More
9 years 11 months ago #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
9 years 11 months ago #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
9 years 11 months ago #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
9 years 11 months ago #83386 by screwtop
Interesting question. I found a couple of pertinent global variables, but don't know that you can access these from pyVCP:
Code:
#<_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:
Code:
emcStatus->task.programUnits emcStatus->motion.traj.linearUnits
and also in src/emc/usr_intf/axis/extensions/emcmodule.cc:
Code:
{(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
9 years 11 months ago #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:
Code:
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
9 years 11 months ago - 9 years 11 months ago #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.
Code:
#!/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: 9 years 11 months ago by cmorley.

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

Time to create page: 0.128 seconds
Powered by Kunena Forum