Hello Guest it is April 25, 2024, 04:57:17 PM

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

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
I need to make a script or macro for turning on my oiler output anytime an axis is moving.

The oiler has it's own motor that pumps out a certain volume over time. So all I need to do is turn it on when the X or Y is moving to keep the ways oiled.

I figured this out in mach 3 with the brain editor thing, but now I am starting from scratch here. I also lost this brain for mach3 somehow. I cannot find it anywhere....I have not used the machine in years. 

Other than turning it on anytime there is a move, do you think I should add a minimum time limit or minimum distance so it is not clicking off and on with every little jog? The issue here is that if you make a bunch of little jogs it may not lube enough? However if it is clicking on and off a million times maybe that will wear out the relay or oil pump?

Anyway, I am sure someone has to have done this by now so any help is appreciated. I was watching videos on youtube of making a tool change script and started to fall asleep, so I figured I better get out here on the machine and do something simpler and wake up :)

In the mean time I will do more research and reading while I see if there is any response here.

Thanks!

Offline mark4

*
  •  167 167
    • View Profile
hello I had the same problem with the machines i rebuild and received some help
-------------------------------------------------------
-- Run Lube
-------------------------------------------------------
local inst = mc.mcGetInstance()
local hsig,rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0)
if (machState == 0)then
    mc.mcSignalSetState(hsig,0)
else
    mc.mcSignalSetState(hsig,1)
end
This program is placed in the plc script and runs when any axis moves. I don't know what type of oiler you have
or how its meant to work. a relay or timer motor should have no problem turning on and off repeatedly. It comes to duty cycle and if a relay fails from that then it was defective or a poor specimen to begin with.

Offline jevs

*
  •  315 315
    • View Profile
Thanks, I will try to decode this so I know what it is doing and then go from there.

I have an MMXL-III oiler.
It pumps out oil at a rate of 2.5cc per 15mins. It just pumps oil real slow when it is on.

I think I may also create a custom on and off M code and make a button on the screen to manually operate it and to light up the button when it is on maybe if I figure it out....

Offline jevs

*
  •  315 315
    • View Profile
I just realized that you said this runs when any axis moves. I only want it to run if X and/or Y moves. The Z axis has no oiling (has grease fittings).
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #4 on: August 01, 2019, 03:27:41 AM »
Hi,
you are scattering the same question over different threads.....its hard to keep up.

The basic problem to be solved is you need to know when the X and/or Y axis is moving. If so turn on the oiler, if
not turn off the oiler.

Turning an oil pump on and off is easy......deciding when is the trick here. Mark came up with a simple idea, test when
Mach is idle, ie machState==0. If its idle turn the oiler off, if Mach is in any other state then turn the oiler on.
As you pointed out that test is pretty crude.......but there are other ways.

The first idea I have is the mcMotorGetVelocity() API:
Code: [Select]
LUA Syntax:
velocity, rc = mc.mcMotorGetVel(
number mInst,
number motor)

Description:
Retreive the current velocity of a motor in counts per sec.

Parameters: Parameter Description
mInst The controller instance.
motorId An integer specifying the motor.
velocity The address of a double to receive the motor velocity.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_MOTOR_NOT_FOUND The motor specified by motorId was not found.
MERROR_INVALID_ARG velocity cannot be NULL.

The second idea is a very similar API mcMotionGetVelocity():
Code: [Select]
LUA Syntax:
velocity, rc = mc.mcMotionGetVel(
number mInst,
number motorId)

Description:
Retrieve the current motor velocity in counts per second squared.

Parameters: Parameter Description
mInst The controller instance.
motorId An integer specifying the motor ID.
velocity. The address of a double to receive the motor velocity. 


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_MOTOR_NOT_FOUND The motor specified by motorId was not found.
MERROR_INVALID_ARG velocity is NULL or motorId is less than 0.

You could use either API in a PLC script to determine if the X and/or Y axis is moving. Devising some strategy for 'smoothing'
the turn-on/turn-off so that the pump is not turning on and off with every move will take some thinking about.

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 #5 on: August 01, 2019, 11:15:15 AM »
Yeah the first problem I have with all of this is that everyone is assuming I am already a Lua programmer and that I am just not figuring out the right commands to use for my task.
The real problem is that I do not know what any of these commands or lines of code are doing. After much digging and noticing people using it in videos, I found the Mach4 Core API help file. So I can start decoding what is going on here....However using the search tool in this help file is about useless. It does not even find stuff that is in there once you look manually.

For example, lets just start with what seems to be the first line to everything I see:
local inst = mc.mcGetInstance()

Where would I find the info that explains what this does. This is not in the Alphabetical API Reference list
I kinda know what this one does just because I have watched so many videos and read so much stuff already, but I do not have a pure definition. I assume this some how sets it to use my currently being used instance of Mach4 or something. I would really like a better definition and how to find it for myself. What is the instance? a number? the profile I am using?, or what?

 
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #6 on: August 01, 2019, 02:27:04 PM »
Hi,

Quote
However using the search tool in this help file is about useless.

There is no substitute for reading it.

A substantial part of Lua programming is knowing the API and the structure of Mach4. You were warned that Mach4
has a learning curve....this is it. It is for this reason that I encourage new-comers to setup Mach with all the standard
procedures that don't require any Lua coding.

I wrote a short intro about using the Signal Library, called SignalScript.pdf, it will answer some of your questions:

https://www.machsupport.com/forum/index.php?topic=40051.msg267764#msg267764

You will need this link, I have it open all the time when I'm coding:

https://www.lua.org/manual/5.3/

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 #7 on: August 01, 2019, 04:10:52 PM »
I am many days of time into this changeover now with a lot of reading, watching videos (and falling asleep during them LOL), and hands on trial and error.

I already have my machine running now......except the stuff that does require learning Lua, updating some parts, and the Mach4 programming structure (Aux functions, toolchanger, etc). I do have the manual button, indicator, and M codes setup for the oiler and working (except turning off when disabled). I figured I would do those before tackling the automatic oiler stuff.

I have already learned a lot, but still have a long way to go. The one thing I am dreading is the tool change most. My old VB script is so easy to understand and follow. I had not looked at it in years, but opened it today, and it makes perfect sense and is darn near plain English the whole way through compared to Lua.

What I meant by the search not working, is that if you go into the API help file, search for some text so you can look up what something is.....it returns nothing sometimes. If you manually dig and search for it, it is in there. This is not really a "being lazy" thing. You would just expect the search tool to find you what you need so you can spend the time reading about it without scrolling through everything trying to find if it is there. This is the great thing about it not being a paperback book vs an electronic text file! :) The important part is alphabetical at least, that helps some.

Thanks for the Lua manual link. I found a PDF version that will be easier to search if anyone reads this and wants it that way....
https://jackens.github.io/downloads/Lua-5-3-Reference-Manual.pdf

I will check out your SignalScript.pdf. Thanks for the link.

I will likely discover this as I read and research more, but I am going to ask anyway...

What is the mc. for? Is this a way of calling out the custom API commands that are only for Mach? Is "mc" an abreviation for something unique to mach4?

Also in the Lua Manual. Many things starts with "LUA_" but I do not see that in any coding for Mach so far? Is that just dropped from the commands or a placeholder for something else? 


« Last Edit: August 01, 2019, 04:12:58 PM by jevs »
Re: Help with first easy script or macro (which term?) for automatic oiler
« Reply #8 on: August 01, 2019, 04:41:37 PM »
Hi,

Quote
What is the mc. for? Is this a way of calling out the custom API commands that are only for Mach? Is "mc" an abreviation for something unique to mach4?

That is explained in the SignalScript.pdf link I gave you.

mc= Mach Core.

Lua has one and one only data structure....the table.

Lets say you have a table called TableXYZ and you want to recall an entry in that table, say 'currentX', you would address this by:

TableXYZ.currentX. All member or entries of a table are addressed that way.

Look at a API, say:
mc.mcSignalGetHandle()

The actual function (or member or entry) is mcSignalGetHandle() but it is in a table of functions called mc.

The use of the table data structure and 'functions as first class values' are ABSOLUTELY FUNDEMENTAL to Lua's flexibility and
power. You will encounter these concepts over and over. Get familiar with them. It is exactly these principles that make
VB so last century.

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 #9 on: August 01, 2019, 05:00:08 PM »
Great info. Thanks. I will be spending more time soaking this up. I think I understood half of what I just read....if I read it 3 days ago it would have been total greek and 0 comprehension...so we are making progress.

The last 12 hours has just been me trying to learn a little here and there while at work. Now I get to commute for an hour and go back to hands on for a couple hours.....if I can stay awake.