Hello Guest it is November 20, 2019, 10:26:13 AM

Author Topic: Making MACROS turn on OUTPUTs faster by inlining your code!!  (Read 7687 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #10 on: August 10, 2014, 08:47:54 AM »
Since your Mcode are 10microseconds to fast, put a 10 ms sleep before the output call.
So change your macros to this (and adjust the Microsleep as needed if 10ms if off:

--m770 macro turns "ON" OUTPUT0
function m770() 
   wx,wxMicroSleep(10);--10ms delay 
   mc.mcSignalSetState(mc.mcSignalGetHandle(0, mc.OSIG_OUTPUT0), 1);
end
--m770()--testing;
--[[
if (mc.mcInEditor() == 1) then--leave uncommented unless in the editor
    m770();
end
--[[

-----------**********************************---------------------------------

--m771 macro turns "OFF" OUTPUT0
function m771()   
      wx,wxMicroSleep(10);--10ms delay
      mc.mcSignalSetState(mc.mcSignalGetHandle(0, mc.OSIG_OUTPUT0), 0);
end
--m771();--testing
--[[
if (mc.mcInEditor() == 1) then--leave uncommented unless in the editor
    m771();
end
--[[

Scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Online Tweakie.CNC

*
  • *
  •  8,006 8,006
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #11 on: August 10, 2014, 12:04:46 PM »
Hi Scott,

That seems to do the trick  ;)

The wxMicroSleep units are uS (not mS) and it took a delay of 50000uS to resolve the issue completely  :)

Tweakie.
Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #12 on: August 11, 2014, 02:04:11 PM »
opps........

the:  wxMilliSleep(); is milliseconds.... sorry...

scott
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/

Online Tweakie.CNC

*
  • *
  •  8,006 8,006
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #13 on: August 12, 2014, 01:43:54 AM »
Thanks Scott - I am learning as I go  ;)

Tweakie.
Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #14 on: August 13, 2014, 01:59:45 AM »
Hello!

Can you please explain, what's the concept of "inlining" (compared to the usual MCode scripting)?

Thank you,
Paul

Offline poppabear

*
  • *
  •  2,233 2,233
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #15 on: August 13, 2014, 08:55:59 AM »
it is not TRUE inlining (like in C) in where the compiler puts the function code where it is written so no call to it is made.

what was done here, was cut out some if statements and a function call. so, in theory less calls to functions and less if statements to process along the way should = more speed (in theory).

look up "inline" and C or C++ as a key word on google or some such.
Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #16 on: August 13, 2014, 09:20:16 AM »
So it means you can inline wxLua code into your G code script?

Something like that?

G1 X10 Y3.5
wx.wxMicroSleep(10);--10ms delay
mc.mcSignalSetState(mc.mcSignalGetHandle(0, mc.OSIG_OUTPUT0), 0);



Online Tweakie.CNC

*
  • *
  •  8,006 8,006
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #17 on: August 13, 2014, 12:21:13 PM »
Quote
So it means you can inline wxLua code into your G code script?

Hi FocusPaul,

No, you can't do that.

In Macro's, if they are written with the fewest number of statements (careful programming) it will reduce the number of function calls and speed up their execution time.

(In practice, as we have discovered, the Mcode call, assuming it is on a separate line, in the Gcode program is actually executed some 50 milliseconds before the CNC machine has completed the preceding line of Gcode - this has been found too early for lasers (although suitable execution time delay can be added) but for many Mcodes and indeed spindle speed changes (Scode) operating early reduces overall machine run time and makes Mach4 faster).

Tweakie. 
Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.

Offline smurph

*
  • *
  •  1,151 1,151
  • "That there... that's an RV."
    • View Profile
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #18 on: August 28, 2014, 01:30:10 AM »
Yes, they are quick!  The issue is because Mach4 doesn't know exactly when the last movement was done on the motion controller.  Mach4 holds up the M code until the last way point is sent to the motion controller.  But there is going to be some latency involved between the time the data was sent and movement actually is done.  So the physical motion always lags the as compared to the position in the G code file.  This latency is PC/motion controller specific and will be different on just about every system. 

The good news is that you can slow up the M codes with a wx.wxMilliSleep(ms) call.  If you are consistently 10ms fast, do wx.wxMilliSleep(10) in the first line of the M code.   

That is something to try, but it is not the best solution.  Eventually, we will have a facility to turn on output in coordination with motion.  We may use the LinuxCNC M62 and M63 type of thing.  It seems that there is no standard at all to follow.  Maybe if we do it like LinuxCNC does, it will "create" a standard.  Only LinuxCNC's current form doesn't go far enough, IMHO.  They only provide for turning output on or off at the beginning of a move.  It would be nice to be able to do the same at the end of a move.  Then there is CV to consider!  It all gets a bit complicated.

http://linuxcnc.org/docs/html/gcode/m-code.html#sec:M62-M65

M62 P1 (Turn output 1 on at the beginning of next move)
M63 P2 (Turn output 2 off at the beginning of next move)
G01 X1 Y1 (The movement.  Outputs 1 and 2 will be coordinated with the start of this motion.)

Steve

Online Tweakie.CNC

*
  • *
  •  8,006 8,006
  • Super Kitty
    • View Profile
    • Tweakie.CNC
Re: Making MACROS turn on OUTPUTs faster by inlining your code!!
« Reply #19 on: August 28, 2014, 01:46:11 AM »
Hi Steve,

The LinuxCNC M62P1 / M63P1 appear to operate in exactly the same way as the Mach3 M11P1 / M10P1 commands. Certainly for laser use it would be nice to have this command set within Mach4  :)

Tweakie.
Success consists of going from failure to failure without loss of enthusiasm.  Winston Churchill.