CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
February 19, 2020, 14:16:19 pm


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Writing a post processor for laser engraving - how to start?  (Read 159 times)
UKFlyer
CNC Ewok
*
Offline Offline

Posts: 5


View Profile
« on: February 15, 2020, 12:59:04 pm »

I've set up a laser on my CNC router and built and wired a homemade constant current driver with PWM support. My Mach2 USB I/F board does not support M11Px/M10Px so I am using the A axis to control the laser on/off

Any move of A in the minus direction turns on the laser but only for the duration of the move. Moves of A in the positive direction leave the laser off.

If I use the MACH3-laser post processor I get the M11 and M10 commands indicating when the laser should be on or off and these can define the blocks of commands that need an appropriate A move appending.

So I want to post process the Cambam output to remove M11/M10 and then for each line add an A move as appropriate. How do I start?

I'm an experienced C programmer but not C#, VB or any of the more modern OO variants. I could just create a standalone program to do what I want but would prefer to integrate with Cambam. Can anyone point me at the relevant documentation of how to create a post processor and is there any sort of pro-forma project?

Thanks

Peter
Logged
EddyCurrent
CNC Jedi
*****
Online Online

Posts: 4143



View Profile
« Reply #1 on: February 15, 2020, 13:02:34 pm »

Did you use the search box at top right of the forum home page ?
If not, enter this, "laser post" and you should get some useful hits.

Please ask again if more help is required though.
Logged

Made in England
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8136



View Profile
« Reply #2 on: February 15, 2020, 13:05:30 pm »

Peter,
Buy all means, write it in C, if that's what you're comfortable with.  You may then call the routine from your Mach3 post-processor by adding a "post-build command" near the end.  It can accept command-line arguments so that you can pass things like the file-name to your command.

Look up the term "post-build command" in this forum for more info on how to invoke it.

I find programmers get more out of the process by writing their own than they do by having someone else do it for them.

Lloyd
« Last Edit: February 15, 2020, 13:07:27 pm by lloydsp » Logged

"Pyro for Fun and Profit for More Than Fifty Years"
dh42
Administrator
CNC Jedi
*****
Offline Offline

Posts: 5752



View Profile WWW
« Reply #3 on: February 15, 2020, 14:07:03 pm »

Hello

The M10/M11 are defined in the "Start Cut" and "End Cut" properties of the laser post processor. Go to the system tab, select the laser post processor, then you can edit those properties just by clicking on the |...| button that appears when you select one of these properties.

++
David
Logged
UKFlyer
CNC Ewok
*
Offline Offline

Posts: 5


View Profile
« Reply #4 on: February 15, 2020, 14:45:15 pm »

Editing the properties isn't the issue (I don't think but I'm stumbling in the dark here :-))

Assume my current G-code has the statements

G3 F800.0 X10.957 Y2.1055 I2.4962 J-0.1721
G3 X10.9925 Y1.554 I3.829 J-0.0304
G3 X11.0509 Y1.2825 I1.9589 J0.279

When engraving I need to turn these into

G3 F800.0 A-0.1 X10.957 Y2.1055 I2.4962 J-0.1721
G3 X10.9925 A-0.2 Y1.554 I3.829 J-0.0304
G3 X11.0509 A-0.3 Y1.2825 I1.9589 J0.279

i.e. I need a negative move on the A axis to turn on the laser during the G3 move. I'm using the A direction bit to trigger the laser. This gets round all delays with M3/M5 and overcomes the fact my I/F doesn't support M11/M10. Note that each move needs to keep A moving negative so my code has to keep a check on A and then decrement it whenever the laser should be on.


Basic pseudocode for what I need below. This is tested and does what I want. I just need to integrate it with the post-processor.
Together your comment and that from LLoyd have given me the clue where to look - thanks. I'll report back success or not.


option explicit
option default none
open "D:\Dropbox\dis\Untitled.nc" for input as #1
KILL "D:\Dropbox\dis\Untitled.nc1"
open "D:\Dropbox\dis\Untitled.nc1" for output as #2
dim ac!=0, ad%=1 ' current A position and direction
dim s$,n$,t$, r$, i$
do
  line input #1,s$
  if s$="G17" then print #2,"M3"
  t$=left$(s$,3)
  r$=right$(s$,len(s$)-3)
  if s$="M30" then print #2,"G92 A0"
  if s$="M10P1" then
   ad%=1
   s$="( "+s$+" )"
  endif
  if s$="M11P1" then
   ad%=-1
   s$="( "+s$+" )"
  endif
  if t$="G0 " OR t$="G1 " OR t$="G2 " OR t$="G3 " then
    If ad%=1 then
      ac!=ac!+0.1
    else
      ac!=ac!-0.1
    endif
    if ac! > -0.05 and ac!<0.05 then ac!=0
    i$="A="+str$(ac!)+" "
    n$=t$+i$+r$
  else
    n$=s$
  endif
  print #2,n$
  loop while not eof(#1)
close #1
close #2



Logged
UKFlyer
CNC Ewok
*
Offline Offline

Posts: 5


View Profile
« Reply #5 on: February 15, 2020, 15:28:39 pm »

IT WORKS :-)

I'm using MMBasic for DOS as it is so easy for this sort of thing.

Post build command set to point to the MMBasic interpreter executable on my system:
Quote
D:\Dropbox\dis\MMBasic.exe
Post build command args set to point to the Basic program:
Quote
"D:\dropbox\dis\postproc.bas" {$outfile}

Final version of the program

Code:
option explicit
option default none
dim c$=MM.CMDLINE$ ' get the command line
dim p%=instr(2,c$,chr$(34))+1 'find the second double quote character
c$=right$(c$,len(c$)-p%) ' strip out the name of the basic program leaving {$output}
open c$ for input as #1  'open the original .nc
open c$+"1" for output as #2 'open the new .nc for write
dim ac!=0, ad%=1 ' current A position and direction
dim s$,n$,t$, r$, i$
do
  line input #1,s$ 'read in a line of the original
  if s$="G17" then print #2,"M3" 'We need a dummy M3 to arm the laser
  t$=left$(s$,3) 'split up the line for parsing
  r$=right$(s$,len(s$)-3)
  if s$="M30" then print #2,"G92 A0" 'At the end of the program zero the A axis
  if s$="M10P1" then 'Whenever we see a M10 command set the laser off direction and comment out the command
   ad%=1
   s$="( "+s$+" )"
  endif
  if s$="M11P1" then 'Whenever we see a M11 command set the laser on direction and comment out the command
   ad%=-1
   s$="( "+s$+" )"
  endif
  if t$="G0 " OR t$="G1 " OR t$="G2 " OR t$="G3 " then 'Check for a move command
    If ad%=1 then 'if laser should be off the move A positive
      ac!=ac!+0.1
    else
      ac!=ac!-0.1 'if laser should be on the move A positive
    endif
    if ac! > -0.05 and ac!<0.05 then ac!=0 'get rid of floating point rounding errors
    i$="A"+str$(ac!)+" "
    n$=t$+i$+r$ ' include the A move in the command
  else
    n$=s$ 'Copy other lines without change
  endif
  print #2,n$ 'Output the G-code line
  loop while not eof(#1) 'Do this until the end of the file
close #1
close #2
quit 'exit MMBasic


« Last Edit: February 15, 2020, 15:35:15 pm by UKFlyer » Logged
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 8136



View Profile
« Reply #6 on: February 15, 2020, 17:06:29 pm »

Wow!  That was fast!

Welcome to the 'Post-Build Processor Guild'!!!   Grin

Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.136 seconds with 19 queries.

Copyright © 2018 HexRay Ltd. | Sitemap