Running a py file from a button
21 Sep 2012 11:20 #24506
by BigJohnT
Replied by BigJohnT on topic Re:Running a py file from a button
Starting from X0
(debug,#5420)
0.000000
g0x1
(debug,#5420)
1.000000
touchoff X to 0
(debug,#5420)
0.000000
(debug,#5221) shows the g54 x offset
1.000000
They do seem to include any offsets and show the same value as the DRO does.
John
(debug,#5420)
0.000000
g0x1
(debug,#5420)
1.000000
touchoff X to 0
(debug,#5420)
0.000000
(debug,#5221) shows the g54 x offset
1.000000
They do seem to include any offsets and show the same value as the DRO does.
John
Please Log in or Create an account to join the conversation.
21 Sep 2012 11:39 #24507
by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
Thanks for the clarity John,
The best thing to do for my purpose is to ensure the current workspace (G5x) is all cleared. This could be a user requirment, or done programaticly. I think making it a user responsibility makes the most sense, after all this is not a procedure that needs to be done much (usually only once on machine setup), as such at that point there is NO reason to have any active user offsets.
There also needs to be a confirmation to the button in case Johns cat were to push it.
The best thing to do for my purpose is to ensure the current workspace (G5x) is all cleared. This could be a user requirment, or done programaticly. I think making it a user responsibility makes the most sense, after all this is not a procedure that needs to be done much (usually only once on machine setup), as such at that point there is NO reason to have any active user offsets.
There also needs to be a confirmation to the button in case Johns cat were to push it.
Please Log in or Create an account to join the conversation.
21 Sep 2012 13:31 - 24 Sep 2012 14:49 #24510
by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button
mhaberler wrote:
I can hear JTs document editing quill scratching as we speak.
The other neater solution that occurs, is to write a userspace component, which links to Xpos, Ypos, Zpos ..........Cpos signals.
When triggered it could write to file, pass the value via an out pin, or even call your python program with the pin values as parameters.
Those signals show the machine position irrespective of the offset being used.
regards
More than a bit, I have never used them but assumed that if they were in absolute machine co-ordinates, it meant just that.is a bit ambiguous
I can hear JTs document editing quill scratching as we speak.
The other neater solution that occurs, is to write a userspace component, which links to Xpos, Ypos, Zpos ..........Cpos signals.
When triggered it could write to file, pass the value via an out pin, or even call your python program with the pin values as parameters.
Those signals show the machine position irrespective of the offset being used.
regards
Last edit: 24 Sep 2012 14:49 by ArcEye.
Please Log in or Create an account to join the conversation.
21 Sep 2012 13:36 - 21 Sep 2012 13:37 #24511
by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
The neater solution sounds really good, but will we be able to pass more than 2 parameters at a time? I don't actually know how to implement your suggestion, but maybe eszyman does?
Last edit: 21 Sep 2012 13:37 by btvpimill.
Please Log in or Create an account to join the conversation.
21 Sep 2012 13:42 #24513
by ArcEye
I'll write you a demo
regards
Replied by ArcEye on topic Re:Running a py file from a button
It can pass as many as you want, it is not making calls through G Code, it is reading the value of hal pins.will we be able to pass more than 2 parameters at a time
I'll write you a demo
regards
Please Log in or Create an account to join the conversation.
21 Sep 2012 14:11 - 21 Sep 2012 15:37 #24514
by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button
Hi
This is gedit back of an envelope stuff, but it compiles and runs under halrun OK, so should work and demonstrates what I meant.
Obviously needs the correct program name to call and needs to be linked to Xpos, Ypos etc in your hal file before anything will happen.
regards
Edit: added bzero(buff,256); to ensure trailing \0 char to terminate string
This is gedit back of an envelope stuff, but it compiles and runs under halrun OK, so should work and demonstrates what I meant.
Obviously needs the correct program name to call and needs to be linked to Xpos, Ypos etc in your hal file before anything will happen.
regards
component positions;
pin in float xposition "Receives current position from Xpos";
pin in float yposition "Receives current position from Ypos";
pin in float zposition "Receives current position from Zpos";
pin in float uposition "Receives current position from Upos";
pin in float vposition "Receives current position from Vpos";
pin in float wposition "Receives current position from Wpos";
pin in float aposition "Receives current position from Apos";
pin in float bposition "Receives current position from Bpos";
pin in float cposition "Receives current position from Cpos";
pin in bit trigger = 0 "connected to the button";
option singleton yes;
option userspace yes;
author "ArcEye";
license "GPL";
;;
#include <stdio.h> /* Standard input/output definitions */
#include <stdlib.h>
#include <stdint.h> /* Standard types */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <signal.h>
int done = 0;
void adios(int sig)
{
done = 1;
}
void user_mainloop(void)
{
char buff[256];
int triggered = 0;
signal(SIGINT, adios);
signal(SIGTERM, adios);
bzero(buff,256);
while(!done)
{
usleep(250000);
FOR_ALL_INSTS()
{
if(trigger && !triggered)
{
sprintf(buff, "mypyprogram X%08.03f Y%08.03f Z%08.03f U%08.03f V%08.03f W%08.03f A%08.03f B%08.03f C%08.03f",
xposition, yposition, zposition , uposition, vposition, wposition , aposition, bposition, cposition);
system(buff);
bzero(buff,256);
triggered = 1; // prevent further activations until button released
}
else if(!trigger && triggered)
{
triggered = 0;
}
}
}
exit(0);
}
Edit: added bzero(buff,256); to ensure trailing \0 char to terminate string
Last edit: 21 Sep 2012 15:37 by ArcEye.
Please Log in or Create an account to join the conversation.
21 Sep 2012 14:43 #24517
by btvpimill
Replied by btvpimill on topic Re:Running a py file from a button
Oh this looks really promising!!! So this is a comp file to be compilied using comp? Also the sprintf is where I need to change the file name to my file? (that seems pretty clear I think buit as a newbie - well you know)
Then just to figure out how to connect it to the button and should be running.
Sorry to need such hand holding on this, but there are a lot of new worlds revolving around it for us, and I need to get all the help I can when I can
Then just to figure out how to connect it to the button and should be running.
Sorry to need such hand holding on this, but there are a lot of new worlds revolving around it for us, and I need to get all the help I can when I can
Please Log in or Create an account to join the conversation.
21 Sep 2012 15:47 - 21 Sep 2012 15:56 #24520
by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button
Hi
Yes thats about it.
Name the code positions.comp
From the directory containing the file, run comp --install positions.comp from a terminal.
Will put the binary positions in /usr/bin
In your hal file
loadusr -W positions
net Xpos positions.xposition
etc
etc
net mybutton positions.trigger nameof.gladebutton.pin
and your python program obviously needs to parse argv to get the individual arguments.
I'll try to test it on a sim to ensure the logic works, but see no reason why it wouldn't
regards
Edit: Yeah just done that and diverted output to stdout and works fine.
Yes thats about it.
Name the code positions.comp
From the directory containing the file, run comp --install positions.comp from a terminal.
Will put the binary positions in /usr/bin
In your hal file
loadusr -W positions
net Xpos positions.xposition
etc
etc
net mybutton positions.trigger nameof.gladebutton.pin
and your python program obviously needs to parse argv to get the individual arguments.
I'll try to test it on a sim to ensure the logic works, but see no reason why it wouldn't
regards
Edit: Yeah just done that and diverted output to stdout and works fine.
Last edit: 21 Sep 2012 15:56 by ArcEye.
Please Log in or Create an account to join the conversation.
21 Sep 2012 15:55 #24521
by BigJohnT
Replied by BigJohnT on topic Re:Running a py file from a button
Don't forget to put sudo in front of comp...
John
John
Please Log in or Create an account to join the conversation.
21 Sep 2012 15:58 #24522
by ArcEye
Replied by ArcEye on topic Re:Running a py file from a button
Good point, JT exposes my nasty habits.
On my development machine I always run as root, can't be arsed with sudo.
On my development machine I always run as root, can't be arsed with sudo.
Please Log in or Create an account to join the conversation.
Moderators: HansU
Time to create page: 0.103 seconds