Running a py file from a button

More
20 Sep 2012 12:48 #24454 by btvpimill
Running a py file from a button was created by btvpimill
Not sure if this is the right forum, its a little about GladeVCP and a little advanced config. Move if needed PLEASE

I have written small py program that will change the HOME_OFFSET values for each axis in the INI file. My question is this:
I want to be able to press a button created with GladeVCP and have it run the code, but I also need it to pass the current joint positions to the code. I am not sure how to :

A) execute the code
and
B) pass the #xxxx values for current position. (I do know what each #xxxx is for each joint)

I am sure this is dead easy, but as yet I don't see it.

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

More
20 Sep 2012 15:22 #24462 by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button
Hi

One way that springs to mind

net your button to halui.mdi-command.NN

Set that mdi command in your ini file to call a user M code file, M100 for example, passing the vars for the axes you want
For example 'M100 P#5221 Q#5222 will pass position of X and Y in G54 offset system

In your user M code file use the passed data to call your py program
for instance

#!/bin/bash
python mypyfile.py $1 $2


would pass the 2 arguments to M100 as arguments to your python file

regards

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

More
20 Sep 2012 15:43 #24467 by andypugh
Replied by andypugh on topic Re:Running a py file from a button
ArcEye wrote:

#!/bin/bash
python mypyfile.py $1 $2


I think that simply renaming the python file to M101 and having it start with #! bin/python ought to work.

It ought to be able to call the Python direct from Glade, though, without any need to mess about with pins in HAL:
www.linuxcnc.org/docs/html/gui/gladevcp....#_emc_action_widgets shows how to call an MDI command,
or look in section 8 for a neater way.

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

More
20 Sep 2012 15:59 #24471 by mhaberler
Replied by mhaberler on topic Re:Running a py file from a button
I recently found a clever Python module which makes it very easy to execute arbitrary shell commands:

amoffat.github.com/sh/index.html

- Michael

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

More
20 Sep 2012 16:06 #24473 by eszyman
Replied by eszyman on topic Re:Running a py file from a button
We can load a handlers.py, per section 8, in fact, because I followed the tutorial, we already try to, although it does not exist yet! haha

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

More
20 Sep 2012 16:20 #24478 by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
Thanks Andy and Michael.

@Andy - is it true that with your method I can only pass P and Q? so only 2 arguments?

@Michael - that looks really intresting - and a bit over my head right now.

In any event, I would like to be able to pass all 9 joint locations, and best if they were G53 positions but I don't see that in the doc's for #parameters. I can live with position based on any Gxx enviroment as I can do the math backwards to get the true machine position, then pass the actual position to the script. OR just make sure there is no offsets loaded in the current Gxx offset system.

This may seem like a lot of work just to set the HOME_OFFSET values, but I am trying to make it more user friendly. (and keep users out of my configs where they will surely mess something up)

The end goal once this small step is achieved will be a config GUI much like stepconf, only able to deal with all 9 axis instead of 3, and allow you to edit existing configs without overwriting what has been done outside the scope of stepconf.

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

More
20 Sep 2012 16:22 #24479 by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
eszyman, does that mean we know how to pass all 9 joint positions also?

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

More
21 Sep 2012 08:33 #24501 by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button

is it true that with your method I can only pass P and Q? so only 2 arguments?

Yes, a limiting factor that if removed would open up a lot of possibilities.

... but I don't see that in the doc's for #parameters.

www.linuxcnc.org/docs/devel/html/gcode/o....html#sec:parameters

specifically
5420-5428 Current Position including all offsets and in the current program units for X, Y, Z, A, B, C, U, V & W. In absolute machine coordinates, volatile.

The easiest way at present to pass 9 co-ordinates would probably be to pass them in pairs to an intermediate script which writes to file, then your py program can open the file and read them.

regards

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

More
21 Sep 2012 10:03 #24503 by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
Thanks ArcEye, looks like that intermediate step is how it will have to be done.

As for the parameters to be passed, My impression of the "current position set" (5420-5428) is it includes any active offsets. This is not a HUGE issue, but would be nice if there was a way to get the actual machine position, not the reported position after offsets.

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

More
21 Sep 2012 10:13 #24504 by mhaberler
Replied by mhaberler on topic Re:Running a py file from a button
the description

5420-5428 Current Position including all offsets and in the current program units for X, Y, Z, A, B, C, U, V & W. In absolute machine coordinates, volatile.

is a bit ambigouous - it IS in absolute machine coordinates, so the concept of offsets does not relate to these values.

- Michael

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

Moderators: HansU
Time to create page: 0.068 seconds
Powered by Kunena Forum