reading Pokeys pins

C Scripting questions and answers
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Yes both are true.

I will change the setting in the planner and see if that has any effect..

Have a question I thought you were not going to add the probing. What changed your mind? I'm not complaining I'm enjoying testing it, maybe more fun for me than you

but thanks gary
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Art

Its a good thing I went back to the planer everything was changed no probe set... so its a different story now... I retested it in the script and worked g31 and stopped with probe hit...

it does also work in the lib script but not correct I have to do edit on the lib script and while its loaded in the scripter I run the lib script it doesn't do anything but if I hit my probe button that is calling the same script it will do the g31 so it does seem to be working now my fault I didn't realize the planner got reset somehow..

so guess just have to figure why I can run the script just from a button press, and have to run it in the scripter first...

I guess for some reason when screen editing or adding panels may reset the planner only thing I can think of after you fixed it not to reset to metric and that was working I didn't think to check it again my bad...

gary 
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Art

Tested some more  I don't think its reading the probe hit correct  if( !GlobalGet("ProbeHit")) it always thinks this is true and the next line prints out no probe hit
so the script never makes it past here, tried both true and false on the probe invert..

I am seeing a message now I assume you are displaying saying probe hit or something like that don't rem for sure but its not in the script.

gary
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

here is a copy of what I have in the lib

global mytable = table( "X", "Y", "Z","A" );

global ZeroToPlate = function(axis,dir,feedrate)
{
&nbsp; if ( axis < 1 || axis > 3 )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("Error: Axis can only be 1 X, 2 Y, 3 Z");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; }
&nbsp; print(mytable[axis]);
&nbsp; axis = mytable[axis-1]; //X = 1 Y = 2 Z = 3 A = 4
&nbsp; print("a = ",axis);
&nbsp; print("d = ",dir);
&nbsp; print("f = ",feedrate);
&nbsp; GlobalSet("ProbeInvert",0); //set probe to normal state
&nbsp; string = "G31"+axis+"-25" + "F" + 100;
&nbsp; print(string);
&nbsp; Engine.GCode(string); //probe 25mm down in Z
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; if( !GlobalGet("ProbeHit"))
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("No hit on probe ..Try again closer to plate.");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; } //we didnt hit the probe during the move
&nbsp; GlobalSet("ProbeInvert",1); //invert probe switch
&nbsp; Engine.GCode("G31Z0F10"); //probe upwards slowly till switch releases
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; xcor = GetAxisPos( 1 );
&nbsp; print("xcor = ",xcor);
&nbsp; if( GlobalGet("ProbeHit"))
&nbsp; {
&nbsp; &nbsp; &nbsp; print("Zero Axis, probe complete.");
&nbsp; &nbsp; &nbsp; GlobalSet("Zero3",1); //this will zero axis #3-Z (the numbering starts at 1 for X in zeroing
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //function even though some other functions start with 0 for X
&nbsp; }
&nbsp; &nbsp; else { print(" Error in touchoff" );
};
};

this is the button

global Probepanel_BUT_2 = function( current )
{
print("Probing");
ZeroToPlate(1,2,3);
return;
};

still have to run the script in the scripter then hit the button for the g31 to work

gary
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4648
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

&nbsp; The setting may have changed because of my fixes. Wrong values were being set and
the fix fixed it, but couldn't fix any corrupted settings.

Ill post your script below and comment on it..

global mytable = table( "X", "Y", "Z","A" );

global ZeroToPlate = function(axis,dir,feedrate)
{
&nbsp; if ( axis < 1 || axis > 3 )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("Error: Axis can only be 1 X, 2 Y, 3 Z");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; }
&nbsp; print(mytable[axis]);
&nbsp; axis = mytable[axis-1]; //X = 1 Y = 2 Z = 3 A = 4

>>Care advised here, axis is originally typed as an integer and
>> the above line changes it to a string character. May work, but
>>not safest thing to do.Try not to override a variable type once declared.

&nbsp; print("a = ",axis);
&nbsp; print("d = ",dir);
&nbsp; print("f = ",feedrate);
&nbsp; GlobalSet("ProbeInvert",0); //set probe to normal state
&nbsp; string = "G31"+axis+"-25" + "F" + 100;
&nbsp; print(string);
&nbsp; Engine.GCode(string); //probe 25mm down in Z
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; if( !GlobalGet("ProbeHit"))
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("No hit on probe ..Try again closer to plate.");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; } //we didnt hit the probe during the move
&nbsp; GlobalSet("ProbeInvert",1); //invert probe switch
&nbsp; Engine.GCode("G31Z0F10"); //probe upwards slowly till switch releases
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; xcor = GetAxisPos( 1 );
&nbsp; print("xcor = ",xcor);
&nbsp; if( GlobalGet("ProbeHit"))
&nbsp; {
&nbsp; &nbsp; &nbsp; print("Zero Axis, probe complete.");
&nbsp; &nbsp; &nbsp; GlobalSet("Zero3",1); //this will zero axis #3-Z (the numbering starts at 1 for X in zeroing
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //function even though some other functions start with 0 for X
&nbsp; }
&nbsp; &nbsp; else { print(" Error in touchoff" );
};
};

this is the button

global Probepanel_BUT_2 = function( current )
{
print("Probing");
ZeroToPlate(1,2,3);
return;
};

>>All looks good really.&nbsp; Is the ProbePanel_BUT_2 the variable name of that button
or the auto created name of the button?
Are these scripts in the Gcode library or library stored in the screen button LIB section
or is it written in the large script editor reached through the config ribbon panel?

Art.

gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

I was pretty sure axis had to be a char so I setup the table so I could use a axis letter related to the motor number, and I could not figure a way to pass a char from the button to the function I tried passing "X" but the function was receiving it as a ascii number and not the char..

I'm not sure if the&nbsp; ProbeHit is getting the right value
I tried this script in in the scripter an changed&nbsp; ProbeInvert from 0 to 1 but X = 0 no matter what, don't even know if it is workable like this,&nbsp; but worth a try did with probe open and closed...

&nbsp; GlobalSet("ProbeInvert",0);
&nbsp; x = GlobalGet("ProbeHit");
&nbsp; print("probe hit = ",x);

the probepanel_BUT is the auto created name

I didn't want to mess with you scripts in the gcode lib so I made my own lib tree and have them there.

the script itself is stored in with my library scripts&nbsp; in LIB


never used the scripter from ribbon panel but will check it out..

the only thing stored in the button script is the call to probe function

gary
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4648
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

&nbsp; >> I was pretty sure axis had to be a char so I setup the table so I could use a axis letter related to the motor number, and I could not figure a way to pass a char from the button to the function I tried passing "X" but the function was receiving it as a ascii number and not the char..

&nbsp; There is a .ToChar() function, but it doesnt matter, the way you have it seems to work fine in that regard.

>> GlobalSet("ProbeInvert",0);
&nbsp; x = GlobalGet("ProbeHit");
&nbsp; print("probe hit = ",x);


&nbsp; Probehit doesnt work that way. It isnt the state of the probe, just a boolean
of if the probe was hit on the last g31 move. When a g31 is commanded the
probehit is set to 0. If the probe is hit during a G31 move, it gets set to true
and stays that way until the next G31 is commanded. SO probehit can only
be queried after a probe and its a message to tell you if the probe actually hit,
this is safer than just reading the probe as it is possible in some circumstances
for a probe to hit, and then release during deceleration. This allows you to KNOW
that it hit at some point during that move.

&nbsp; GlobalGet("MotionPin19") should tell you the current state.

x = 0;
while(x < 60)
{
&nbsp; &nbsp; print( GlobalGet("MotionPin19"));
&nbsp; &nbsp; sleep(500);
&nbsp; &nbsp; x = x + 1;&nbsp; // x++ is not allowed in script--note
}
&nbsp; try something like above in your script window and see if it prints 1 or 0
when the probe is pressed or released. If the rest condition is 0 and the hit
condition is 1, then probeinvert is set right for "stop on hit", if hit condition
is 0, then probeinvert is set for "stop on release of probe".

Note:&nbsp; The print mechanism will not print the same message more than once.
If it sees the print is for a line that matches the last print statement, it will ignore
it as a safety to ensure a scripted print loop is not occuring.. Early on it was easy
to lock yourself up with looping on a print statement, this should no longer occur
but has this side effect. Its worth noting. :)

Art



gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

I already have a script running that checks the state of motionpin19 I am using it to trigger an led on off when pin19 is triggered. works fine

I was just trying to see if&nbsp; &nbsp; x = GlobalGet("ProbeHit"); was working it doesn't seen to change state I always get no probe hit in the probe script so if the probe was hit the script still ends there and will not finish the rest of script or should I not use "ProbeHit" and use a check on motionpin19 in the scripts

have you figured out why I need to run the script in the scripter before I can get it to run with the button press..
it doesn't seem to do anything run from the scripter I just get message mdi run mdi end then I can do the button press and all the print statements show and the motor moves..

thanks gary
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

I chanced it to check pin19
it seems to work if I hit the probe it continues to the line probe hit if I let run to end of travel distance prints no probe hit.
it prints the line probe hit but doesn't do anything after it seems to ignore the next engine.gcode with or without the pause line..&nbsp;

global ZeroToPlate = function(axis,dir,feedrate)
{
&nbsp; if ( axis < 1 || axis > 3 )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("Error: Axis can only be 1 X, 2 Y, 3 Z");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; }
&nbsp; print("a = ",axis);
&nbsp; print(mytable[axis]);
&nbsp; axis = mytable[axis-1]; //X = 0 Y = 1 Z = 2 A = 3
&nbsp; print("a = ",axis);
&nbsp; print("d = ",dir);
&nbsp; print("f = ",feedrate);
&nbsp; GlobalSet("ProbeInvert",0); //set probe to normal state
&nbsp; string = "G31"+axis+"-25" + "F" + 100;
&nbsp; print(string);
&nbsp; Engine.GCode(string); //probe 25mm down in Z
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; pinstate = Pokeys1.GetPinDig(19);
&nbsp; if( pinstate )
&nbsp; //if( !GlobalGet("ProbeHit"))
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("No hit on probe ..Try again closer to plate.");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; } //we didnt hit the probe during the move
&nbsp; &nbsp; print("hit on probe");
&nbsp; &nbsp; sleep(500);
&nbsp; GlobalSet("ProbeInvert",1); //invert probe switch
&nbsp; Engine.GCode("G0X3F100"); //probe upwards slowly till switch releases
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; xcor = GetAxisPos( 1 );
&nbsp; print("xcor = ",xcor);
&nbsp; if( GlobalGet("ProbeHit"))
&nbsp; {
&nbsp; &nbsp; &nbsp; print("Zero Axis, probe complete.");
&nbsp; &nbsp; &nbsp; GlobalSet("Zero1",1); //this will zero axis #3-Z (the numbering starts at 1 for X in zeroing
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //function even though some other functions start with 0 for X
&nbsp; }
&nbsp; &nbsp; else { print(" Error in touchoff" );
};
};

gary
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4648
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

>> sleep(500); this is sleep for 500 seconds. Its probable that you didnt wait the 8 minutes to
see if the rest of the script runs..

Im not sure why you have to call it in the scripter before the button will work. I typically
use a variable name in a button. Id try setting the button to a variable name and
rename the script Probepanel_BUT_2 to that variable name. Its possible theres some bug
in the label to script functionality, but I know the variable to script works as most of mine
tend to use it.

Art
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Art

I may be lost here a bit..

If I am I panel edit and set the button id 2 and var name to Zprobe

now I go to script edit the button name is removed there's no button name.. without the var name the button is main_panel.BUT2 in the panel script
I save the panel and run auggie again

hit the probe button and the script is gone, so I go to script edit in main auggie there is no button name there either.
so here is where I'm lost if the button name is gone how would I call the buttons with its var name&nbsp; when button is pressed if there is no button name in the script editor for that panel button now .

don't know if this makes sense, bottom line is if var name set then no button name anymore.
and when I had a button name I couldn't see how to change the button name. endless I can go into the script folder and edit it manual ? as long as that wouldn't mess something else up

thanks gary
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

After messing around some more Not sure if this is how you wanted me to set it up but

I created a global function with the buttons var name and that works when I press the button now.
and I added the call to&nbsp; ZeroToPlate(1,3,100); from the global button press

but still won't run endless I run it in the scripter first...
and also still won't run the second engine.gcode() or any thing after that line...

gary
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

art yet another message hope you like reading&nbsp; :D

I got the script to run some of the problem was I copy this&nbsp; xcor = GetAxisPos( 1 ); from the doc file and just realized it needed the enging&nbsp; xcor = Engine.GetAxisPos( 1 );

now the script will run to the end...

still some strange behaver I still need to run the script first though the script RUN to work,

if I press button and let run to the full distance entered for the axis I would have to do the script RUN first before every button press and I find if I have X-25&nbsp; it stops at different distances usably at -28 after the first run.. I find the same when reversing if 1 have X3 It will run to X3 the first time but run again seem to stop at X0 this is all without hitting the probe....

if I run the script though script RUN then do a button press X-25 Axis starts running then I hit probe it stops ok pauses and then starts to reverse I hit the probe it stops and ZEROS the X axis.
the strange part is as long as I hit the probe while axis is running, I only have to run the script thought the script RUN Once as long as I keep hitting the probe while running I can just use the button.

here is the latest script&nbsp;

global mytable = table( "X", "Y", "Z","A" );
global ZeroToPlate = function(axis,dir,feedrate)
{
&nbsp; if ( axis < 1 || axis > 3 )
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("Error: Axis can only be 1 X, 2 Y, 3 Z");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; }
&nbsp; print("a = ",axis);
&nbsp; print(mytable[axis]);
&nbsp; axis = mytable[axis-1]; //X = 0 Y = 1 Z = 2 A = 3
&nbsp; print("a = ",axis);
&nbsp; print("d = ",dir);
&nbsp; print("f = ",feedrate);
&nbsp; GlobalSet("ProbeInvert",0); //set probe to normal state
&nbsp; string = "G31"+axis+"-25" + "F" + 100;
&nbsp; print(string);
&nbsp; Engine.GCode(string); //probe 25mm down in Z
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; pinstate = Pokeys1.GetPinDig(19);
&nbsp; if( pinstate )
&nbsp; //if( !GlobalGet("ProbeHit"))
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; print("No hit on probe ..Try again closer to plate.");
&nbsp; &nbsp; &nbsp; return;
&nbsp; &nbsp; } //we didnt hit the probe during the move
&nbsp; &nbsp; print("hit on probe");
&nbsp; &nbsp; sleep(0.5);
&nbsp; GlobalSet("ProbeInvert",1); //invert probe switch
&nbsp; string = "G31"+axis+"3" + "F" + 100;
&nbsp; print(string);
&nbsp; Engine.GCode(string); //probe upwards slowly till switch releases
&nbsp; block("MotionStill"); //wait for all motion to stop, no system delay for this.
&nbsp; xcor = Engine.GetAxisPos( 1 );
&nbsp; print("xcor = ",xcor);
&nbsp; pinstate = Pokeys1.GetPinDig(19);
&nbsp; if( pinstate )
&nbsp; //if( GlobalGet("ProbeHit"))
&nbsp; {
&nbsp; &nbsp; &nbsp; print("Zero Axis, probe complete.");
&nbsp; &nbsp; &nbsp; GlobalSet("Zero1",1); //this will zero axis #3-Z (the numbering starts at 1 for X in zeroing
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //function even though some other functions start with 0 for X
&nbsp; }
&nbsp; &nbsp; else { print(" Error in touchoff" );
&nbsp; };
};

thanks gary
Last edited by gburk on Tue Mar 05, 2019 10:38 am, edited 1 time in total.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4648
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

&nbsp; I think I see the problem. If the probe isnt hit the engine is left in Pokeys control
with the engine in a probe state. Thats weirding things up internally. It probably
explains the final problem you have any why if you hit the probe every call all
is fine. I will fix this tomorrow by ending the probe state in the engine when MotionStill
is signaled if probe is in effect. That should fix the issue. I appreciate your work in defining
it. Ill notify on this thread when I post the fix.

Art
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4648
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

&nbsp; Auggie 3.5 is online. It fixes a problem where if the probe didnt hit, the engine
was left in a probing condition until the start of the next move. Now, just prior
to MotionStill being signaled to the scripts, the probing , if in effect, is terminated
properly so its ready for any command.

&nbsp; Let me know if this fixes your problem..

Thx
Art
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest