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 »

Art

It was failing when I added the code line the hitting RUN...

So of course it was bugging me all night, so first thing this morning I decided to delete the script file..
I then entered one tool change function at a time, it has a little less code per function now, and all 16 tool functions are working,,
don't know what will happen as I add more code to each function but will find out later...

anyway it does seem to be working now, i'm thing maybe some sort of a glitch somewhere in the code not one I was able to see
spent a lot of time on till I decided to delete old file and start again

You didn't mention if you thought that I would be alright running with the dos's not running to the values I entered 2 seems to stop at 1.994 does it with all the axis's
but if I enter for it to return to 0.0 it doe's ok

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

Re: reading Pokeys pins

Post by gburk »

Art

It was working then I went to add or modify the code, if I check back in the lib I see no errors in the lib, but if I edit the lib and do a RUN I get compile erorrs

If I hit the tool1 button it runs OK except the machine and work cord seem messed up now if I set the dro's to 0 and them run the script, I added a print to show the start x y z axis positions i am getting them with GetAxisPos(1 2 and 3) I don't get a 0 value I will get what seems random values one time I will get 0.033 but I don't get 0 even though the DRO's are set to 0

My thought is because I am getting the compile errors problem is I don't see anything wrong, only seems to happen after adding or editing the script, but once it starts I have to redo the entire script..

Do you think I should break up the tool chance script into 3 or 4 separate scripts, there is 16 functions in the script. I haven't tried that yet maybe next thing to try.

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

Breaking it up will probably get it to run. I will check into the GetAxisPos
to see what the error may be. Ill see if I can figure out why the limitation as well,
though I may not be able to do much on that score..depends on its cause.

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

Re: reading Pokeys pins

Post by gburk »

Art

Update
I deleted the entire script and folder..
Started from scratch..
Now tool1 seems to be working getting the correct Positions values the only thing I see is I do a Gcode  or Rapid move on x y z then I do FreeTo
when it does the free move I get the message buffer underrun.. still seems to jog to the correct value though. and now returns to 0..
Still stops a little short of the distance entered seem to be the same every time

if I enter 2.0 axis go's to 1.9994 same for all axis's off just a tad..

I think a lot of the problems are from the scripts getting corrupted don't know why, have typed in some code into notepad++  and copy and pasted into auggie
just a thought..

I have had to redo the tool button scripts from scratch 3 or four times now confused as to why, I did split the tool change into two lib scripts one with tool 1-8 and the other with toll 9-16 will see how that go's..

The getaxispos is ok I think when the script gets corrupted it for some reason messes that up also..

Thanks gary
Last edited by gburk on Mon Jul 08, 2019 11:02 am, edited 1 time in total.
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Art

Have a spindle problem, not sure if is me or something internal,

If I do a M3 S3000 the spindle and relays turn on as expected.. and the speed is ok.

Now if I do a M3 S0 it seems to mess up it looks like auggie is calling all the M3 functions over again, turning on relays again, and I get the message spindle turned on it should be turned off I have gone though the code and when I get the spindle speed = 0 I call the spindleoff() function it seems to turn off the spindle and relays but then it looks like it starting the M3 again and turning on the relays

M5 Works fine everything turns off.. Only problem is M3 with a value of 0.

not sure if i'm being clear?.

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

  I think you'd have to add to the SpindleOn script a check of the speed, and if
its zero, just turn it off. I suspect auggie is getting fooled by the m3s0 and not
really knowing what to do. I dont think m3s0 is a typical command, though I can
see where it would have it uses.

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

Re: reading Pokeys pins

Post by gburk »

Art

Yes I already had a check for 0 if speed = 0 then SpindleOff() it just reacts weird to m3 s0 its fine if m3 is >0 it runs the relays and spindle as expected..

But if I enter a m3 s3000 all is good then if I enter another m3 with s0 is when it messes up.

I have nothing in the code for it to do anything other the relays and spindeoff with m3 s0.,,

Thats why I am thinking if you already sent an m3 s-speed, then another one m3 s0 the second m3 seems to rerun the m3 from the beginning  and not just change the speed... I attached the script..

Gary
Attachments
Spindle.zip
(1.56 KiB) Downloaded 173 times
gburk
Old Timer
Posts: 324
Joined: Sun Nov 25, 2018 3:57 pm

Re: reading Pokeys pins

Post by gburk »

Art

Did some more messing around with the m3 calls
best I can tell auggie calls, gobal SetSpindleSpeed = function( speed ) is called first, I put a print statement in that function also a sleep(10)
I also put a print statement in global SetSpindleState = function( state ) and a sleep(10).

it printed the print from gobal SetSpindleSpeed = function( speed ) but the sleep didn't seem to have any affect there.. it printed the print from SetSpindleState = function( state ) with no delay at all, but it did sleep after the print in SetSpindleState = function( state ).

So it looks like every time a m3 is called it runs both functions so endless i'm not getting this, and i'm probably not, is if a m3 s200 is call the fist m3 call its good
Now if I call it again m3 s0 or any value it auggie is calling both functions again, so  the  SetSpindleState = function( state ). is calling spindleOn again and it does set the speed to 0 but it is messing up the relays, that are set with the first  spindleOn call...

let me know if you get what I'm trying to say a little confusing

New update

made a few changes seems like it may work here is some of the code let me know if you think its Good or if I may have a problem with it somewhere down the road.
still have the long delays but seemed to do what I expected now..

global MySpindleOutput = 5;
global MySpindleAxis = 5;
//global SpindleMODE = 0;
global SpindleDevice = Motion();

//Sets the Spindle speed, triggered by S3000 fo example
global SetSpindleSpeed = function( speed )
{
    print("first speed");
    SpindleSpeed( speed );
};

//Set Spindle State.
global SetSpindleState = function( state )
{
    if (SpindleMODE == 0 || state == 0)
    {
    //1 = CW, 2 = CCW, 0 = off
    print( "Setting Spindle with " + state);
    sleep(10);
    switch( state )
    {
        case 1: {  if( lookup("SpindleOn")) { SpindleOn( ); }; }
        case 2: {  if( lookup("SpindleREV")) { SpindleOff( ); }; }
        case 0: {  if( lookup("SpindleOff")) { SpindleOff(); }; }
    };
  }
};

 
global SpindleOn = function()
{
    global SpindleMODE = 1;
    FreeSetSpeed( MySpindleAxis, GlobalGet("SpindleSpeed")); //turn on spindle
    print("Frequency Spindle was turned on");
    print("Set to Frequency " + GlobalGet("SpindleSpeed"));
}; 

//this is a relay spindle control,
//it will use only the OC output #1
//to control a relay to turn a simple
//on/off spindle, on or off.

global SpindleOff = function()
{
    //FreeSetSpeed( MySpindleAxis,0); //turn off spindle
    print("Spindle speed zeroed turned off");
    global SpindleMODE = 0;
   
}; 

//this is a relay spindle control,
//it has no speed control but this dummy
//routine will stop any error, and maybe
//test for zero speed.

global SpindleSpeed = function( speed )
{
    print("Entering SpindleSpeed function "+speed);
    sleep(10);
    if( speed != 0)
    {
      Maxspeed = GlobalGet("MAXspindleSpeed");    // Max spindle speed
      zerotohundred = (speed / Maxspeed) * 100;  // Get PWM5 value to set the spindle speed 0-100 for 0-10 volts
      SpindleDevice.SetPWM( MySpindleOutput, zerotohundred  );
      print("Spindle Speed set to " + speed );
    }
      else
      {
      SpindleDevice.SetPWM( MySpindleOutput, 0 );
      print("Spindle Speed set to " + speed );
      };
}; 

Is there a way to check to see if when sending an m3 if the S is sent also, from what I can tell if no S code sent its doesn't call the spindle speed function
but it still calls the spindleon with no speed setting so I can't check for 0 speed...


Gary

Last edited by gburk on Wed Jul 10, 2019 12:01 pm, edited 1 time in total.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4647
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

>>You didn't mention if you thought that I would be alright running with the dos's not running to the values I entered 2 seems to stop at 1.994 does it with all the axis's
but if I enter for it to return to 0.0 it doe's ok


  Yes, thats fine, its not unusualy to stop just short of a step. So you probably are
using 166.6 steps per inch or mm.. Mach3 does the same, it knows internally where you are
as a number of steps, not a position really.

Im still reading your scripts, but the command m3 literally means turn
on spindle while S means set speed. Typically you turn it on and then only use
S commands to change the running speed. So M3S0 wouldnt be quite the same as
M5 as a stop. Speed is set first when command are on one line, this is just a priority
thing and the spindle speed has higher priority than spindle on.

  Now when you call M3, the spindle is set to on, then your script is called.
If the M3 is seen again it does the same. Now I could change this internally
so that if M3 is called when the spindle is already running, the M3 could
be ignored. The S command will still work, you dont need an M3 before
every S command, just for the first turn on.

  That may be the best way around it.

Art


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

Re: reading Pokeys pins

Post by gburk »

Art

Thanks I think I may have it figured out, not being a programmer I sometimes get lost in the logic maybe most of the time.
Anyway with a few global var, placed in the right spots I do have it running fine...

Now that I when from testing m6 to m3 I see that the g code I sent you has no S commands only m3 so spindle turning on but not moving..

So I had to edit cambams post again re ran it an now I have m3 S3000 in the g code,

I ran the g code it was looking good all relays turning on and off spindle flood exc.. tool change dialog also..

But seems like cambam left out the m8 after doing the two dill pecks cycles. so when it started to run the pocket holes no flood strange not sure if I can fix that in the post..

anyway seems like I got the m3 m4 m5 scripts going ok.. tool change seems ok also, so maybe I can clean them up a little now...

I'm sure I will have more questions, we came a long way..

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

Re: reading Pokeys pins

Post by gburk »

Art

Just an update I was able to get the m8 working right with cambam now...

But one problem, still having the m6 called twice on first run...

if I run stop and run the g code again its fine, seems only when the code is first loaded then run to runs the first m6 t twice..

Do you think the buffer underrun I get when running the freeaxis's will be a problem?..

told you I'd have more questions..

do you want a new copy of the g code its not much different other than m8 is where it should be and m3 now has the S in the g code..

Also I don't think I ever mentioned this but 98% of the time when I shut auggie down it close's them reboots it's self..

Gary
Last edited by gburk on Thu Jul 11, 2019 11:11 am, edited 1 time in total.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4647
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: reading Pokeys pins

Post by ArtF »

Gary:

>>if I run stop and run the g code again its fine, seems only when the code is first loaded then run to runs the first m6 t twice..

  Ill continue to try to find that one, I have seen it occur, just not repeatable for me for
some reason.

>>Do you think the buffer underrun I get when running the freeaxis's will be a problem?..

  Hard to say. Buffer Underrun means for some reason the system ran out of data
from a planner. OR it may feel its out of position, so let me know if you see
ill effects, as your doing mill work your stressing the program more than most
of us with lasers.

>>Also I don't think I ever mentioned this but 98% of the time when I shut auggie down it close's them reboots it's self..

  Sign of an internal memory fault as it shuts down, Some windows will restart the
program in such an event, others wont. I suspect the scripting has some dangling
memory at times, and as it trys to delete it at shutdown it creates a memory
fault. Doesn't matter at that point really, but windows see's it as an error and
restarts if the group policy tells it to.

Art




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

Re: reading Pokeys pins

Post by gburk »

Art

I don't think there is much going on when I run freeaxis all other motion had stopped.., so far I haven't seen any problem with the buffer underrun message..

I have a pokeys board question don't know if you will have an answer...

I ended up putting 2 more relays in so if I wanted to switch from pokeys control to manual,  so the switch and relays turn on the spindle and forward relays but of course there still connected to the plugs in the pokeys relays.. so if there is no power going to the pokeys and I turn on the manual relays it seems to power up the pokeys I assume it is feeding back somehow though the pokeys relays and powering the pokeys board do you think it should back feed power to the pokeys and the pokeys power up like normal..  I know weird question if its there or not I will make it happen..

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

Re: reading Pokeys pins

Post by gburk »

Art

Have a question about reading and writing to files,
How can that be handled with a script, I tried a few ways I have done it in c++ and c but not having any luck getting it to work..

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

Re: reading Pokeys pins

Post by ArtF »

Gary:

Script commands do exist for several file interface commands
in script. What kind of file are we talking... text, binary, data, gcode?


Art
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests