Hello Guest it is October 19, 2019, 11:29:51 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Using a button script to set jog increments etc
« Reply #60 on: May 28, 2018, 08:33:21 AM »
Steve

Thanks for the insights given in the two videos. I now see that mcJogSetInc() and mcJogSetRate(), which I took out of my code thinking they seemed to serve no obvious purpose, do fulfil a potential need. Another hitherto invisible gem is scr.DoFunctionName(), which obviates the (rare) temptation to have a hidden button operated by (e.g.) scr.ButtonUp() which itself can have side effects such as transfer of focus, just to make a script take an action.

I think I'll take another look at my own jogging code to see if I might make any changes  some 6 months after it was written. A key objective, though, was to avoid any surprise switches from metric to Imperial units, so I will continue to disregard any internal increment values.

I do appreciate your giving the time to clarify some of the considerable mystique we users find in the inner workings of Mach4.

Allan
Re: Using a button script to set jog increments etc
« Reply #61 on: May 28, 2018, 11:20:14 AM »
Hi Steve,

This is a copy of the comment I left on the video which I'm grateful for.

Actually, I've been using the same method ie I've used the left down action to change the mode from Continous to Incremental and the up action to set the Joc increment like you've showed. I did mention this in one of my many posts, but you may have missed it.

I'm glad you agree that the internal system should at the very least change the JogIncX value so you can read it using the mcJogGetInc() function elsewhere. This is how I would set radio button colours in a PLC routine.

However, that's not quite enough though, because you don't know the initial condition on startup. I think this is another bug. I think the core should update the JogIncX value etc to whatever the Jog Increment actually is when you fire up Mach4.
You don't address this issue in the video. You assume what the default increment will be.

I also notice that the JogTypeX variable also don't follow the Button Jog Mode on the screen and also don't appear to be initialised to whatever Mach4 core is going to use. Those appear to be scripted, but again, I would have thought that Mach4 core would update those to whatever the current mode is.

I'd suggest that the reason people don't use these functions is not because they don't want to, but when they experiment, they simply find that it doesn't work how they might reasonably expect.
At the very least you expect to be able to ask Mach4 what incerement it's using and what mode it's in.

Also, I would have thought that the actions, such as Jog Inc.3 would be able to be called from scripts. Maybe you can, but if not, why not? It would be so useful when you want to do seveal of these options.

Anyway, thanks for looking at this, maybe you can look at these other things too?
Re: Using a button script to set jog increments etc
« Reply #62 on: May 28, 2018, 02:40:45 PM »

Quote
when they experiment, they simply find that it doesn't work how they might reasonably expect.

Agreed, but I tend to accept Mach4 for what it is, powerful yet amazingly good value, and use the flexible scripting to make it work as I would wish. It can be a challenge but to me that is part of the fun.

Allan
Re: Using a button script to set jog increments etc
« Reply #63 on: May 28, 2018, 03:12:49 PM »

Quote
when they experiment, they simply find that it doesn't work how they might reasonably expect.

Agreed, but I tend to accept Mach4 for what it is, powerful yet amazingly good value, and use the flexible scripting to make it work as I would wish. It can be a challenge but to me that is part of the fun.

Allan

Agreed, it's a lot of fun playing when it makes sense. I don't mind going the extra mile to figure out how to make it do what I want. It's just frustrating when it's actually a bug that's been causing so much grief! such is life.

Anyway, here's my solution to the RadioButton type of interface that seems to work ok now.
This function is written in the SreenScript and called in the PLC loop.

Each increment button uses a Left Down Action of Jog Node Step and a Left Up Action of Jog Inc. 3 for example. There's also a Left Up script as follows...

--Set JogIncX variable using mcJogSetInc() and test it using a call
--from the PLC script to set the radio button colours
--For some reason this has no effect on the actual jog amount which is
--set from the UpAction event for this button
local inst = mc.mcGetInstance()
local rc

rc = mc.mcJogSetInc(inst, mc.X_AXIS, 0.01)

....We now know that this shouldn't have been necessary, the GUI should have done that for us.

----------------------------------------------------------------------------
--   Handle the radio button action of the Jog increment buttons - My code!
----------------------------------------------------------------------------
function UpdateJogRadioButtons()
--currentInc = 0 -- my global var to track the current increment is defined above
--currentMode = -1 -- my global var to track current mode is defined above
local increment
local rc

--See if we're in continous or incremental jog mode first
local cont = mc.mcSignalGetHandle(inst, mc.OSIG_JOG_CONT);
local jogcont = mc.mcSignalGetState(cont)

if (jogcont ~= currentMode) then   --so it's not done every loop
   --mc.mcCntlSetLastError(inst, "jogcont=" .. tostring(jogcont)); --debug only
   if (jogcont==1) then --continuous
      scr.SetProperty("btnContinuousMode", "Bg Color", "Green");--"ControlName", "PropertyName", "Value"
      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", "");--"ControlName", "PropertyName", "Value"
   end
   currentMode = jogcont   --so we don't update every time
end
if (jogcont==0) then   --incremental
   scr.SetProperty("btnContinuousMode", "Bg Color", "");--"ControlName", "PropertyName", "Value"

   --NB:-The following gets the value set by the buttons, it has no effect on the actual jog amount!
   increment, rc = mc.mcJogGetInc(inst, mc.X_AXIS)   --You can see the value JogIncX in the Debug_RegFile

   if (increment ~= currentInc) then   --so we don't unnecessarily update anything
   
      if (increment == 1) then
         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
         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
      
      currentInc = increment   --remember what the new increment is
   end
end   
end

So this is pretty simple now really. I've tested the Continuous mode signal that's used elsewhere to decide whether to blank out the incremental buttons.

It's a fantastic piece of software, but I'm famous for breaking things and finding bugs that have lain dormant for years. I'm dogged an won't just give up because it doesn't make sense.

Anyway, hopefully others will be able to do this easily now all this has been thoroughly aired.

Many thanks to all who've contributed, it's been an enormous help. I'm now going to tackle the MDI box to make that less dangerous.
« Last Edit: May 28, 2018, 03:17:00 PM by striplar »
Re: Using a button script to set jog increments etc
« Reply #64 on: May 28, 2018, 03:58:54 PM »

striplar

Quote
I originally did this without scripts but found there's a bug that occasionally moves 1" instead of 1mm!!!

Maybe I've lost you somewhere, but how did you avoid your problem with unexpectedly changing units?

Allan
Re: Using a button script to set jog increments etc
« Reply #65 on: May 28, 2018, 05:02:46 PM »

striplar

Quote
I originally did this without scripts but found there's a bug that occasionally moves 1" instead of 1mm!!!

Maybe I've lost you somewhere, but how did you avoid your problem with unexpectedly changing units?

Allan


This only seems to be an issue if you play around with the Config settings and then continue without restarting Mach 4 from Windows. I haven't seen an issue when I've started Mach 4 from scratch. Is that the situation that you found?
Re: Using a button script to set jog increments etc
« Reply #66 on: May 28, 2018, 05:40:05 PM »
striplar

Yes, I definitely saw it after a config change, though it took me a while to link the two, by which time I had decided to eliminate it as it struck me as pretty hazardous.. I was by then working on a way of using a set of direct access buttons, so combined the two objectives.

Allan
« Last Edit: May 28, 2018, 05:42:14 PM by Fledermaus »
Re: Using a button script to set jog increments etc
« Reply #67 on: May 28, 2018, 07:07:40 PM »
striplar

Yes, I definitely saw it after a config change, though it took me a while to link the two, by which time I had decided to eliminate it as it struck me as pretty hazardous.. I was by then working on a way of using a set of direct access buttons, so combined the two objectives.

Allan

Fair enough, I'll keep a close eye on it to see whether it's a problem that will recur. There must be a way to force Metric mode that could be included in the script. I know you can execute G-Code like this...

mc.mcCntlMdiExecute(inst, "G21")

... so perhaps that's all that's needed as a button script for each of the buttons

Actually, that would get executed after the move, so it would probably be necessary to call the X- button functions in the script first. They are currently done by actions selected from the drop down menu in the Mach Mill screen.

Perhaps something like this...

mc.mcCntlMdiExecute(inst, "G21") --force it to metric first
local inst = mc.mcGetInstance()
scr.DoFunctionName("Jog X-")  --then do the jog

Obviously you could get the Inch/Metric information from the ini file and make it to suit if you wanted a more general solution. This still only works for the screen buttons though, an MPG could still cause trouble.

Alternatively, maybe there's a function that's called on exit from doing a config? Or, maybe there's a flag that we can test to see what mode it's in and throw an error if it's not Metric

Or finally, perhaps someone at Mach might take this bug seriously and fix it!


« Last Edit: May 28, 2018, 07:23:45 PM by striplar »

Offline smurph

*
  • *
  •  1,138 1,138
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #68 on: May 28, 2018, 07:24:44 PM »
rc = mc.mcJogSetUnitsMode(inst, axis, mc.MC_UNITS_METRIC || mc.MC_UNITS_INCH);

Also,

unitsMode, rc = mc.mcJogSetUnitsMode(inst, axis)

The mode of the machine may override it.  Meaning if you called mcJogSetUnits() to set the jogs to metric and then executed G20 in G code, the jogs will be in inches.  And vice verse. 

Steve
« Last Edit: May 28, 2018, 07:29:39 PM by smurph »

Offline smurph

*
  • *
  •  1,138 1,138
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #69 on: May 28, 2018, 07:46:09 PM »
Or finally, perhaps someone at Mach might take this bug seriously and fix it!

It isn't a bug.  I explained in a earlier post that the jog units will follow the machine units mode.  The jogging USED to be ONLY in machine native units.  But we got so many support tickets about that so we made it follow the units mode.  Damned if we do and damned if we don't...

Steve