Running a py file from a button
- btvpimill
- Offline
- Elite Member
- Posts: 220
- Thank you received: 3
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
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.
- ArcEye
- Offline
- Junior Member
- Posts: 25
- Thank you received: 761
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.
- andypugh
- Offline
- Moderator
- Posts: 23310
- Thank you received: 4858
#!/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.
- mhaberler
- Offline
- Moderator
- Posts: 197
- Thank you received: 11
amoffat.github.com/sh/index.html
- Michael
Please Log in or Create an account to join the conversation.
- eszyman
- Offline
- New Member
- Posts: 11
- Thank you received: 0
Please Log in or Create an account to join the conversation.
- btvpimill
- Offline
- Elite Member
- Posts: 220
- Thank you received: 3
@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.
- btvpimill
- Offline
- Elite Member
- Posts: 220
- Thank you received: 3
Please Log in or Create an account to join the conversation.
- ArcEye
- Offline
- Junior Member
- Posts: 25
- Thank you received: 761
Yes, a limiting factor that if removed would open up a lot of possibilities.is it true that with your method I can only pass P and Q? so only 2 arguments?
www.linuxcnc.org/docs/devel/html/gcode/o....html#sec:parameters... but I don't see that in the doc's for #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.
- btvpimill
- Offline
- Elite Member
- Posts: 220
- Thank you received: 3
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.
- mhaberler
- Offline
- Moderator
- Posts: 197
- Thank you received: 11
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.