reading Pokeys pins

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

Re: reading Pokeys pins

Post by gburk »

Art

Tried it in the script window G31 Doesn't move the dro's or motor the same results as running though the lib script
I changed to G0 and the motor ramped up to -25 and then ramped to 0 and I did get the printout on the display screen
with both g0 and g31..

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

Re: reading Pokeys pins

Post by ArtF »

Thats what Id expect if the ProbeInvert was set wrong. But then it wouldn't
work in GCode single line mdi if that were true.

  The script I listed was one I tested on my machine.. so it must be a setting somewhere..
Ill give it some thought and look in the code to see why it may not go.

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

Re: reading Pokeys pins

Post by gburk »

I have the probe active high low problem with mach3 and 4, mach4 needs it set high mach3 needs it low not sure what auggie has it set at but when its triggered my script to read pin19 is triggered..

I removed the print statements for the pin19 script and replaced it with an led on screen seems to work ok...

gary

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

  Auggie assumes Active High, but if in the config/planner you set
ProbeInvert, Auggie will then assume active low.
  The trigger of a script will happen no matter if it toggles from
a 1 to a 0, or a 0 to a 1. Either will trigger a script.

  So if a g31 is sensed, and the probe is sensed as already hit,
no motion will occur. It will just trip right at start.

  So I need to confirm..

A GCode single line MDI of G31 works?
A script call to G31 doesn't?

  Are both true?

Thx
Art
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: 4593
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: 4593
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: 4593
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
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests