Hello Guest it is December 11, 2019, 06:43:30 AM

Author Topic: Spindle warm  (Read 308 times)

0 Members and 1 Guest are viewing this topic.

Spindle warm
« on: March 22, 2019, 05:24:22 PM »
Hello,

today I've updated mach4 to version build 4124 and I have some problem with the code in plc script. This code was working just fine with version build 3804. It's a code to warm up my spindle. It activates this code by pressing button to activate the led to start the timer dro and set the spindle rpm to 6000 for 4minutes. The rest of the code is in plc. With new update this code in plc doesent work when dro reads value of 4000, 8000 and 12000. Can someone please help me make it work again. Thanks.

PLC code:

local inst = mc.mcGetInstance()
local zero = 0
local SpindleWarmStartLED = scr.GetProperty("SpindleWarmStartLED", "Value")
local droSpindleWarm = scr.GetProperty("droSpindleWarm", "Value")
local machEnbld = mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.OSIG_MACHINE_ENABLED))

if (SpindleWarmStartLED == "1") then   
     local droSpindleWarmVar =(droSpindleWarm + 1)
     droSpindleWarm = tostring(droSpindleWarmVar)
     scr.SetProperty("droSpindleWarm", "Value",droSpindleWarm)
     end


     if (droSpindleWarm == "4000") then
         mc.mcSpindleSetDirection(inst, 1);
         mc.mcSpindleSetCommandRPM(inst, 12000);
     end

             if (droSpindleWarm == "8000") then
             mc.mcSpindleSetDirection(inst, 1);
             mc.mcSpindleSetCommandRPM(inst, 18000);
             end

                     if (droSpindleWarm == "12000") then
                     scr.SetProperty('droSpindleWarm', 'Value', tostring(zero))
                     scr.SetProperty("SpindleWarmStartLED", "Value", "0")
                     mc.mcSpindleSetDirection(inst, 0);
                     mc.mcSpindleSetCommandRPM(inst, 0);
                     end

                             if (machEnbld == 0) then
                             scr.SetProperty("SpindleWarmStartLED", "Value", "0")
                             mc.mcSpindleSetCommandRPM(inst, 0);
                             end
Re: Spindle warm
« Reply #1 on: March 22, 2019, 05:33:54 PM »
Hi,
I'm sorry I can't see anything wrong with that code.

I understand that just recently NFS has upgraded their Lua for 5.2 to 5.3. While 99% of it is identical there are a few
differences. I would guess that is whats happening here. Not that I can see it......

Craig
My wife left with my best friend...
     and I miss him!
Re: Spindle warm
« Reply #2 on: March 22, 2019, 10:16:28 PM »
I'm with craig, I can't see anything wrong with the code either.
However, why don't you just make a G Code file to warm up your spindle?

%
(Spindle Warm Up)
S12000 M3
G04 P240.0 (4 Min)
S18000
G04 P240.0 (4 Min)
M5
M30
%


I made a G Code file to warm up the spindle, I just keep it saved in my G Code Folder.

You can still put it in a button and make that button call a sub program.
You can save the spindle warm up program as a subprogram, and save it in the Subprogram folder in the Mach4 directory; save it as O9000 or something like that.
Then in the button script, use the MdiExecute API to call the subprogram.  M98 P9000
« Last Edit: March 22, 2019, 10:18:02 PM by Cbyrdtopper »
Chad Byrd
Re: Spindle warm
« Reply #3 on: March 23, 2019, 07:43:18 AM »
Hi,

thanks Craig and Chad for reply. Yes I can make spindle warm up program in G code. That solves this problem. But I have the similar code in plc for turn on/off my grease pump and It also don't recognize the value of 30000 for turning on the pump. This code was working in build 3804. The dro counts only when machine is moving. Any idea how to make this code to wokr in another way? Here is the code:

local inst = mc.mcGetInstance()
local MotionLED = scr.GetProperty("MotionLED", "Value")
local droPumpCounter = scr.GetProperty("droPumpCounter", "Value")
local zero = 0
local hsig,rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT7)
local Feed = mc.mcCntlFeedHoldState (inst)
local machEnbld = mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.OSIG_MACHINE_ENABLED))
--------------------------
if (MotionLED == "1") then   
     local droPumpCounterVar =(droPumpCounter + 1)
     droPumpCounter = tostring(droPumpCounterVar)
     scr.SetProperty("droPumpCounter", "Value",droPumpCounter)
end

if (droPumpCounter == "30000") then
      mc.mcSignalSetState(hsig,1)
     end
     
             if (droPumpCounter == "30010") then
             scr.SetProperty('droPumpCounter', 'Value', tostring(zero))
             mc.mcSignalSetState(hsig,0)
             end
--------------------------
if (machState == 0) then
     scr.SetProperty("MotionLED", "Value", "0")
     else
         scr.SetProperty("MotionLED", "Value", "1")

             if (Feed == 1) then
             scr.SetProperty("MotionLED", "Value", "0")
             end
end


Thanks,
Peter
Re: Spindle warm
« Reply #4 on: March 23, 2019, 06:59:10 PM »
Hi,
again I can't see anything wrong with that code.

I found this:

http://www.lua.org/manual/5.3/manual.html#8

Which list the differences and clashes between 5.2 and 5.3.

In 5.2 ALL numbers were float types, now there is a 64 bit integer subtype. If I were to guess I would say its that
change that has upset your code.

For instance how is:
"local droPumpCounterVar =(droPumpCounter + 1)" interpreted?
Under 5.2 local "droPumpCounterVar" was a float but under 5.3 its integer....I think??
How then is the subsequent "droPumpCounter = tostring(droPumpCounterVar)" type conversion handled?
and more importantly how is the conditional "if (droPumpCounter == "30000") then" evaluated?
is the variable '30000' or is it '30000.0' ??

Craig
My wife left with my best friend...
     and I miss him!
Re: Spindle warm
« Reply #5 on: March 23, 2019, 07:06:49 PM »
Hi Peter,
this is a reply in another thread that is very similar:
https://www.machsupport.com/forum/index.php?topic=39727.new#new

Craig
My wife left with my best friend...
     and I miss him!
Re: Spindle warm
« Reply #6 on: March 25, 2019, 02:59:41 PM »
Hi Craig,

Today I’ve tried again new update build and It worked! I’ve changed the numbers from 30000 to 30000.0. All the codes now work. Thanks again for you help.

Regards,
Peter