Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: rrc1962 on June 12, 2016, 05:56:16 PM
-
Consider the following M code. It should read the feedrate from a DRO, which is does (300), set the feedrate to 300, move to X5Y5 then back to zero.
function m200()
local inst = mc.mcGetInstance()
local Feedrate = mc.mcProfileGetDouble(inst, 'PersistentDROs', 'droPLFeedRate', 1)
mc.mcCntlSetLastError(inst, 'Set Feedrate')
code2 = 'F ' .. Feedrate .. '\n'
code2 = code2 .. 'G01 X5 Y5\n'
code2 = code2 .. 'G01 X0 Y0\n'
mc.mcCntlGcodeExecuteWait(inst, code2)
end
if (mc.mcInEditor() == 1) then
m200()
end
It does not set the feedrate to 300IPM. It sets it to 3IPM. The Feedrate variable is correct. Same thing happens if I replace Feedrate with a '300'. So thinking that I just need to multiply the Feerate variable by 100, I try this...
function m200()
local inst = mc.mcGetInstance()
local Feedrate = mc.mcProfileGetDouble(inst, 'PersistentDROs', 'droPLFeedRate', 1)
mc.mcCntlSetLastError(inst, 'Set Feedrate')
code2 = 'F ' .. Feedrate * 100 .. '\n'
code2 = code2 .. 'G01 X5 Y5\n'
code2 = code2 .. 'G01 X0 Y0\n'
mc.mcCntlGcodeExecuteWait(inst, code2)
end
if (mc.mcInEditor() == 1) then
m200()
end
This sets the system Feedrate to 9IPM. Do I have a setting wrong? Seems like the only code that will run inside mc.mcCntlGcodeExecuteWait is simple. This one is similar. The G31 executes but the feedrate is a fraction what it is told to be.
function m200()
local inst = mc.mcGetInstance()
local Feedrate = mc.mcProfileGetDouble(inst, 'PersistentDROs', 'droPLFeedRate', 1)
mc.mcCntlSetLastError(inst, 'Set Feedrate')
code2 = 'G31 Z-2 F100\n'
code2 = code2 .. 'G92 Z0\n'
mc.mcCntlGcodeExecuteWait(inst, code2)
end
if (mc.mcInEditor() == 1) then
m200()
end
The Feedrate is running at 1IPM. Also can't get any of this to actually run by calling the M code. It runs in the editor, but not when the M code is called.
-
I should also mention that if I load a gcode file that has say...F100 in it, The feedrate sets properly. This only seems to be happening using mc.mcCntlGcodeExecuteWait. Also interesting is that no matter what I set the Feedrate variable to, it will not go higher than 9IPM. I can say 'F3000' or 'F900000'. Either way, the system feedrate gets set to 9IPM.
-
So....I got this M code working. Not sure what I did, but now it works one time. If runs as it should, but to get it to run again, I have to shut down M4. Most of the time, I have to use task manager to shut it down.
Isn't there a way to trap runtime errors here? It runs fine in the editor, so debugging there is of little use.
-
there is a post on the affect of each Gcode run type I will find it and post it. it's from one of the mach guys
-
Have you ever considered using the registry plugin (also can be persistent) and assign a register to your dro, this can then be retrieved from within the macro.
DazTheGas
-
Have you ever considered using the registry plugin (also can be persistent) and assign a register to your dro, this can then be retrieved from within the macro.
DazTheGas
Good idea. I had not thought of that. Could the feedrate also be set that way? IE: Assign the Feedrate DRO to a register and rather than posting 'F100' to mc.mcCntlGcodeExecuteWait(), just set the registry value assigned to the DRO. Retrieving the feedrate value wasn't the problem. Setting it was the issue.
I did get it working. I knew the macro was running because is was setting last error. I was just failing somewhere within. I put message boxes after every line of code and ran it until the message boxes quit showing. Turns out it was a case of a bad line of code. The code looked fine and ran fine in the editor, just wouldn't run in real time. I retyped what looked like an identical line and commented the first, and it ran fine. This is the second time this has happened.