reading Pokeys pins

C Scripting questions and answers
Post Reply
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4589
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

  I hooked it all up here, the table seems to probe fine in the X and Y axis, I cant test
the Z on mine for technical reasons at the moment, but as far as I can see it
all seems to be running at speed during the probe and after...

Let me know what you find, it may be some setting or another ..

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

Re: reading Pokeys pins

Post by gburk »

Sorry Art;

Probably left to many messages and am confusing you?

1 ? I am finding that running a script to check the probing pin19 must take to much time from the gui and that's why the main screen dro only updates after the axis has move around 0.254?
without the script the screen dro updates fine?

2 ? I am probing now on the X Axis Setting?s for xaxis are ENB = TRUE, REV = FALSE, STEPS PER   
= 2500.000000 , MAX ACC = 19.999001, MAX VEL = 1000.00000, SLIMITS = FALSE,  HOMING REV = TRUE,  HSPEED = 20,  HOME RET SP = 50,  MAP MOTOR 1.

3 - Maybe taking a break and rebooting the computer was what I needed, motor seems to be running fine now with both g0 and g31 the g31 runs at a slower speed but I assume you have the feed rete set lower for probing I did try F100 and ran a little faster so looks good...

have you figured a way yet to read a register or variable to get feed back to see if the probe was hit or went to the enter axis travel distance?.
looks to me like in a script it may be to slow for probing, but seeing your programing over the years you may have a way...

thanks gary

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

Re: reading Pokeys pins

Post by gburk »

Art

maybe you can use the scripting I did a little more research and tried using the yield() after the print line in my script and now the dro's display correctly
and when I hit the probe I get the printed message pin19 hit I may get the message printed twice but the dro is running steady now..

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

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

  Thx, good to know. A script shouldn't take any time at all if it uses a line like

Block("MotionPin19");

  that stops the script altogether until Auggie sees pin19 toggle, at which point the
script will continue onwards..

  The script command

a = GlobalGet("ProbeHit");

  will make "a" true if the probe hit on the last G31.

x = GobalGet("ProbePos0") will return the X position of the hit.  1,2,3 will give you y,z,a axis positions
where the probe hit and before decelerating.

  If your just doing a zeroing to a touch plate you may want a script something like this one
designed to be called from a zeroed Z axis position somewhere less than 1" above the touchplate.
User is expected to zero axis when it stops. Because it rises off plate at such a slow feedrate
you will stop withing a step or so of probe hit. If you make the feedrate of rise F1, youd probably
stop exactly on the zero point.

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

}

    Thats off top of head, untested so you may find lots of syntax errors there.. :)
Art




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

Re: reading Pokeys pins

Post by ArtF »

BTW:

  Do not use G43 at this time, I just fixed a problem with zeroing
when toollengthoffset is in effect and it affects the zeroing..Next update
should fix that issue.

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

Re: reading Pokeys pins

Post by gburk »

Art

For some reason I'm having a problem creating panels, I tried to make a panel with 3 buttons and 3 labels
when in panel mode and scripting, then when I go to edit a script it shows no buttons only the labels all as main label 0
if I put a script into the label its there every time I load the panel thought panel create mode but no buttons and 1 did give the buttons a number 1 to 3

if I go back to the main screen I have the panel placed on the screen ok now I script edit from the main screen still shows all labels under that panel
but  it didn't carrier over the scripts  from the panel edit screen create mode.. and of course the buttons don't work, I guess because its only picking up the labels no buttons

I have created panels with  buttons from older versions of auggie with no problems
let me know if I'm doing something wrong ? or something has changed

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

Re: reading Pokeys pins

Post by gburk »

here is the script that works

global  FloodOffOn = 0;
global  MonitorPin19 = function()
{
  //Pokeys1.SetPinDig( 19 , 0 ); // turn off pin 19, ( assumed to be digital output)

  while(1)
  {
    print("Pin 19 Check");
    block( "MotionPin19");  //or you cold use IOPin9

  //
  //  when you reach here, its because pin9 has changed..
    pinstate = Pokeys1.GetPinDig(19); 
    print("Pin 19 Changed");
    yield();
        //do what you need to do. Take not that if you change pin9, youll get called again..
        //so make sure you dont get into a loop where your change makes this gets called which then changes it..etc.. .
  }
};
MonitorPin19();

should I replace yield with a block?

also trying to wrap my head around global vars
I set global  FloodOffOn = 0;

if I use FloodOffOn in button script and change its value to 3, when I call the button script a second time the value is back to 0 
so I assume setting it as a global then its not changeable ? 

also is it possible to read the encoder pins I think pin13 as a one rev index rpm?

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

Re: reading Pokeys pins

Post by gburk »

Art

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

called from button

ZeroToPlate (1,2,3);


its strange I was in simulator mode pressed the button
and the z moved to -25

can't get it to work a second time in simulator or with pokeys
it does print 1 2 3 but no axis movement
so I know its calling the function just strange it worked once

do you suggest a better way to call the function?

thanks gary


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

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

  Im sim mode the G31 will not function. ITs because half of the probe work is done in
the Pokeys itself. The simulator probably didnt understand the PROBE type trajectory
and simply passed it on as a feed move. Trouble is, the pokeys needs to shut off the
probeing mode. Sim mode wont do G31's as a result..

>should I replace yield with a block?

  In your example, you can remove the yield(). the next line encountered is
to print "ProbeCheck" and then it blocks anyway. So replacing yield with block
would break it as it would need two probehits..one for each block.

A yield simply passes control back to the program so it can process other
threads and then immediately returns. So yields are good practise if doing
a long calculation as you can pass control back every once in a while to
allow auggie to work, but in the case of a block, the program stops entirely
until the event occurs.

>>if I use FloodOffOn in button script and change its value to 3, when I call the button script a second time the value is back to 0 
so I assume setting it as a global then its not changeabl e ? 

  Ill have to check this.  Ill get back to you.

I think you can get encoder count... but not the index pin itself, typically they
pass so fast youd never see it. Ill check what the call is for the count.

Art


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

Re: reading Pokeys pins

Post by ArtF »

Gary:

>>For some reason I'm having a problem creating panels, I tried to make a panel with 3 buttons and 3 labels when in panel mode and scripting, then when I go to edit a script it shows no buttons only the labels all as main label 0 if I put a script into the label its there every time I load the panel thought panel create mode but no buttons and 1 did give the buttons a number 1 to 3

  This one gets confusing. Originally I was adding scripts to the panels and sub screens that were hard
coded by the panel designed into the panel itself. That script could then be overridden if one
wished by editing it in the screen containing the panel. This virtual override was thought to be
safer but I found it too confusing. So when you design a panel, just name the various interfaces
by a variable name and dont do any scripting. When the panel loads the label names and such
will be decorated to stop duplications, but the variable names will be fine.

  So, if for example you have a DRO on a Zeroing panel, just give it a variable name of
m_MyZeroXDRO for example. Then once the panel is saved and is part of a screen, add your
scripts to any library file (or make a new library file for that panel.). Adding a
function like

global function m_MyZeroXDRO( value )
{
}

  Should then make that function get called when the dro is typed into. You can
send to it as well with GlobalSet("m_MyZeroXDRO",value) or get from it with
GlobalGet..

  Its the best way to attach scripts to objects, I highly advise not hard scripting in the
panel designer, its very messy unless your me and know all the strange interaction
with the virtual override system.

  On your question about  FloodOn, did you mean you created a global variable named
FloodOn or were you trying to access an internal var of that name. (There is no var
of that name internally.). There is a script to set flood mist in the Gcode library
which you can call from a script of your own as well. I didnt add any way I dont
think to check the current state. The GCode library hardcodes what relays to use
with flood and mist. So I guess you could check the relay state in a script to
see if its on or off.

Art


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

Re: reading Pokeys pins

Post by gburk »

Art

yes I created a global var FloodOnOff
I have a button to turn on flood relay  and a led I was trying to set global FloodOnOff = 0
then if I hit the flood button FloodOnOff  would = 0 and relay would turn on and change FloodOnOff = 1 and when button again relay would shutoff and  FloodOnOff set back to 0 but when I set FloodOnOff to 1 it always reverts back to 0 so of course the second button press won't shut off the relay
I worked around this by using getrelay instead.

is there a way for engine.gcode('G31',axis,'-25F100') to except a value like axis ='Z'
so I will call the probe function like probing("Z',10,100)
then probing function start like probing(axis,distance,feedrate)}{
also doesn't seem to be a way to set the var axis to a char on the receiving function it  receives 'Z' as an int..

as far as the probing routine it will not run as long as pokeys is connect
the g31 may not work in  simulation but I can get the dro running to -25 in simulator

but I have to have the script loaded in local edit then run the script hit stop once or twice
then hit my button script and then the z dro runs to -25

but just can't get to work with pokeys connected

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

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

>>yes I created a global var FloodOnOff ....

    As I recall there's some strange syntax possible here, Id have to see the code for it.
You wouldn't use GlobalSet or GlobalGet for actual script globals, only for Auggie internals.
For a script global you'd declare it in a global scope.. like before the function declaration..

ex:
(In a loading library like Gcode or System)

global FloodOn = 0; //declare script global in global scope outside of function.

global function FloodOnOff( state )
{
    if(...)
      FloodOn = 1; //should be able to simply use the global name here.. no GlobalSet or get required.
}

>>is there a way for engine.gcode('G31',axis,'-25F100') to except a value like axis ='Z'
>> so I will call the probe function like probing("Z",10,100)

  All variables are automatic. so for example..

global function Probing( axis, dist, feedrate )
{
  string = "G31" + axis + " " + dist + "F" + feedrate;
  print( string ); //as a test
  Engine.GCode( string );
}

to use:
  Probing( "Z" , -10, 100 );

  Again, top of head so excuse me if Im off a bit on syntax.


>>as far as the probing routine it will not run as long as pokeys is connect
>>the g31 may not work in  simulation but I can get the dro running to -25 in simulator

  I verified that simulation will not run G31, effects are unknown  so it may explain lockup
or strange effects.

>>but I have to have the script loaded in local edit then run the script hit stop once or twice
>>then hit my button script and then the z dro runs to -25
>>but just can't get to work with pokeys connected

  Make sure your script and globals are in a library checked to be loaded. Libraries are
reinitialized each reset of system to ensure all globals are current and all scripts are
registered. If it doesnt recognize a script, lets find why. If the script is recognized,
but the probe just doesnt move, it may be the probe is already being seen as hit.
The ProbeInvert and GlobalSet("ProbeInvert", n ); will have an effect. Make sure
that a G31 entered in single line MDI works, if no motion occures, change the setting
of ProbeInvert in the settings. If the probe moves, then the probeinvert is set correectly.

  Ignore the results of sim test, it doesnt show anything usefull.

  Just to be clear, the script commands GlobalSet and GlobalGet are used only
with Auggie internals, theres about a hundred of them that may be used. All
others are simply used as script names for direct reference.

Art

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

Re: reading Pokeys pins

Post by gburk »

Art

I wasn't using globelset  or get for the flood, but don't need it anyway using getrelay and that works fine...

I tested the probe script again with pokeys on engine.gcode doesn't seen to work with g31 I get no motor movement
I changed the engine.gcode form g31 to g0 and motors ran fine so I'll leave this one up to figure out I'm kind of lost now..

but the g31 and probe hit do work from single line mdi.

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

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

>>I wasn't using globelset  or get for the flood, but don't need it anyway using getrelay and that works fine...

  Ahh, ok. Sorry if I explain too much at times or much such assumptions, Ive been doing support
now for decades and Ive found too much is better than too little.

>>I changed the engine.gc ode form g31 to g0 and motors ran fine so I'll leave this one up to figure out I'm kind of lost now..but the g31 and probe hit do work from single line mdi.

  Could be me, Ive been testing from mainly the single line MDI myself. Though I did also
test the Engine.GCode.. I will check to see why the script may have broken..

Art

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

Just tried this in the script window. Can you try it and tell me what it does?

Engine.GCode("G31Z-25F500");
axis = "Z";
string = "G31"+axis+"0" + "F" + 100;
print(string);
Engine.GCode(string);

  On the toolpath screen you should see the line printed
as "G31Z0F100" as well..

Art
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests