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 »

//Set mist/flood control
//1 = mist, 2 = flood, 0 = off
global SetMistFlood = function( relayNumber )
{
    //Relay # 1-4
    //print("Flood change");

OnOrOff = MyMotion.GetRelay(relayNumber);
  if (OnOrOff == 0)
  {
  MyMotion.SetRelay(relayNumber,1);
  print("M8 Flood Relay Turned ON");
  GlobalSet("FloodOnLED",1);
  }
  else
    {
    MyMotion.SetRelay(relayNumber,0);
    print("M9 Flood Relay Turned OFF");
    GlobalSet("FloodOnLED",0);
    }
};

If I call m8 the relay go's on, if I call m9 the relay stays on but it does do the print M9 flood relay turner off, if I call m8 a second time the relay turns off ok..

I will check to see if the led is set to flashing..

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

I believe the function gets a 0,1, or 2 in the parameters to indicate if this is an M7,m8 or M9. They way the commands for mist,flood work
is SetMistFlood(0) shoudl turn on whatever relay mist is contolling, a 1 to turn on the flood relay and a m9 to turn them both off.
Various machines use various logic for this , my script dopesnt actually use mist,flood but Id think its more..

//Set mist/flood control
//1 = mist, 2 = flood, 0 = off
global SetMistFl ood = function( desiredstate )
{
   
  MistRelay = 1;
  FloodRelay = 2;


  if (desiredstate == 0) //mist
{
    MyMotion. SetRelay(MistRelay,1);
    print("M7 Mist Relay Turned ON");
  GlobalSet("FloodOnLED",1);
}

if (desiredstate == 1) //flood
{
    MyMotion. SetRelay(FloodRelay,1);
    print("M8 Flood Relay Turned ON");
  GlobalSet("FloodOnLED",1);
}

if (desiredstate == 2) //flood,mist off
{
    MyMotion. SetRelay(MistRelay,0);
    MyMotion. SetRelay(FloodRelay,0);
    print("M9 Flood and Mist Relays Turned ON");
    GlobalSet("FloodOnLED",0);
    GlobalSet("MistOnLED",0);
}
 
};

Art


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

Re: reading Pokeys pins

Post by gburk »

Ok thanks will try it out

Here is a script to read pin19 doesn't work

  global MyMotion = Motion(); //Will not exist unless lib is loaded

global  MonitorPin19 = function()
{
  while(1)
  {
    print("Pin 19 Check");
    block( "MotionPiin19");  //pokeys57 Pin19
  //
  //  when you reach here, its because pin9 has changed..
    pinstate = MyMotion.GetPinDig (19); 
    if( pinstate == 1 )
    {
          print("Pin 19 Changed");
        //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();

prints the first print statement but never seems to read the pin when hit so never get the pin 19 changed message..

You were right the led in the homing was set to blink so fixed now...

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

Re: reading Pokeys pins

Post by gburk »

Art

Tried the relays as your post but doesn't work,
m8 I get nothing no relays on and no printed message

m7 I get the printed message but no relays on

M9 I get the printed message but there isn't any relays on so don't know it that will turn them off..

in the script I first sent the relays did go on and off...
Not sure what the major change would have been to effect that..

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

Re: reading Pokeys pins

Post by gburk »

I printer out the (desiredstate)
and I get 3 when m8 is run
and also when I run m9 it seen to run twice first its = to 2 then it must run a second time and it = to 0;;

make sense?

But the relays still don't turn on makes no sense to me using the same MyMotion.SetRelay(MistRelay,1); command as the script I sent you
and mine turns them on and off... as far as I can tell the only difference is in mine its using the m8 as the relay number and looks like to # 3
so its sending #3 as the relay #

in your script its using 1 and 2..

//Set mist/flood control
//1 = mist m7, 3 = flood m8, 2 and 0 = off m9
global SetMistFlood = function( desiredstate )
{
  print("M Number = ",desiredstate);
  MistRelay = 1;
  FloodRelay = 2;

  if (desiredstate == 1) //mist
{
    MyMotion.SetRelay(MistRelay,1);
    print("M7 Mist Relay Turned ON");
    GlobalSet("FloodOnLED",1);
}
  if (desiredstate == 3) //flood
{
    MyMotion.SetRelay(FloodRelay,1);
    print("M8 Flood Relay Turned ON");
    GlobalSet("FloodOnLED",1);
}
  if (desiredstate == 2) //flood,mist off
{
    MyMotion.SetRelay(MistRelay,0);
    MyMotion.SetRelay(FloodRelay,0);
    print("M9 Flood and Mist Relays Turned OFF");
    GlobalSet("FloodOnLED",0);
    //GlobalSet("MistOnLED",0);
}
};
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4591
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

I think we may be using differernt versions, I just refreshed the download to be sure so please reinstall auggie. If you changed
and screens but didnt rename them, do that first as it will overwrite changes you made to my screens.

  Hers is the script I just tested as working, But read on after..

global SetMistFlood = function( state )
{
    //1 = CW, 2 = CCW, 0 = off
   
   
    if( state == 0)
      {
          Pokeys1.SetRelay(1,0);
          Pokeys1.SetRelay(2,0);
      }
    if( state == 1)
      {
          Pokeys1.SetRelay( 1,1 );
      }
      if( state == 2)
      {
          Pokeys1.SetRelay( 2,1 );
      }

print( "flood/mist state: " + state );
   
};

  The relays in a pokeys arent in bit order, so auggie sees them as different numbers.

auggies Relay 1 is Pokeys OC2
            Relay 2 is Pokeys OC1
            Relay 3 is Pokeys hard relay 1
            Relay 4 is Pokeys hard relay 2


  Now this script assumes a relay for mist, one for flood and turns them both off on m9. This is conventional with
some cnc systems where one relay turns on the mist pump, and the second speeds it up. M9 then turns off both relays.
I jst tested this and it seems to work fine.

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

Re: reading Pokeys pins

Post by gburk »

That works now had a different version of auggie

do you think reading the pins may work now also, haven't tried that yet with this version..

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

Re: reading Pokeys pins

Post by gburk »

nope pin state never seems to change
when first run it prints pin 19 check
but never seems to change the pinstate

global  MonitorPin19 = function()
{
  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); 
    if( pinstate == 1 )
    {
          print("Pin 19 Changed");
        //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();

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

Re: reading Pokeys pins

Post by gburk »

sorry for all the messages
It almost seems like once auggie is booted it checks the pin 19 script then and not again...

this is what I have found I boot auggie pin 19 not shorted I get the message pin 19 change then pin 19 checked
if I boot auggie with pin 19 shorted I only get the message pin 19 checked

after the initial booting of auggie and received the message at boot
that's the end doesn't see a short or no short almost seems like its not running after auggies first boot

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

Re: reading Pokeys pins

Post by ArtF »

Hmm..

Does sound like a script that is stopping. The script you have shoudl be

global  MonitorPi n19 = function()
{
  while(1)
  {
    print("Pin 19 Check");
    block( "MotionPin 19");  //or you cold use IOPin9
  //
  //  when you reach here, its because pin9 has changed..
    pinstate = Pokeys1.G etPinDig(19); 
    print("Pin 19 Changed");
    //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.. .
  }

};

  Probably wont make a difference, but the == 1 is nbot needed to check for a change. So long as the block is signaled, you should
get a message. Ive been fighting some hardware issues, but Ill see if tomorrow I can find out why it may only run the once..

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

Re: reading Pokeys pins

Post by gburk »

I tested without the if pinstate == 1 and I think it may be needed

when I booted auggie I got both printed messages pin 19 changed first then pin 19 check
it didn't matter if the pin was shorted or open same order of messages...

So I think it may be need if I remember correct when I had the pinstate == 1 check it would switch the order of the printed message depending if the pin was shorted or open

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

Re: reading Pokeys pins

Post by ArtF »

Hi Gary:

  I added thius to my motionio library..

global  MonitorPin19 = function()
{
  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 to state " + pinstate);
   
  }
};

  And though I cant yet hook up a pin19 to my system, I did config the pokeys so that pin19 is a digitial output.
I then changed the code in auggie so that as it reads the incoming pin states, it toggles pin19 to 0 as long
as the ctrl key is held, this allowed me to test the script. Its responds properly and shows the message that
the pin has toggled and its state.

  Take note though, that youd miss fast presses, this is a slow way to read an input, fine for switches and knobs
but youd never be able to probe with it, probing is a hardwired fucntion due to its complexity and timing
requirments. Ive checked on adding it, but it looks complex enough that I dont think its feasable for the
small amount of people that use auggie or would use it for probing.

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

Re: reading Pokeys pins

Post by gburk »

I understand thanks for giving it a shot let me know if anything changed

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

Re: reading Pokeys pins

Post by gburk »

I see you decided to give probing a try in the new release great...

Have a request to be added if possible as you progress with probing.

I have requested pokeys developers to add some probing return codes for mach4's register's and they have done so not working correct yet but close..

Code that if probe is hit send a say 1 that can be read from a script or to the probe status register or -1 if no probe hit my reason for this is if probing for the center of a block
and you enter a distance that is to small, what I do is use a g31 not a g1 to move the probe down so if the probe returns a -1 I know probe wasn't hit
and then will do the move towards the part, but if I get a value of 1 I know the probe was hit going down and I am not off the block edge and I will send a message
stock size to small enter a lager size retract to start z Hight and back to we probe move x and y started.

I find doing this the probe doesn't crash into the part on the z down move..

make sense?

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

  That will be in the next release. After a G31 motion, you will be able to do something
like this..

Engine.GCode("G31Z-20");
h = GlobalGet("Probehit");
if( h )
{
  px = GlobalGet("ProbeX"); //etc for each axis you wish to use..
}

  The probe hit variable will tell you if the probe actually hit.
It should be possible to easily script a button to do something like
find the center of a hole. I haven't done much testing with scripts
doing repetitive calls as yet, so be cautious about the use of G31,
it should now be safe for zeroing. I already get back a 1 or -1 for
hit or miss I just haven't passed them back to the user yet.

Art

 
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests