Hello Guest it is March 28, 2024, 02:00:15 PM

Author Topic: Help with first easy script or macro (which term?) for automatic oiler  (Read 2136 times)

0 Members and 1 Guest are viewing this topic.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #10 on: August 03, 2019, 06:47:49 PM »
Something like this should work. Make sure you set the right output in the script. I would have a function in the screen load script that is ran each cycle through the PLC script.

Code: [Select]
--PLC script
TogWayOil()

--Screen load script
function TogWayOil()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)
local sigState, rc = mc.mcSignalGetState(hSig)
local vX, rc = mc.mcAxisGetVel(inst, mc.X_AXIS)
local vY, rc = mc.mcAxisGetVel(inst, mc.Y_AXIS)
local xyVel = math.sqrt((vX * vX) + (vY * vY))

if (sigState == 0) and (xyVel > 0) then --turn the output on
rc = mc.mcSignalSetState(hSig, 1)
elseif  (sigState ~= 0) and (xyVel == 0) then --turn the output off
rc = mc.mcSignalSetState(hSig, 0)
end
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline jevs

*
  •  315 315
    • View Profile
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #11 on: August 03, 2019, 06:52:54 PM »
I was just about to type this before you responded above. I am going to have to try to decode what you just put there to understand it. That will take me a bit.

However, what about using MotorIsStill instead of velocity?

Motor has its "isStill" when it is not in motion. still == TRUE is no movement, still == FALSE motor has movement.

This seems like it could be exactly what I was looking for and possibly easier than the extra math of using the velocity? (I have not fully decoded your code yet)

Also. Is there a specific place within the PLC script that I should be putting my stuff?

« Last Edit: August 03, 2019, 06:57:28 PM by jevs »
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #12 on: August 03, 2019, 07:00:13 PM »
Hi,

Quote
Motor has its "isStill" when it is not in motion. still == TRUE is no movement, still == FALSE motor has movement

Yes that would work but there is a catch. That signal is set by the motion controller....not Mach. Thus if the motion
controller manufacturer included in his firmware to set this signal every time the motor stopped this would work.
It is not a given however. This API is used particularly when homing or probing. There is no requirement that it be set
otherwise.

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline jevs

*
  •  315 315
    • View Profile
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #13 on: August 03, 2019, 08:02:54 PM »
I guess the only way I will know if the ESS has this setup is to write the code and try it?
I guess I would like to try and see, then go back to the above code with the velocity if it does not work. The only reasons being is that it could be less lines of code and it is all good learning to code this stuff.
I am still trying to figure out how to put mcMotorIsStill into code in a proper way to try it....decoding this all a bit rough for a newbie. Thank god for coffee :) 

Offline jevs

*
  •  315 315
    • View Profile
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #14 on: August 03, 2019, 09:14:44 PM »
Well, I cannot figure this out so far, but I am still working on it......
this does NOT work, but I have not figured out what is wrong with it yet
Something to do with mcMotorSetStill being nil I suspect, but I barely know what I am doing here....
Code: [Select]
---------------------------------------------------------------
-- Start of P&W Mill additions
---------------------------------------------------------------
function TogWayOil()
local still, rc = mc.mcMotorIsStill(inst, mc.MOTOR0)
local mcMotorSetStill(inst, mc.MOTOR0, 0) --Get the state if MOTOR0 is moving
if(still == 0) then
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig, 1) --sets OSIG_OUTPUT4 to True
else
local hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig, 0) --sets OSIG_OUTPUT4 to False
---  THIS CODE MAY TURN OFF THE OILER EVEN IF IT WAS TURNED ON WITH M CODE OR BUTTON!------
end
end
---------------------------------------------------------------
-- End of P&W Mill additions
---------------------------------------------------------------

I know if I ever get this working that I have to make some mods somewhere to keep it from turning off the oil if it was manually turned on with a button or M-Code. That is why I made that note there, but I have to get it working before I can look into that.
« Last Edit: August 03, 2019, 09:16:59 PM by jevs »

Offline jevs

*
  •  315 315
    • View Profile
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #15 on: August 03, 2019, 10:08:28 PM »
After wasting a ton of time with no success figuring out how to use the isStill function, I went back to try the velocity as suggested.
I did post on the Warp9 forum to ask if they use the other function or not....however, I cannot justify spending any more time with that one for now.

I got the velocity method working and even put an indicator LED next to my jog buttons as a visual to know it is already on or working when I jog.

This code does kill the manual oiler button as I suspected. So, I need to figure out how to make the whole thing ignored if the oiler button was used to turn it on already.
« Last Edit: August 03, 2019, 10:12:59 PM by jevs »