Hello Guest it is April 29, 2024, 08:42:58 AM

Author Topic: Jogging/Pendant Interface-What is the best way? Ramblings  (Read 39858 times)

0 Members and 1 Guest are viewing this topic.

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #40 on: May 17, 2015, 05:26:18 AM »
the answer is in the Mach4 scripting manual

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #41 on: May 17, 2015, 05:31:10 AM »
Daniellyall,

You have provided a good description of the process you want to create, so I can speak to that and provide a process for you to follow to create a solution.

Your process makes a good general example as it is a bit complicated due to the number of dependencies. Because of that, you should consider doing a flow chart as a first step and make sure you have all of the combinations accounted for.

In the coding, you will handle the dependencies with nested statements. The code fragment that I posted previously was in response to someone else's post which was quite simple and had no dependencies.

Here is a code fragment that demonstrates the solution you need:


-- ****************** JoyStick Jogging Routine *******************

  if  JoyStickActive == '1' then
      SpeedX, rc = mc.mcRegGetValue(JoyStick_X_RegHandle);
      SpeedY, rc = mc.mcRegGetValue(JoyStick_Y_RegHandle);
      --ByteZ,  rc = mc.mcRegGetValue(JoyStick_Z_RegHandle);
    if JoyJogHoldX == '0'then
     if SpeedX ~= 0 then
      IsJoggingX, rc = mc.mcJogIsJogging(inst,0)
      if SpeedX > 0 then
       DirectionX = 1;
      end


  . . . . . AND SO ON

Please keep in mind that this is a fragment and not a program.  However it demonstrates one (of several) methods that are applicable to your project. only the 'functions' that begin with 'mc.mc' are specific to MACH4. The rest is typical variables and logic.

The basic process is to first collect the data into variables and then plug those into the logic.

In the example above (which is actual code from my PLC),
'JoyStickActive' is a variable that is set 'true' if the I/O line that carries that signal is high (value of 1 or true).
'JoyJogHoldX' is 'true' if the X axis is on hold (the joystick controls all axis simultaneously, so 'disabling' one axis allows fine positioning of a single axis).
'SpeedX' is a variable that contains the desired jogging speed.
'DirectionX' is self explanatory.

In this fragment, you can see the actual code used to collect the data from MACH. Of particular interest to you would be the variable 'IsJoggingX' and how and where it gets it's value from.

So, you will create your own variables using descriptive names and use the appropriate MACH4 function to fill the variables with the date. Then arrange your nested conditional statements (if this , then do that). Finally, when all of the conditions are met, you perform the action.

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #42 on: May 17, 2015, 05:42:37 AM »
the answer is in the Mach4 scripting manual

Glad to hear you found your answer.

Hopefully other readers will still benefit from the time I spent here.
« Last Edit: May 17, 2015, 05:51:04 AM by simpson36 »

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #43 on: May 17, 2015, 05:59:50 AM »
yep thank whats in the manual is for a external switch not keyboard should of checked before I posted

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #44 on: May 27, 2015, 09:36:20 AM »
I created a pendant last night from an MPG and discrete switches. It works well, I just have a bug to resolve with the registers that I have defined in Mach4; possible race condition when flipping between Axis and Increment selections and writing the registers.

Once I get the "ok" from ArtSoft, I will post the script on both sights.

The solution requires that the MPG is defined in the ESS plugin config. and lua script code is written that responds to the MPG control signals (inputs) as define (which axis you are controlling and what increment you have selected).  The user maps the MPG to the controlled axis based upon control signals (inputs) defined in the signal code.

I believe that the ESS plugin takes care of the MPG counting up and down.   I have asked Jeff_Birt/Greg of Warp9 to verify this. ...hey, it works  ;D

I will post my script code on both sites and notes as soon as I get the "Ok" from ArtSoft.

Offline simpson36

*
  •  1,369 1,369
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #45 on: May 27, 2015, 02:34:24 PM »
Tim,

two questions, please;

1) What is a 'race condition'

2) Did you coordinate the MPG actions with the existing jog buttons? i.e. Do the screen jog buttons still function or does the user choose one or the other?

I have, or had, a completed interfacing a joystick jogging setup to MACH4 and it had not occurred to me to make sure it would coexist with the existing jog buttons. Seemed like it would be a simple matter to attend to . . . but ultimately required pretty much a complete rewrite of the joystick part of the code (which is in the PLC).

My device also has three rotary encoders (which is essentially the same interface as an MPG assuming quadrature output) but they are not for jogging and therefor do not interact with the internal jogging functions. For jogging, at least in my case, you must share the same resources with the existing system and that presented a very large challenge.

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #46 on: May 27, 2015, 03:27:55 PM »
1) When two pieces of code try to change the same variable at about the same time.  (I have changed the way I went about tracking the settings and I will test it tonight: simplified and clearer)
2) All of the screen functions still work
   a) The Jog Mode can get out of sync if you select a jog mode using the <Jog Mode> button on the screen to neither "Cont" or "Inc".  If I push the physical switch, it selects the mode depending on the state of the switch (bi-state "CONT" or "STEP") and the LEDs on the screen update accordingly to match the switch settings.  The LED on the switch is mapped to the "STEP" LED on the screen.  If  the LED on the switch is out the mode is continuous/unknown.
   b) The MPG controls the movement
   c) The MPG axis is selectable by a 5 position rotary switch (posted somewhere on this site)
      i) Each axis can have a separate MPG/Encoder (I have not tried this yet but it is do-able)
   d) The Jog Increment is selectable by a 5 position rotary switch (The switch stays in sync with the display because the display tracks the X_Axis setting)
      i) Jogging Increment can be set for each axis independently
3) I would like to graphically represent the switches on the display; similar to your joystick application... I just need more time in my day :D

Offline TimGS

*
  •  108 108
    • View Profile
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #47 on: May 27, 2015, 03:44:54 PM »
One problem I haven't been able to solve is that the <Enable/Disable> button on the screen does not stay in sync with

mc.mcCntlEnable(); call

I have even tried to manually changing the screen.  If I map the Input#0 to the button it stays in sync but I do not like that solution.
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #48 on: May 28, 2015, 08:42:06 PM »
...code (which is in the PLC)...smart. I wonder if a button script can call a function from PLC. I think maybe my looping problems stem from not writing the functions in PLC. I'll try to call PLC function from a button.

Racing conditions ... yah, I noticed that to whereas when a line of Gcode is coded in Lua and mdi executed the rest of your script has completed and you cannot perform conditions on that specific block. It's like the block is released to the interpreter and for got about by Lua which just preceeds to goto the next line of Lua code. For example mc.mcCntlMdiExecute(" whatever block"), code for some condition, wx.wxMessageBox ("Complete") -> Run. Your Gcode is still running but yet the MessageBox immediately pops up. Hence, all these timing loops everyone seems to be doing or the need for mcJogIsJogging, IsStill, etc. I would think these functions would be for deconfliction of resources but I'm noticing the need for them like 'while mc.mcJogIsJogging do some line of logging message until not mcJogIsJogging or vice versa in order to hold mcLua from advancing to the next line of code.

Tim, your out of sync jog type issue with the button vs. MPG ... try this
1. highlight the Jog Inc button in operator edit screen (mine is named 'tbutton8'
2. change the properties value to this:
    Text Up = Jog Cont
    Text Dn = Jog Step      

3. now goto the button's events where we would normally enter script and change to this: (select from predefined actions)
    Down Action = Jog Mode Step
    Up Action = Jog Mode Continuous

The button is of a toggle type. hence 'ibutton8' vs 'btnLaunchNuclearBomb' naming convention. Think of a DPDT type toggle switch where you would throw the lever to the left for jog continuous, lever in the middle is off, and lever thrown to the right is jog incremental. That is why you are seeing a three cycle rotation on two LED's on a toggle button. Just need to change the action state of the button. Super easy with the predefined actions that are their for us. Worked for me.
    
Re: Jogging/Pendant Interface-What is the best way? Ramblings
« Reply #49 on: May 28, 2015, 09:05:48 PM »
I may of gotten if backwards... I think to better visually match "your" switch just add a LED in the middle and map it to a 'nor conditional statement' ie
   jog cont (led off) --- jog cont Nor jog inc (led on) --- jog inc (led off)
now that would have to be coded, there is not a predefined action for this on a LED. It would have to be wx.Lua scripted I think to create that specific LED.
using screen calls?? output is true if = nor (wow, that almost sounds like an oxymoron)