2211
Mach4 General Discussion / Re: Help with first easy script or macro (which term?) for automatic oiler
« 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:
The second idea is a very similar API mcMotionGetVelocity():
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
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