Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Cal892 on December 16, 2016, 10:25:15 AM

Title: Feed Rate Override Absolute Value?
Post by: Cal892 on December 16, 2016, 10:25:15 AM
Hey everyone,

I'm fairly new to Mach 4 and am setting up a new system. I'm trying to enter a new feed rate for use with the 'Go To Work Zero' button that is on the default screen. I use this very frequently to move in straight cuts as it is a CNC hotwire machine. I need to frequently change the feed rate depending on what material I'm cutting.

the API indicates that mcCntlSetFRO is only be able to change the feed rate by percentage. Is there a method of changing it to an absolute value? Or is there perhaps a way to use a DRO to enter a new value with the 'f' Gcode command?
Title: Re: Feed Rate Override Absolute Value?
Post by: DazTheGas on December 16, 2016, 11:03:36 AM
This runs a function that is within the Screen Load Script that simply runs an mdi code.

Code: [Select]
function GoToWorkZero()
    mc.mcCntlMdiExecute(inst, "G00 X0 Y0 A0")--Without Z moves
    --mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG00 X0 Y0 A0\nG00 Z0")--With Z moves
end

DazTheGas
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on December 16, 2016, 11:19:05 AM
Thanks Daz,

I figured that I could use a button with an mdi/gcode to change the feed rate. Is there a way to use a DRO to enter a variable that I can then use in that function?
I'm assuming I can use the 'on modify script' section in a DRO to run the function, but I'm unsure how to pull a number that I enter into it.
Title: Re: Feed Rate Override Absolute Value?
Post by: Chaoticone on December 16, 2016, 12:55:28 PM
You can link the DRO to a register or a parameter and get those values in your script. You can also assign the DRO to neither and get the value property of the DRO. Like this.......

local rate = scr.GetProperty("droJogRate", "Value")

You can set the jog rate for all axis or each axis individually.

scr.SetProperty("droJogRate", "50")

mc.mcJogSetRate(inst, mc.X_AXIS, 50)

There isn't much you can't do really.
Title: Re: Feed Rate Override Absolute Value?
Post by: Chaoticone on December 16, 2016, 12:59:00 PM
But Daz is right............ if you want to alter how that function works alter it in the function.
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on December 16, 2016, 01:25:03 PM
Thanks for the help,

I didn't fully understand Daz's original suggestion, I'm not used to being able to edit the pre-defined functions at will.
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on December 16, 2016, 02:25:51 PM
Thanks for the tips however I'm not looking to change the jog rate, just the feed rate. Perhaps I'm not seeing what you're trying to tell me. I'm aware that I can edit the go to zero function to have any specific feed rate I like, but I need to change that feed rate frequently so coding it into the button isn't the best option.

Your example seems to show that I can pull a user entered value from a DRO, but I'm not sure how to change the feed rate with that value. I don't think I can edit the mcCntlSetFRO function to accept an absolute value instead of a percentage. I also don't think I'm able to use a variable in an mdi code.

The only option that I'm seeing is to create individual buttons with mdi commands for each feed rate I would like to use. A possibility, but not an ideal solution.
Title: Re: Feed Rate Override Absolute Value?
Post by: Chaoticone on December 16, 2016, 03:39:24 PM
Not sure exactly what your looking to do but jogging speed is only set as a percentage of max velocity. But with some math you can arrive at what percentage any speed would be.............. so you could have a DRO you enter a speed into.

You can do feed moves at any speed you want but you also have to know what position or distance.

The following example has a little of everything your looking for I think. Down script goes in a buttons down script event and the up script goes in the same buttons up script event. It will get the vale from the JogRate DRO and jog the X axis negative at 50% of that percentage and it will jog the Z axis positive at 100% of that percentage. Lets see what you can do with it........

Code: [Select]
--Down Script

local inst = mc.mcGetInstance()
local rate = scr.GetProperty("droJogRate", "Value")
rate = tonumber(rate)

mc.mcJogSetRate(inst, mc.X_AXIS, (rate/2))
mc.mcJogSetRate(inst, mc.Z_AXIS, rate)
mc.mcJogVelocityStart(inst, mc.X_AXIS, mc.MC_JOG_NEG)
mc.mcJogVelocityStart(inst, mc.Z_AXIS, mc.MC_JOG_POS)

--Up Script
local inst = mc.mcGetInstance()
mc.mcJogVelocityStop(inst, mc.X_AXIS)
mc.mcJogVelocityStop(inst, mc.Z_AXIS)
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on December 21, 2016, 04:13:04 PM
Thanks for the help Daz and Chaoticone, got it working well now
Title: Re: Feed Rate Override Absolute Value?
Post by: Chaoticone on December 21, 2016, 04:34:39 PM
Good deal!

How about tell us or show us what you did. It may answer others questions.
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on December 22, 2016, 10:13:01 AM
I have three DRO's; one for X move value, one for Y move, and one for feed rate. The feed rate entered is an absolute feed rate so the feed rate is determined as a percentage of 150in/min(100% jog speed on my setup)
After calculating the diagonal distance needed to travel, feed rate values are calculated for the X and Y so that the motors move together and arrive at the same point at the same time. the values are factors of the Hypotenuse so as to create the right triangle.

For some reason I was originally having issues with setting slow feed rates because the motors were running at rapid feed rates and the PMDX BOB was sending strange signals resulting in the motors moving abnormally slowly(up to 10x slower than was entered). After the jog rate was corrected in the configurations it ran smoothly.

The script is all in the "left up" section, there are probably more tonumber() functions than are necessary, but I was having some problems and haven't gone back to remove extras as they don't cause any issues.

Code: [Select]
--"Move To" Script

local inst = mc.mcGetInstance()
local hypLength = 0                                
local rateH = scr.GetProperty("droSpeed", "Value")  --Requires DRO named "droSpeed"
local rateX = 0
local rateY = 0
local xJog = scr.GetProperty("droXmove", "Value")   --Requires DRO named "droXmove"
local yJog = scr.GetProperty("droYmove", "Value")   --Requires DRO named "droYmove"
local xNeg = 1
local yNeg = 1

hypLength = tonumber(hypLength)
rateH = tonumber(rateH)
rateX = tonumber(rateX)
rateY = tonumber(rateY)
xJog = tonumber(xJog)
yJog = tonumber(yJog)
xNeg = tonumber(xNeg)
yNeg = tonumber(yNeg)



--Determining if negative values
if(xJog < 0) then
xNeg = -1
math.abs(xJog)
end

if(yJog < 0) then
yNeg = -1
math.abs(yJog)
end


--X Y Rates Calc
hypLength = math.sqrt((xJog^2)+(yJog^2))

rateX = xJog/hypLength
rateX = rateH*rateX

rateY = yJog/hypLength
rateY = rateH*rateY


--Feed rate calcs if single asix travel(100% = 150in/min)
if(xJog or yJog == 0) then
rateH = rateH/1.50
rateH = tonumber(rateH)
rateX = rateH
rateY = rateH
end

--Set jog rate for each axis
rateX = tonumber(rateX)
rateY = tonumber(rateY)
mc.mcJogSetRate(inst, 0, rateX)
mc.mcJogSetRate(inst, 1, rateY)


--Input distance to travel for each axis
xJog = tonumber(xJog)
yJog = tonumber(yJog)
xJog = xJog*xNeg
yJog = yJog*yNeg
mc.mcJogIncStart(inst, 0, xJog)
mc.mcJogIncStart(inst, 1, yJog)

Thanks again for all the help, I hope this can be of use to others as well
Title: Re: Feed Rate Override Absolute Value?
Post by: Chaoticone on December 22, 2016, 02:41:24 PM
Nice! I'lll check out your script later today. Thanks for posting your solution. 
Title: Re: Feed Rate Override Absolute Value?
Post by: Cal892 on January 06, 2017, 04:56:37 PM
I realized there were some errors in the code posted earlier. Here is an update.


Code: [Select]
--"Move To" Script

local inst = mc.mcGetInstance()
local hypLength = 0                                 
local rateH = scr.GetProperty("droSpeed", "Value")  --Requires DRO named "droSpeed"
local rateX = 0
local rateY = 0
local xJog = scr.GetProperty("droXmove", "Value")   --Requires DRO named "droXmove"
local yJog = scr.GetProperty("droYmove", "Value")   --Requires DRO named "droYmove"
local xNeg = xJog
local yNeg = yJog

hypLength = tonumber(hypLength)
rateH = tonumber(rateH)
rateX = tonumber(rateX)
rateY = tonumber(rateY)
xJog = tonumber(xJog)
yJog = tonumber(yJog)
xNeg = tonumber(xNeg)
yNeg = tonumber(yNeg)
rateH = rateH/1.50


--Determining if negative values
if(xJog < 0) then
--xNeg = xJog
math.abs(xJog)
end

if(yJog < 0) then
--yNeg = yJog
math.abs(yJog)
end


--X Y Rates Calc
hypLength = math.sqrt((xJog^2)+(yJog^2))

rateX = xJog/hypLength
rateX = rateH*rateX

rateY = yJog/hypLength
rateY = rateH*rateY

--Set jog rate for each axis
rateX = tonumber(rateX)
rateY = tonumber(rateY)
mc.mcJogSetRate(inst, 0, rateX)
mc.mcJogSetRate(inst, 1, rateY)


--Input distance to travel for each axis
xJog = xNeg
yJog = yNeg
mc.mcJogIncStart(inst, 0, xJog)
mc.mcJogIncStart(inst, 1, yJog)