Hello Guest it is March 28, 2024, 12:12:38 PM

Author Topic: Request for LUA advice: Absolute homing  (Read 722 times)

0 Members and 1 Guest are viewing this topic.

Request for LUA advice: Absolute homing
« on: September 22, 2019, 02:45:33 PM »
Hi again,

I have developed a serial interface from Mach 4 to my Allen Bradley Ultra 3000 servo drives using LUA. One of the capabilities of this interface is to define the zero (home) position of the motor in the servo drive, and later read the current position of the motor back into Mach 4. Since my motors have magnetic multiturn encoders, this position will be stored through power cycles and even when the motor is moved by hand when the machine is powered off. This means that once the home position is set in the servo drive, I will never need to home my CNC again unless the motor is decoupled from the drive or ballscrew.

What I am hoping to do is run the normal homing routine in Mach 4, but modify it to set the zero position in the drive at the same time as it is set in Mach 4. Then going forward, clicking Ref All Home need only ask the drive where it is currently located and copy that data into Mach 4 axis positions.

My questions is this, if I have all my axes dereferenced, can I copy my known motor position into the axis position using mcAxisSetPos(Inst, 0, XPosition)? If so, how do I mark that axis as referenced without running the Mach 4 homing sequence to drive the axes to their limit switches?

Thanks in advance for any help or thoughts on this.
Re: Request for LUA advice: Absolute homing
« Reply #1 on: September 22, 2019, 02:58:09 PM »
I'm sure there are errors in this code but this is what I am imagining for the homing (just the X axis in this example).

The call
Code: [Select]
serialError, XPosition = mcServo.GetPosition(00, XctsInch) is a function from a custom module that messages my servo drive over RS485 serial and returns an error code (usually 0) and a position of the motor using the parameters drive serial address (x axis = 0) and counts per inch.


Code: [Select]

local inst = mc.mcGetInstance()

function absoluteHomeX()
local serialError = 0
local XPosition = nil
mcAxisDerefAll(Inst) --Deref all axes

int rc = mcMotorGetCountsPerUnit(Inst, 0, &XctsInch) --Store the X Axis counts per inch into XctsInch
serialError, XPosition = mcServo.GetPosition(00, XctsInch) --Query the X Axis Drive for the position (in inches from zero)
if serialError~= 0 then --Determine if the serial request failed
XAxisPos = nil
return
end
mcAxisSetPos(Inst, 0, XPosition) --Set the X Axis Position
mcAxisHomeComplete(Inst, 0);  --Mark the X Axis in Mach 4 as referenced
end