Hello Guest it is April 18, 2024, 07:41:03 PM

Author Topic: how to press a button within a script  (Read 1494 times)

0 Members and 1 Guest are viewing this topic.

how to press a button within a script
« on: May 15, 2019, 08:53:08 PM »
Newbie to mach4 coding here, sorry :-\

What function can I use to actuate one of the jogging buttons: x+,x-,y+,y-,z+,z- as if I was using the mouse but from within a script?
Thanks,
Gaston
 
 
Re: Mach4: how to press the screen Jog x+ button from within a script
« Reply #1 on: May 16, 2019, 01:27:54 PM »
Same message, just made the object a bit more significant if that can help.
Re: how to press a button within a script
« Reply #2 on: May 16, 2019, 02:04:30 PM »
Hi,
not quite sure what you mean...'from within a script'?

If you are running a Gcode job and you call a macro. m100 say. Is this what you mean 'while running a script'?
If so the motion planner is under control of the Gcode interpreter and you can't jog.

To my knowledge Mach has always been this way.....you can run code OR you can jog but you can't do both at once.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: how to press a button within a script
« Reply #3 on: May 16, 2019, 02:28:23 PM »
Thanks Craig, let see if this makes more sens.
I am writing a script to control Mach4 with a Xbox360 device. If that matter, the screen set used is Wx4. The Xbox360 plugin is written by DasTheGas.
https://www.machsupport.com/forum/index.php?topic=33121.50

My goal is to use the jogging screen as it is but actuate the jogging buttons: x+,x-,y+,y-,z+,z- with the controls of the xbox360.
I have not found a function to simply press and release a screen button like X+

Any thought on how this can be done or simply a function mc.mc??? or a snippet of code to achieve this?

Thanks for your help,
Gaston

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: how to press a button within a script
« Reply #4 on: May 16, 2019, 02:32:18 PM »
You really DON'T want to press a button with a script call.  Why?  M code scripts don't natively have access to the screen.  And the script to press a button paradigm was more of a Mach 3 thing.

What you want to do is DUPLICATE the functionality of the button in script.  You do this with the Mach API.  For example, mcJogVelocityStart/Stop will do what pressing the X jog button does, etc...

Steve
Re: how to press a button within a script
« Reply #5 on: May 16, 2019, 03:02:57 PM »
Is this is what you mean?
   Yval=GetXin("LTH_Y_Val")

   if  Yval > 25  or Yval < -25  then
      if Yval >25 then
         mcJogVelocityStart(mInst,mc.Y_AXIS,MC_JOG_POS)
      else
         mcJogVelocityStart(mInst,mc.Y_AXIS,MC_JOG_NEG)
      end   
   else
      mcJogVelocityStart(mInst,mc.Y_AXIS,MC_JOG_STOP)
   end

Something must be missing, nothing moves.

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: how to press a button within a script
« Reply #6 on: May 16, 2019, 04:48:57 PM »
I have no idea where GetXin() comes from.  :(

What is mInst?  Typically the instance is garnered with:

local mInst = mc.GetInstance('my function')

And it is usually going in a function. 

Code: [Select]
function JogAxis(axis, direction)
    local inst = mc.mcGetInstance('My JogAxis Function') -- just a label so that API tracing works. 
    if (direction > mc.MC_JOG_STOP) then
        mcJogVelocityStart(inst, axis, mc.MC_JOG_POS)
    elseif (direction < mc.MC_JOG_STOP) then
        mcJogVelocityStart(inst, axis, mc.MC_JOG_NEG)
    else
        mcJogVelocityStop(inst, axis)
    end
end

And to call that function to jog the Y axis:

Code: [Select]
JogAxis(mc.Y_AXIS, mc.MC_JOG_POS) --Jog positive
...
JogAxis(mc.Y_AXIS, mc.MC_JOG_STOP) -- Stop the positive jog

JogAxis(mc.Y_AXIS, mc.MC_JOG_NEG) --Jog negative
...
JogAxis(mc.Y_AXIS, mc.MC_JOG_STOP) -- Stop the negative jog

Steve

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: how to press a button within a script
« Reply #7 on: May 17, 2019, 08:01:56 AM »
Quote
I have no idea where GetXin() comes from.  :(

GetXin() is a function I included with the examples for the Lua version of XBox Controller, so unless you are running the plugin for the controller etc that will not work.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: how to press a button within a script
« Reply #8 on: May 17, 2019, 02:47:57 PM »
Yes, I am using DazTheGas's XBox controller example as the basis for getting acquainted with mach4 programming. Thanks DazTheGas for you very useful video on this.

Steve, you code snippet is promising. I think get the idea .

At this time I can write the script and incorporate it in the screen.  But I have some errors and I need to run in debug mode with the xbox connected.

I could certainly appreciate some pointers on how to do this as I did not have much success so far.

Thanks for you help,
Gaston