Hello Guest it is April 25, 2024, 06:07:08 AM

Author Topic: Using a button script to set jog increments etc  (Read 14798 times)

0 Members and 1 Guest are viewing this topic.

Re: Using a button script to set jog increments etc
« Reply #40 on: May 26, 2018, 05:20:24 PM »
ok, I've added this in the PLC script but it always turns the btn1000micron button green, regardless of the increment that I know is working correctly because it jogs the amount that it should.

So it looks like the line "increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)" always returns 1.
Can you see what I'm doing wrong? In a previous example you set up the function in the screen script and called that from the PLC. Maybe you can't access the increment from the PLC script directly?

Also, I'm not sure about that line in the error checking that says "return" I think that needs to go.

-------------------------------------------------------
--   Handle the radio button action of the Jog increment buttons
-------------------------------------------------------

local increment
local rc
increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)
if (rc ~= mc.MERROR_NOERROR) then
    mc.mcCntlSetLastError(inst, "JogGetInc failed")
    return;  --???????
end

if (increment == 1) then
   scr.SetProperty("btn1000micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"    ????? this line always executed
   scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
elseif (increment == 0.1) then
   scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn100micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
elseif (increment == 0.01) then
   scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn10micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
elseif (increment == 0.001) then
   scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   scr.SetProperty("btn1micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
end
« Last Edit: May 26, 2018, 05:29:06 PM by striplar »
Re: Using a button script to set jog increments etc
« Reply #41 on: May 26, 2018, 05:41:19 PM »
Hi striplar,
this is an ideal situation for you to use one of the 'flags' we were talking about.

Put a:
mc.mcCntlSetLastError(inst,'Jog Increment=1')
in the first if-then and a:
mc.mcCntlSetLastError(inst, 'Jog Increment=0.1')
in the second and so on.

It will indicate whether the If conditional is being executed and if it correctly decides which chunk of code to run.

Of course they can be stripped out again once you've got it to work.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #42 on: May 27, 2018, 05:23:34 AM »
Hi Craig,
Point taken, I can see how useful that mcCntlSetLastError() function is.

I've now moved the code called from the PLC to the Screen Load Script as shown below and incorporated the error function to show me what's going on.
The global variable to track the changed in the increment was borrowed from a previous example shown me in this thread. It makes sense to only update screen properties when they change so as to save time, and it also reduced the number of errors in the log so it's more readable.

What this has confirmed is that it all works except that the increment value read using...     increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)   ... always returns the value 1, regardless of the actual jog increment that is set using the buttons. I know they are doing their job because the jog does move the selected amount.

So the question is, why does that function not return the value that's set by the button when the button for 0.1mm for example calls the.... Jog Inc. 2 function from the Left Up Action button event? It seems to me that the variable used for jogging is cannot be mc.X_AXIS or it's somehow not available for some reason. Perhaps it's an error in the syntax?

----------------------------------------------------------------------------
--   Handle the radio button action of the Jog increment buttons - My code!
----------------------------------------------------------------------------
function UpdateJogRadioButtons()  --called from the PLC script
--currentInc = 0 -- my global var to track the current increment defined above

--local inst = mc.mcGetInstance() --apparently not required
local increment
local rc
increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)
if (rc ~= mc.MERROR_NOERROR) then
    mc.mcCntlSetLastError(inst, 'JogGetInc failed')
    return;
end

if (increment ~= currentInc) then   --so we don't unnecessarily update anything
    mc.mcCntlSetLastError(inst, "currentInc=" .. tostring(currentInc))
    mc.mcCntlSetLastError(inst, "increment=" .. tostring(increment))
   
   if (increment == 1) then
      mc.mcCntlSetLastError(inst,'Jog Increment=1')
      scr.SetProperty("btn1000micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   elseif (increment == 0.1) then
      mc.mcCntlSetLastError(inst,'Jog Increment=0.1')
      scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn100micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   elseif (increment == 0.01) then
      mc.mcCntlSetLastError(inst,'Jog Increment=0.01')
      scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn10micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn1micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   elseif (increment == 0.001) then
      mc.mcCntlSetLastError(inst,'Jog Increment=0.001')
      scr.SetProperty("btn1000micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn100micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn10micron", "Bg Color", "");--"ControlName", "PropertyName", "Value"
      scr.SetProperty("btn1micron", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
   end
      
   --scr.SetProperty("btnContinuousMode", "Bg Color", "");--"ControlName", "PropertyName", "Value"
   currentInc = increment   --remember what the new increment is
end
end
Re: Using a button script to set jog increments etc
« Reply #43 on: May 27, 2018, 06:17:49 AM »
There's something definitley screwy going on. As an experiment, I put the following code into the button script that should set the increment to 0.001mm

It fails on the SetJogInc() function..... however, it does appear to have changed the mc.X_AXIS variable because now I can read back that value using GetJogInc() and it shows me 0.001mm!

However, the amount it actually jogs is unaffected by this. In other words, mc.X_AXIS can't be the value it's using when it actually goes to jog.

Any ideas what the actual variable used is called? Perhaps it is mc.X_AXIS but I'm not using the right syntax


local inst = mc.mcGetInstance()
local increment
local rc

increment, rc = mc.mcJogSetInc(inst, mc.X_AXIS, 0.001)

if (rc ~= mc.MERROR_NOERROR) then
    mc.mcCntlSetLastError(inst, 'JogSetInc failed')
   return;
end

increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)
if (rc ~= mc.MERROR_NOERROR) then
    mc.mcCntlSetLastError(inst, 'JogGetInc failed')
    return;
end

    mc.mcCntlSetLastError(inst, "increment=" .. tostring(increment))

Another thought is that the MachMill screen is using something else for the jogging increments. I see that the Left Dow Action for the X- button is calling "Job X-" action, but I've searched through the screen script and that's not in there. I can't see that anywhere listed in any of the help or scripting documents so I have no idea how it work and what it affects.
It certainly doesn't take any notice of the value in mc.X_AXIS

Any ideas?

Re: Using a button script to set jog increments etc
« Reply #44 on: May 27, 2018, 09:31:26 AM »
Hi,
I'm a bit confused myself.

Quote
however, it does appear to have changed the mc.X_AXIS variable because now I can read back that value using GetJogInc() and it shows me 0.001mm!
mc.X_AXIS is NOT a variable, it is an ENUM, it is the number of the X axis. Its defined within Machs core and you cant change it.

Quote
In other words, mc.X_AXIS can't be the value it's using when it actually goes to jog.
That is correct, mc.X_AXIS is of type number, I suspect its value is one, it is not a jog increment,

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #45 on: May 27, 2018, 09:38:04 AM »
Hi,

Quote
button is calling "Job X-" action, but I've searched through the screen script and that's not in there
While some buttons have 'left down' scripts for instance however others have an 'action' That action is programmed within Machs core where you cant see it or edit it,
and they're probably all in C++ anyway.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #46 on: May 27, 2018, 12:11:27 PM »
Hi,
I'm a bit confused myself.

Quote
however, it does appear to have changed the mc.X_AXIS variable because now I can read back that value using GetJogInc() and it shows me 0.001mm!
mc.X_AXIS is NOT a variable, it is an ENUM, it is the number of the X axis. Its defined within Machs core and you cant change it.

Quote
In other words, mc.X_AXIS can't be the value it's using when it actually goes to jog.
That is correct, mc.X_AXIS is of type number, I suspect its value is one, it is not a jog increment,

Craig



Ok, not well phrased. The variable that the function is directed to by mc.X_AXIS doesn't get updated. I'm trying to both set and read the jog increment variable, wherever that is, and whatever that's called, and the mc.mcJogSetInc(inst, mc.X_AXIS, 0.001) throws an error when I try to do that.

When I read back the value given by mc.mcJogGetInc(inst, mc.X_AXIS), if that happens to be say 0.001mm that's not what it jogs by.

The conclusion is that whatever is being used by the jog button to incrementally move the axis is not the value that's being read by mc.mcJogGetInc(inst, mc.X_AXIS)
Re: Using a button script to set jog increments etc
« Reply #47 on: May 27, 2018, 12:13:06 PM »
Hi,

Quote
button is calling "Job X-" action, but I've searched through the screen script and that's not in there
While some buttons have 'left down' scripts for instance however others have an 'action' That action is programmed within Machs core where you cant see it or edit it,
and they're probably all in C++ anyway.

Craig

Fair enough, so what variable is being used by that routine so that the incremental jog knows how far to move? I've read back the value from mc.mcJogGetInc(inst, mc.X_AXIS) and it doesn't match the amount it actually jogs, so it's not using whatever is being read by that function

It seems to me that what it uses is always the value that's currently being pointed to in the table that you populate in the config for the different step.

Maybe I'm using the wrong approach and I should be trying to change that variable.
« Last Edit: May 27, 2018, 12:16:23 PM by striplar »
Re: Using a button script to set jog increments etc
« Reply #48 on: May 27, 2018, 12:46:09 PM »
striplar

If you display the RegFile diagnostics, you will find entries for core/inst/JogIncX etc for the 6 axes. These are all set to the same value, as you would expect. You might like to see how these compare with the varables you are reading and writing. There are also 6 registers for the jog rates, but I have only seen these set to 0.

I initially used the values from these12  registers, but eventually abandoned that idea because their values did not always reflect what I had previously set. Sorry I have forgotTen the details.

As I said earlier, I ultimately abandoned trying to fathom out what Mach was doing and worked independently. Since then I have had no issues whatsoever with jogging. I do use the Config list as the basis from which my button names and jog increments are taken, so these can easily be changed without further coding.

It would be fascinating to see what the core actually does: I would especially like to see the logic behind Mach's state machine.

Allan
Re: Using a button script to set jog increments etc
« Reply #49 on: May 27, 2018, 12:54:48 PM »
Hi Allan,
Can you point me to where I can see the RegFile diagnostics? I don't know where to look.

It seems to me that the SetJogInc and GetJogInc aren't related to what's used when you tell the system to set the jog increment based on what's in the table. These things seem so basic, I'm stunned that all this stuff isn't sorted out and made clear. Everyone who attempts to change the way the jog works is going to go through these mental gymnastics.

Can someone close to the code answer these questions? I've posted a request to the page indicated in the Mach 4 Bug Reports thread in the hope of getting a definitive answer.
« Last Edit: May 27, 2018, 01:07:59 PM by striplar »