Totally new to me anything in a macro thats more than just a few commands. Ive managed to get this one together but it will be full of mistakes. I have been on this for a while now and its time to ask. Aim is to have a M10 and M11 for a hydraulic brake on a 4th Axis I have built. All it needs to do is:
M10
Switch on hyd pump
Make sure the "brake off" solenoid is closed or close it if its open
Open the "brake on" solenoid
Wait for an input (NO signal) closed on brake extension.
Close "brake on" solenoid
Turn off hyd pump.
M11 will be the same but with the IOs swapped around. I managed to get a macro without the inputs working. But only if the "Brake Off" button on my screen is toggled. I guess someone familia with LUA will say - "thats where you went wrong" Hey anyways would someone please give me some advice on how to change this macro to function as it should?
If I can get this working, I would also like to add in a section that checks pump pressure prior to proceeding. And if there is no pressure, via another input, an error comes up. I think I know what I need to code for this, I just want to get the basic version working. Would appreciate some help please. I can build things, coding is not my strength. To be brutally honest I have no idea what half of my code does. Well, the hSig thing for a start.
function m10()
local inst = mc.mcGetInstance() -- Get Mach 4 Instance
local hSig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4) -- Set the handle for output4 pump on output
local state, rc = mc.mcSignalGetState(hSig) -- Set the state of the handle
if state == 0 then -- Not sure why but this seems to work to make sure the pump is on.
mc.mcSignalSetState(hSig, 1) -- Set the pump on
else
mc.mcSignalSetState(hSig, 1) -- Regardless of state make sure the pump is on.
end
local hSig6, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT6) -- Set the handle for Output 6 which is the brake release solenoid
local state6, rc = mc.mcSignalGetState(hSig6) -- State
if state6 == 1 then
mc.mcSignalSetState(hSig6, 0) -- Ensure the solenoid is closed or the brake wont work
else
mc.mcSignalSetState(hSig6, 0) -- Again
end
local hSig2, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5) -- Set the handle for output 5 which is the brake on solenoid. On = open
local state2, rc = mc.mcSignalGetState(hSig2) -- State
if state2 == 0 then
mc.mcSignalSetState(hSig2, 1) --If its off set it on.
end
local hSig3, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4) -- Set the handle for input 4 which is the brake on micro switch. Made = brake on.
local state3, rc = mc.mcSignalGetState(hSig3)
if state3 == 1 then
mc.mcSignalSetState(hSig2, 0) -- Close the brake on solenoid which will lock the brake.
mc.mcSignalSetState(hSig, 0) -- Turn the pump off
end
end