reading Pokeys pins

C Scripting questions and answers
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 »

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: 4648
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: 4648
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: 4648
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: 4648
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: 4648
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
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: 4648
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: 4648
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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest