Hello Guest it is March 28, 2024, 10:53:25 AM

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

0 Members and 1 Guest are viewing this topic.

Re: Using a button script to set jog increments etc
« Reply #50 on: May 27, 2018, 02:43:16 PM »
Hi,

Quote
Everyone who attempts to change the way the jog works is going to go through these mental gymnastics.
You want to CHANGE the way it works therefore you assume responsibility for the effort.

Look under Diagnostics/Regfile...expand the various categories and have a look.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #51 on: May 27, 2018, 03:53:44 PM »
Guys, it isn't this hard!  :)  I made a video that might help. 

https://youtu.be/hISdOAVaAbM

The registers are there for external access to the current jog increment that the screen is using.  So that some plugin or external script can tell what the current increment (the screen's notion) is. 

For example, say you have a script that needs to change the jog increment and then change it back to what it was AFTER it is done.  Otherwise, those registers are not needed.  Don't use what you don't need. 

All of this can be done with mcJogGetIncr() and mcJogSetIncr().  The screen will follow these increments, as shown in the video.  And I WILL say this...  If I could learn how to use that damned video capture software and create that video, then you guys can certainly learn this LUA stuff.  I will not fib, it was frustrating.  I made several videos that were just blank screens with audio.  But guess what?  I didn't have a clue about what I was doing!  :)  Once I figured it out, and the light bulb in my head came on, it all started working as it was meant to.  Same goes for Mach. 

Steve
Re: Using a button script to set jog increments etc
« Reply #52 on: May 27, 2018, 04:13:50 PM »
Sorry guys, but it's not as simple as you are trying to make out from a position of knowledge. I've been programming in all manner of languages for forty years, I've written my own CNC control from scratch, so I' think it's fair to say that I'm not new to this lark.

The problem is that there's no joined up easy to understand way to find out about how Mach4 hangs together. I don't ask questions because I'm lazy or stupid, I ask them because they aren't obvious.

So far, I've not made any sense of how Mach4 decides what size jog increment to use, how to set that with a script and how to read it back. That's not for lack of trying, it just doesn't appear to work. Maybe I'm missing something that's blindingly obvious, but mcJogSetInc() returns an error and mcJogGetInc() doesn't return the value of the increment it's currently jogging at.

Do put me straight as to where I'm going wrong if this is all so easy?
Re: Using a button script to set jog increments etc
« Reply #53 on: May 27, 2018, 04:41:50 PM »
I can go into the Debug->RegFile and see the JogIncX variable which does follow the JogSetInc even though that returns an error, assuming the error testing is correct of course. I'm using the following suggested code...

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

... which says it's failed.

Now if I leave out the error checking, it does save and retrieve the value set, but that has NO effect on the amount it actually jogs.

As it happens, I can just use that stored information to set the colour of the Radio buttons in the PLC, but it doesn't explain why this has absolutely no effect on the jog increment it actually uses!
Re: Using a button script to set jog increments etc
« Reply #54 on: May 27, 2018, 05:05:20 PM »
I think the error is actually that I'm testing for mc.MERROR_NOERROR and not MERROR_NOERROR, so that's probably a syntax mistake.

It still doesn't resolve the fundamental issue of the JogIncX variable in the RegFile changing but having no effect on the actual amount the jog increments by when I press the X- button for example.
Re: Using a button script to set jog increments etc
« Reply #55 on: May 27, 2018, 06:22:54 PM »
striplar

As I said, I never managed to resolve the inconsistencies so I think you will have to hope Steve has some  idea.

Have you come across the mcErrorCheck.lua module in Mach4's modules directory? This lists the possible rc codes and can be handy in your scripts. For example you could use something like this:?

Code: [Select]
if (rc ~= mc.MERROR_NOERROR) then
    mc.mcCntlSetLastError(inst, "Jogging error:" .. ec[rc])
end

This would append the offending error message to the text of your choice.  so may make it easier for you to resolve any issues that arise.

To use the above, you must link in the mcErrorCheck.lua  module using a require statement, the typical code being:

Code: [Select]
----------AW Load error check module ---------------
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Modules\\?.lua;" .. path .. "\\Profiles\\" ..  profile .. "\\Modules\\?.lua;"
package.loaded.mcErrorCheck = nil
ec = require "mcErrorCheck"

This may already exist in the screen load script: if not you can safely add it.

Allan
Re: Using a button script to set jog increments etc
« Reply #56 on: May 27, 2018, 07:03:34 PM »
Hi Allan,
No, that one's new to me, I see that now. I've just tried that and it seems to work fine, so I'll put that in all of the button scripts.


Anyway, I've raised a support ticket asking for an explanation as to why the JogIncX variable set by the mcJogSetInc() function has no effect on the actual jog it does using the X- button. I mean, what's the point in having those registers if they don't do anything useful.

Although I can sort of get my code to work, I still can't set the initial conditions to whatever the true jog increment is, unless I somehow force the ScreenScript to set it initially. We know you can't use mcJogSetInc() for that, so maybe you can call the Action function that you can select from the drop down list of Actions in the button event tab?

I'm also surprised that there's no mcJogGetType. Again, there are individual Type variables for each axis, but those don't follow the Incremental/Continuous modes of the actual machine either! It's frankly bizarre.

Hopefully someone at Mach will be able to explain all of this.
 

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #57 on: May 27, 2018, 07:12:59 PM »
The problem is that there's no joined up easy to understand way to find out about how Mach4 hangs together. I don't ask questions because I'm lazy or stupid, I ask them because they aren't obvious.

So far, I've not made any sense of how Mach4 decides what size jog increment to use, how to set that with a script and how to read it back. That's not for lack of trying, it just doesn't appear to work. Maybe I'm missing something that's blindingly obvious, but mcJogSetInc() returns an error and mcJogGetInc() doesn't return the value of the increment it's currently jogging at.

Well, technically speaking, it isn't how Mach 4 hangs together, but rather how the GUI hangs together.  Mach 4 has a core that can be run by any GUI that is written using the Mach 4 API.  We ship an example GUI called wxMach.exe that is basically a static front end.  So what we are technically talking about here (now) is the functionality of the GUI.  Mach4GUI.exe is the GUI that is dynamic and can be customized.  It provides FAR more functionality than the static wxMach.exe GUI does.  For instance, there is no LUA scripting in the wxMach.exe and you can't add or change the display beyond that of any other windows program.  

So we have established that the Mach4GUI.exe provides a lot of functionality that the user needs to run a machine.  One of the functions it provides is jogging.  But it is important to note that it is a SCREEN implementation of the jog.  So the internals of the GUI keeps track of the increment in its' own container.  It calls API functions such as mcJogSetIncr() etc...  This is done per axis in the core so the GUI is actually doing something more than setting just one global increment.  It is doing it for ALL coordinated axes.  But that is not all it does.  It also keeps track of the jog mode (incremental or velocity) too.  So that when you press the jog button on the screen, it does that particular jog mode.  So there is a lot built in here.  

mcJogSetIncr() and mcJogGetIncr() are basically APIs to use to STORE and RETRIEVE a jog increment.  They don't, in fact, DO ANYTHING.  When you cycle the Jog increments in the GUI, the GUI will use mcJogSetIncr() to store the jog increment that is selected.  Mainly as a means of communication to the rest of the Mach world what increment it will use the next time an incremental jog is performed.  But it also tracks what it was told to use in its' own internal variable.  Why?  Because there may be an MPG or some other control device (panel) that has jog buttons on it.  The increments my be chosen by a buttons or some rotary knob.  Say the user has an MPG and they switch to the .001 increment.  Then they do some jogging and stuff with it and put it down.  Do they want the MPG to always control the jog increments?  Or do they want the jog increments to remain set by the device that is actually used for the current jogging activity?  Most want them separate and that is the default behavior of the screen.  

Some MPGs may only have a hand wheel and no increment switching available.  This is the reason for mcSetJogIncr().  It allows for the screen to set the increment and the increment to be retrieved by whatever is running the MPG with mcGetJogIncr().  So the GUI's stock behavior WILL update mcSetJogIncr() if you toggle the jog increments with the stock jog control buttons.  To let the rest of the Mach world know what the screen's current increment is.  mcSetJogIncr() has no other function than that.  The stock jogging implementation doesn't use mcGetJogIncr() to retrieve this increment before jogging.  It uses its' own internal variable.  So that the screen's jog increment can be different than the other devices that my be used to jog the machine.  

Now, let's take a look at the API function that the GUI (or any other thing that may be running a jog will use) uses.  Namely mcJogIncStart().

In LUA:  

number: rc = mcJogIncStart(number: inst, number: axis, number: dist)

Notice the distance parameter.  This is what drives the incremental jog's distance!  Not what was set by mcJogSetIncr().  There is no function like mcJogIncStartUsingLastSetIncr().

Mach 4 was designed so that no scripting is required to use the stock screen sets.  It is meant to cover 98% of the use cases.  One can wire up a machine to a motion controller, map the necessary I/O to signals, and run the machine from just the screen and mouse.  All of this functionality is "canned" or "shrink wrapped", if you will.  However, it also provides a means of changing the default behavior, for whatever reason.  Don't like it?  Not applicable to the task at hand?  Rather do it your own way?  All of these are valid.  But understand this:  Now the work and functionality is up to you.  So to change the jogging functionality, you will have to write your own and provide ALL of the functionality.  Fortunately, you have the tools of the API to accomplish this.  What I think you are wanting to do is do your own thing but also use the stock jog actions.  We all want to have our cake and eat it too, right?  :)

What does the stock jog functionality do?

1. Provides a jog mode variable. (incremental, velocity)
2. Provides a jog increment variable. (for the increments)
3. Provides a table of jog increments.  
4. Provides canned actions to drive the jog buttons based on the above variables. (toggle jog mode, jog an axis, toggle increments).
5. Calls mcJogSetInc() to let the rest of the world know what the screen is doing.

So all of this will need to be duplicated/provided.  Or...  you can try and use the stock functionality and merge it with yours.  HOWEVER, I do suggest that once you deviate from what is stock that you would be better off doing it all.  So that YOU know what is going on all of the time and don't get bit by some stock behavior for which you may not have accounted.  Because if you do "modify" the stock implementation, you pretty much need to know how it all works AND how to manipulate it to begin with.  That is something that is in my head and it will probably NEVER be documented because 99% of the people using Mach don't kneed to know it.  EVER.  :)  Never the less, I have attached the test file that I used in the video to show how to do what I think you are wanting to do.  But to do it right, you would need to edit all of the jog buttons, remove the stock actions, and write scripts to do all of the required functionality.  

But can you guys imagine what kind of crap would be on this board if the stock jog buttons/actions didn't exist?  I mean, it would be apocalyptic!  "You mean that I have to write LUA code to jog an axis!!!", etc...  

In the attched file, the SetJogIncrements() function now uses a screen API called scr.DoFunctionName().  You can open the screen editor and use the names of the stock button actions to get the name.  This function ONLY works with the primary instance (no instance parameter), so multiple instance controls definitely need to handle this type of thing differently.  

Steve

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #58 on: May 27, 2018, 07:41:48 PM »
I didn't remember who said it when I was writing the above post.  But this is exactly what Craig was referring to.  Luckily, most of the stuff people want to modify is less complicated than jogging.

Hi,

Quote
Everyone who attempts to change the way the jog works is going to go through these mental gymnastics.
You want to CHANGE the way it works therefore you assume responsibility for the effort.

Look under Diagnostics/Regfile...expand the various categories and have a look.

Craig

The only mental gymnastic one has to go through is to understand this point.  And don't assume that there is a one line function call that will do what you want either.  Sometimes, that is the case though!  :)  But the stock jog actions use numerous API functions behind the scenes to give the functionality that is does. 

Developing something that works the way you want it to may not be easy.  It may require learning something and it may take a while to learn it.  And that is why this forum exists, to help people learn.  Learning is something we all can do.  Some consider it a chore while others consider it an adventure.  A lot of the time this involves some amount of experimentation.  At least that is what I tell myself that I was doing when I stuck my fingers into a light socket as a kid.  :)

Steve

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #59 on: May 27, 2018, 08:41:15 PM »
New video:  https://youtu.be/dtEKxEudc8M

Striplar, turns out this is easy!  But...  there is a bug.  I guess nobody had tried to use this stuff before.  You are definitely a %1-er!  LOL  The bug will be fixed in the next development version.  Until then, use the method in the Test.mcs file or the new SetJogIncrements() in the video. 

Steve