Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Pedio on December 18, 2015, 09:02:15 PM

Title: Add a laser to my CNC
Post by: Pedio on December 18, 2015, 09:02:15 PM
This is probably a stupid question  ::)

How do I add a laser to my existing CNC. More specifically how do I activate the laser? I thought about doing it with a micro switch and when the Z axis reaches a certain point it provides power. I have a 12V light on the router head that is connected to a jack. I could use this. I am sure there is a more elegant way of doing this in Mach 4.
Title: Re: Add a laser to my CNC
Post by: Tweakie.CNC on December 19, 2015, 02:07:13 AM
Within Mach4 two very special commands (which do not have any noticable delay) have been added to switch lasers (and other fast acting devices). These commands switch an Output# of your choice which you have mapped to an output pin number (to provide the actual signal output).
The Mach4 command M62P1 will switch on Output#1 and the command M63P1 will switch off Output#1. Both of these commands need to be followed by an axis (any axis) movement (because activation only occurs at the instant of initial axis movement).
There are other methods and the following short video was made (before the M62/M63 commands had been written into Mach4) using the A axis direction pin for laser switching. My Gcode included the command A0.01 to turn the laser on and A0.00 to turn the laser off. My laser output power was varied between cutting and engraving toolpaths using the spindle speed S### commands.

https://youtu.be/8fUg6ebWut0 (https://youtu.be/8fUg6ebWut0)

Tweakie.
Title: Re: Add a laser to my CNC
Post by: Pedio on December 19, 2015, 10:21:17 AM
I use Vcarve pro for my CAD and toolpaths. I will see if they have an A axis for laser on. I guess I would need a relay to go from 5V on an output to 12V for the laser. I do have extra outputs on my PMDX board that I could use.
Title: Re: Add a laser to my CNC
Post by: Tweakie.CNC on December 19, 2015, 11:02:26 AM
Your laser would be switched on/off using a TTL signal (5volts or 3.3volts) not sure why you would want to use a relay.
Modifying your Vectric post-processor to replace any Z axis movements with a small A axis movement would seem the easiest way to use the A axis direction signal as the laser trigger.

Tweakie.
Title: Re: Add a laser to my CNC
Post by: Steve Stallings on December 19, 2015, 11:18:28 AM
Most small diode lasers have an input that is designed to take a PWM signal to turn
the laser on and also to control its power level. This input will take a logic level
signal and the main power input is left on continuously. Your breakout board most
likely has some outputs that are logic level that you can use to control the laser
in this way.

I don't know about configuring Vectric, but the most sensible way to configure
Mach4 is to use the spindle controls for the laser. M3 and M5 would turn the laser
on and off while the S word would control the PWM to set the power level.

The above will result in "exact stop" operation with the motion being planned
to come to a complete stop before the M3 or M5 turns the laser on or off.

Mach4 does have provision for some special M codes to turn a signal on or off
without stopping but you may not be able to use these because, first they
do not allow for PWM to control power level, and second, most controllers
do not yet support these codes. This is true for the PMDX SmartBOBs.
Title: Re: Add a laser to my CNC
Post by: Pedio on December 19, 2015, 09:06:06 PM
I was thinking about adding this one http://3dsupplysource.com/L-Cheapo
Title: Re: Add a laser to my CNC
Post by: Steve Stallings on December 19, 2015, 09:33:49 PM
OK, this guy does NOT have a logic level ON/OFF signal, so you will
need to use a relay or an electronic switch that can handle the 1.77
amperes that it is designed to draw.

With a relay you will not be able to modulate the power level, nor
switch it fast enough to do raster style engraving. You can adapt
to the power level by controlling your motion speed.
Title: Re: Add a laser to my CNC
Post by: Pedio on December 19, 2015, 10:06:55 PM
They have a newer version http://3dsupplysource.com/L-CheapoV3
Title: Re: Add a laser to my CNC
Post by: Steve Stallings on December 19, 2015, 10:13:32 PM
Their newer units seem to simply offer higher power, but still require
the input power to be switched. Other than lacking a power level
adjustment, this will still work fine for simple vector cutting.
Title: Re: Add a laser to my CNC
Post by: Pedio on December 20, 2015, 07:56:01 AM
Steve - the write up stated "Both the Mark 2 and the Mark 3 are now available with an optional PWM connector that lets you control the output via any logic-level pin, from 15% to 100% (if for some reason, such as engraving grasycale images, you need less laser power)."

Would that work with the PMDX-407 on a PMDX-410 board?

Not sure how I would get this to work with V-carve Pro yet without having to manually edit the Gcode. I did notice they have a couple of laser post processors. Perhaps one of these will work.
Title: Re: Add a laser to my CNC
Post by: Steve Stallings on December 20, 2015, 11:21:09 AM
Sorry, I missed the optional PWM connector.

If you have a PWM input, you do not need a PMDX-407, just configure
the spindle output in our plug-in to output on pin 14 or pin 16 and
feed that to the PWM input of the laser.

You will still need a 12 VDC power source for the laser and the negative
side of that power source must also connect to the GND on the
PMDX-410 so that the PMDX-410 and the laser share a ground
reference.



Title: Re: Add a laser to my CNC
Post by: Pedio on December 20, 2015, 10:05:50 PM
Perhaps this is too much 'inside baseball' for this forum; however, I have to ask because I have #$%#@@% stuff up with bad grounds. To my defense who knew that electricity flows from the negative to the positive! They should put this in a book somewhere...     ::)

Ok - Can I connect the grounds for my PMDX-410 together with my power supply that drives a lot of ancillary items? I have a power supply that was scavenged out of an old PC that drives fans, digital thermometer, LED light on the router, etc. It has 12V running to the router to drive the LED that illuminates the area under the router. The LED is puugged into a nice DC connector on the head. It would be easy to take the 12V connector out and plug in a connector for the laser. I could then strap the grounds of the PMDX 132 and the scavenged power supply together. This would give me my ground for the PWM connection.

If I have offended the spirits of Watt and Volt please let me know...

One day I am going to understand this enough to be able to work on an old MG.
Title: Re: Add a laser to my CNC
Post by: Steve Stallings on December 21, 2015, 03:02:31 AM
OK, settle in for a long post. Taking this from the top.....

For a typical CNC machine there may be many different "grounds".

The first is the safety ground. It starts as the ground wire that comes
to the machine through the mains power cord and should be connected to
the frame and cabinetry of the machine. When other considerations tempt
you to not ground the frame to the mains safety ground, think again.
Safety is the most important thing. Your computer, unless it is a laptop
or tablet, will also connect to this safety ground.

The next ground is the signal ground used by signals coming out of the
USB and parallel ports of the host computer. This ground is necessary
for the interface to "look" at the signals.

Desktop computers internally connect the safety ground to the signal ground
of USB ports and parallel ports. This is where problems can arise from ground
loops when the safety ground of the machine and the safety ground of the host
compute are not at the same voltage potential. This can happen when other
devices on the mains circuit are causing current to flow in the safety ground
wires of their mains connection. In industrial settings this can be tens of
volts sometimes. When the USB or parallel port cable is connected to the host
computer, and the signal ground at the machine is also connected to the
safety ground, then the ground wire in the USB or parallel port cable will
try to short these two grounds together and current will flow through
the ground of the cable. This is called a ground loop and it is not a good
thing.

The first step in avoiding ground loops is to power the host computer
from the same outlet or power strip as the machine. This will minimize the
magnitude of any voltage offset between the grounds. The next step is
to use an interface design that electrically isolates the signal ground of
the host computer from the safety ground of the machine. Low cost
interfaces such as the SmartBOB USB do NOT provide this isolation so
the quality of the safety ground wiring becomes more important.

Ground loops can also be avoided by using interfaces with isolation. This
can take the form of isolation on the host port side, or isolation on the
machine signal side. Sometimes both are utilized.

Isolation on the host port side can be implemented via Ethernet connections
which are, by design, isolated by a signal transformer. Isolation can also be
provided by special versions of the USB port on the controller or by an
isolation device in the cable between the controller and the host computer.

Isolation on the machine side can be provided by devices such as opto-isolators
and/or by simply avoiding connections between the machine interface signal
ground and the safety ground of the machine. It is common for axis motor
drivers to internally provide opto-isolation of their Step and Direction
signals. Geckodrive, Leadshine, and most packaged stepper and servo drives
do this. For low cost interfaces that do not have isolation circuits for the
machine control and status signals typically extend this concept by not making
connections between the control signals and the machine frame. This can be as
simple as not grounding limit switches and sensors to the frame of the machine,
and by using mechanical or solid state relays on output signals. When doing
this it becomes important that power sources for the sensors or relays are
also not grounded to the machine frame.

You mentioned that you are using a PMDX-132, and it provides opto-isolated
inputs for limit switches and sensors. This will allow you to connect the
ground side of these sensor inputs to the machine frame if necessary, but
without any special reason to do so, I would not.

When using axis motor drivers with isolated Step and Direction signals the
negative side of the power to the drivers can usually be connected to the
frame of the machine as long as that power supply is not powering anything
else such as sensors that connect to non-isolated inputs on the controller.
It is common to connect the negative side of this power supply to the frame
ground as it will often reduce the level of electrical noise radiated from
the motor wiring. Do not do this if your axis motor drivers do not have
isolated Step and Direction inputs.

In your case, you mention that have a PMDX-132 for mounting your axis motor
drivers. The DC power connections to it go only to the Gecko motor drivers which
have opto-isolators for the Step and Direction signals. The power supply going
to the PMDX-132s motor power connector can safely have its negative side tied
to frame ground of the machine as long as nothing else powered by it has a
grounding conflict.

Again, in your case, you mentioned a scavenged PC power supply being used for
accessory power. This power supply will, by design, have its safety ground
and the negative side of its outputs internally connected together.

Your proposed ElCheapo laser vendor does not document how the PWM interface
is implemented, but it is likely that the PWM signal uses the same ground
reference as the power input. This in combination with the scavenged power
supply having its negative side tied to safety ground means that whatever
drives the PWM input of the laser will also get its signal ground tied to
safety ground through the lasers power supply. In the specific case of the
PMDX-132, the logic level control outputs are opto-isolated from the host
computer port, but share a ground with the limit and home signal inputs.
This means that you should be able to safely connect the negative side of your
scavenged power supply to the ground of the J9 output signal connector of the
PMDX-132. This analysis applies ONLY to the PMDX-132 and is not valid for
other boards or to the PMDX-410's direct outputs. You must use the J9
connector on the PMDX-132.

I know this was a long description, but I hate giving a simple answer without
explaining the reasons for it.
Title: Re: Add a laser to my CNC
Post by: Pedio on December 21, 2015, 09:22:18 AM
Thanks - I have had ground problems before and I have figured out it is not an easy problem.

I will let you know how the L-Cheapo works.
Title: Re: Add a laser to my CNC
Post by: Pedio on January 30, 2016, 09:28:22 PM
I got the laser working on my machine today. As Steve suggested I used the spindle control to activate the laser PWM. The only downside is the laser stays on even when making rapid moves. Since it moves the focal length with the Z axis movement it may not be a big problem. So far I have drawn shapes and have not played with complex patterns. Will try more tomorrow - stand by.
Title: Re: Add a laser to my CNC
Post by: Tweakie.CNC on January 31, 2016, 05:30:18 AM
I am following your progress and will be most interested to learn how you get on with changing the S#### (and thus the PWM) to switch your laser beam on / off.  In Mach3 the command is certainly far too slow but it is many times faster in Mach4 and it may work well.

Tweakie.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 01, 2016, 11:24:38 AM
Yea - I got the laser to work!!! Right now I am using the normal post processor for Vcarve Pro so it turns on the spindle at the beginning and turns it off at the end. This causes light tails between the toolpaths when a rapid move occurs. On wood it can be sanded off easily. Today I will try to edit my post processor to turn on an off the spindle when the Z axis goes down and up. I will see if this is fast enough.

The engraving on the cutting board was done at a feedrate of 5 i/s and a rapid of 150 i/s. The Z axis was set at .05" with a plunge rate of 150 i/s. I used ramps to start each line so it did not put a little black dot at the beginning of the line. The engraving is on a bamboo cutting board that was purchased at Publix. The engraving is deep enough to feel with your fingernail.  So far I am pleased with the elCheapo laser. I purchased the v3.0 laser that has 3W of power and PWM control of the laser.

I will post something if I get my post processor to work to turn on and off the laser.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 01, 2016, 04:49:55 PM
Yeaaaaa - I got the post processor for Vcarve Pro working for my laser. I added a spindle start (m03) before any feed type moves and spindle stop (M05) before a rapid move. I also added a M05 to the header and footer just in case. I guess it is possible for the file to end up at the home point and not engage a rapid move therefore leaving the laser on.

Disclaimer - use this at your own risk.

Here is the code - You need to copy down to the % mark. I had to put this post in as a quote so the forum did not look at some of the code as code for formatting the post.

Code: [Select]
+================================================
+                                               
+ Mach2/3 - Vectric machine output configuration file   
+                                               
+================================================
+                                               
+ History                                       
+                                               
+ Who      When       What                         
+ ======== ========== ===========================
+ Tony     15/11/2005 Written
+ Tony     06/01/2006 Added ATC option   
+ Tony     14/05/2006 Fixed G20 inch in header   
+ Tony     24/07/2006 Added G2 & G3 Arc support + removed (( ))
+ Tony     18/06/2007 Replaced the Tool comment       
+ Mark     14/08/2008 Added G1 to Feed moves, added New_Segment
+                     Removed 2nd G20 in header.
+ Mark     28/08/2009 Added G91.1 to force use of incremental arcs
+                     Added Substitution, File & Toolpath Notes.
+ Mark     30/11/2009 Added TOOLPATHS_OUTPUT.
+ Brian    15/12/2009 Remove M05 from NEW_SEGMENT
+ Mark     18/01/2014 Added Dwell
+Peter     2/1/16     Converted to Laser
+================================================

POST_NAME = "Mach Laser Arcs (inch) (*.txt)"

FILE_EXTENSION = "txt"

UNITS = "inches"

DIRECT_OUTPUT = "Mach|Mach4.Document"

SUBSTITUTE = "({)}"

+------------------------------------------------
+    Line terminating characters                 
+------------------------------------------------

LINE_ENDING = "[13][10]"

+------------------------------------------------
+    Block numbering                             
+------------------------------------------------

LINE_NUMBER_START     = 0
LINE_NUMBER_INCREMENT = 10
LINE_NUMBER_MAXIMUM = 999999

+================================================
+                                               
+    Formating for variables                     
+                                               
+================================================

VAR LINE_NUMBER = [N|A|N|1.0]
VAR SPINDLE_SPEED = [S|A|S|1.0]
VAR FEED_RATE = [F|C|F|1.1]
VAR X_POSITION = [X|A|X|1.4]
VAR Y_POSITION = [Y|A|Y|1.4]
VAR Z_POSITION = [Z|A|Z|1.4]
VAR ARC_CENTRE_I_INC_POSITION = [I|A|I|1.4]
VAR ARC_CENTRE_J_INC_POSITION = [J|A|J|1.4]
VAR X_HOME_POSITION = [XH|A|X|1.4]
VAR Y_HOME_POSITION = [YH|A|Y|1.4]
VAR Z_HOME_POSITION = [ZH|A|Z|1.4]
VAR SAFE_Z_HEIGHT = [SAFEZ|A|Z|1.4]
VAR DWELL_TIME = [DWELL|A|P|1.2]
+================================================
+                                               
+    Block definitions for toolpath output       
+                                               
+================================================

+---------------------------------------------------
+  Commands output at the start of the file
+---------------------------------------------------

begin HEADER

"( [TP_FILENAME] )"
"( File created: [DATE] - [TIME])"
"( for Mach2/3 from Vectric )"
"( Material Size)"
"( X= [XLENGTH], Y= [YLENGTH], Z= [ZLENGTH])"
"([FILE_NOTES])"
"(Toolpaths used in this file:)"
"([TOOLPATHS_OUTPUT])"
"(Tools used in this file: )"
"([TOOLS_USED])"
"[N]G00G20G17G90G40G49G80"
"[N]G70G91.1"
"[N]T[T]M06"
"[N] (Tool: [TOOLNAME])"
"[N]G00G43[ZH]H[T]"
"[N](Toolpath:- [TOOLPATH_NAME])"
"[N]([TOOLPATH_NOTES])"
"[N]G94"
"[N][XH][YH][F]"

+---------------------------------------------------
+  Commands output for rapid moves
+---------------------------------------------------

begin RAPID_MOVE

"[N]M05"
"[N]G00[X][Y]"


+---------------------------------------------------
+  Commands output for the first feed rate move
+---------------------------------------------------

begin FIRST_FEED_MOVE

"[N][S]M03"
"[N]G1[X][Y][F]"


+---------------------------------------------------
+  Commands output for feed rate moves
+---------------------------------------------------

begin FEED_MOVE

"[N][S]M03"
"[N]G1[X][Y]"

+---------------------------------------------------
+  Commands output for the first clockwise arc move
+---------------------------------------------------

begin FIRST_CW_ARC_MOVE

"[N][S]M03"
"[N]G2[X][Y][I][J][F]"

+---------------------------------------------------
+  Commands output for clockwise arc  move
+---------------------------------------------------

begin CW_ARC_MOVE

"[N][S]M03"
"[N]G2[X][Y][I][J]"

+---------------------------------------------------
+  Commands output for the first counterclockwise arc move
+---------------------------------------------------

begin FIRST_CCW_ARC_MOVE

"[N][S]M03"
"[N]G3[X][Y][I][J][F]"

+---------------------------------------------------
+  Commands output for counterclockwise arc  move
+---------------------------------------------------

begin CCW_ARC_MOVE

"[N][S]M03"
"[N]G3[X][Y][I][J]"

+---------------------------------------------------
+  Commands output at toolchange (Commented out)
+---------------------------------------------------

begin TOOLCHANGE

+[N]T[T]M6
+[N] (Tool: [TOOLNAME])
+[N]G43H[T]


+---------------------------------------------------
+  Commands output for a new segment - toolpath
+  with same toolnumber but maybe different feedrates
+---------------------------------------------------

begin NEW_SEGMENT

"[N][S]M03"
"([TOOLPATH_NAME])"
"([TOOLPATH_NOTES])"


+---------------------------------------------
+  Commands output for a dwell move
+---------------------------------------------

begin DWELL_MOVE

"G04 [DWELL]"

+---------------------------------------------------
+  Commands output at the end of the file
+---------------------------------------------------

begin FOOTER

"[N]M05"
"[N]G00[ZH]"
"[N]G00[XH][YH]"
"[N]M09"
"[N]M30"
%
Title: Re: Add a laser to my CNC
Post by: Pedio on February 01, 2016, 04:58:52 PM
The laser will cut through masking tape so you can make your own paint masks for fancy items - too cool!
Title: Re: Add a laser to my CNC
Post by: Pedio on February 02, 2016, 07:21:40 PM
Burned a logo for the local sailing club in the back of a leather jacket I got at Goodwill today. It work fine. The lines were rather thin. I may try defocusing the laser to see if it gives a better result. Anyone tried doing leather with a laser? Tips would be appreciated.

Also, found an error in the post processor for Vcarve. Here is an update:

Code: [Select]
    +================================================
    +                                               
    + Mach2/3 - Vectric machine output configuration file   
    +                                               
    +================================================
    +                                               
    + History                                       
    +                                               
    + Who      When       What                         
    + ======== ========== ===========================
    + Tony     15/11/2005 Written
    + Tony     06/01/2006 Added ATC option   
    + Tony     14/05/2006 Fixed G20 inch in header   
    + Tony     24/07/2006 Added G2 & G3 Arc support + removed (( ))
    + Tony     18/06/2007 Replaced the Tool comment       
    + Mark     14/08/2008 Added G1 to Feed moves, added New_Segment
    +                     Removed 2nd G20 in header.
    + Mark     28/08/2009 Added G91.1 to force use of incremental arcs
    +                     Added Substitution, File & Toolpath Notes.
    + Mark     30/11/2009 Added TOOLPATHS_OUTPUT.
    + Brian    15/12/2009 Remove M05 from NEW_SEGMENT
    + Mark     18/01/2014 Added Dwell
    +Peter     2/1/16     Converted to Laser
    +================================================

    POST_NAME = "Mach Laser Arcs (inch) (*.txt)"

    FILE_EXTENSION = "txt"

    UNITS = "inches"

    DIRECT_OUTPUT = "Mach|Mach4.Document"

    SUBSTITUTE = "({)}"

    +------------------------------------------------
    +    Line terminating characters                 
    +------------------------------------------------

    LINE_ENDING = "[13][10]"

    +------------------------------------------------
    +    Block numbering                             
    +------------------------------------------------

    LINE_NUMBER_START     = 0
    LINE_NUMBER_INCREMENT = 10
    LINE_NUMBER_MAXIMUM = 999999

    +================================================
    +                                               
    +    Formating for variables                     
    +                                               
    +================================================

    VAR LINE_NUMBER = [N|A|N|1.0]
    VAR SPINDLE_SPEED = [S|A|S|1.0]
    VAR FEED_RATE = [F|C|F|1.1]
    VAR X_POSITION = [X|A|X|1.4]
    VAR Y_POSITION = [Y|A|Y|1.4]
    VAR Z_POSITION = [Z|A|Z|1.4]
    VAR ARC_CENTRE_I_INC_POSITION = [I|A|I|1.4]
    VAR ARC_CENTRE_J_INC_POSITION = [J|A|J|1.4]
    VAR X_HOME_POSITION = [XH|A|X|1.4]
    VAR Y_HOME_POSITION = [YH|A|Y|1.4]
    VAR Z_HOME_POSITION = [ZH|A|Z|1.4]
    VAR SAFE_Z_HEIGHT = [SAFEZ|A|Z|1.4]
    VAR DWELL_TIME = [DWELL|A|P|1.2]
    +================================================
    +                                               
    +    Block definitions for toolpath output       
    +                                               
    +================================================

    +---------------------------------------------------
    +  Commands output at the start of the file
    +---------------------------------------------------

    begin HEADER

    "( [TP_FILENAME] )"
    "( File created: [DATE] - [TIME])"
    "( for Mach2/3 from Vectric )"
    "( Material Size)"
    "( X= [XLENGTH], Y= [YLENGTH], Z= [ZLENGTH])"
    "([FILE_NOTES])"
    "(Toolpaths used in this file:)"
    "([TOOLPATHS_OUTPUT])"
    "(Tools used in this file: )"
    "([TOOLS_USED])"
    "[N]G00G20G17G90G40G49G80"
    "[N]G70G91.1"
    "[N] (Tool: [TOOLNAME])"
    "[N]G00G43[ZH]H[T]"
    "[N](Toolpath:- [TOOLPATH_NAME])"
    "[N]([TOOLPATH_NOTES])"
    "[N]G94"
    "[N][XH][YH][F]"

    +---------------------------------------------------
    +  Commands output for rapid moves
    +---------------------------------------------------

    begin RAPID_MOVE

    "[N]M05"
    "[N]G00[X][Y]"


    +---------------------------------------------------
    +  Commands output for the first feed rate move
    +---------------------------------------------------

    begin FIRST_FEED_MOVE

    "[N][S]M03"
    "[N]G1[X][Y][F]"


    +---------------------------------------------------
    +  Commands output for feed rate moves
    +---------------------------------------------------

    begin FEED_MOVE

    "[N][S]M03"
    "[N]G1[X][Y]"

    +---------------------------------------------------
    +  Commands output for the first clockwise arc move
    +---------------------------------------------------

    begin FIRST_CW_ARC_MOVE

    "[N][S]M03"
    "[N]G2[X][Y][I][J][F]"

    +---------------------------------------------------
    +  Commands output for clockwise arc  move
    +---------------------------------------------------

    begin CW_ARC_MOVE

    "[N][S]M03"
    "[N]G2[X][Y][I][J]"

    +---------------------------------------------------
    +  Commands output for the first counterclockwise arc move
    +---------------------------------------------------

    begin FIRST_CCW_ARC_MOVE

    "[N][S]M03"
    "[N]G3[X][Y][I][J][F]"

    +---------------------------------------------------
    +  Commands output for counterclockwise arc  move
    +---------------------------------------------------

    begin CCW_ARC_MOVE

    "[N][S]M03"
    "[N]G3[X][Y][I][J]"

    +---------------------------------------------------
    +  Commands output at toolchange (Commented out)
    +---------------------------------------------------

    begin TOOLCHANGE

    +[N]T[T]M6
    +[N] (Tool: [TOOLNAME])
    +[N]G43H[T]


    +---------------------------------------------------
    +  Commands output for a new segment - toolpath
    +  with same toolnumber but maybe different feedrates
    +---------------------------------------------------

    begin NEW_SEGMENT

    "[N][S]M03"
    "([TOOLPATH_NAME])"
    "([TOOLPATH_NOTES])"


    +---------------------------------------------
    +  Commands output for a dwell move
    +---------------------------------------------

    begin DWELL_MOVE

    "G04 [DWELL]"

    +---------------------------------------------------
    +  Commands output at the end of the file
    +---------------------------------------------------

    begin FOOTER

    "[N]M05"
    "[N]G00[ZH]"
    "[N]G00[XH][YH]"
    "[N]M09"
    "[N]M30"
    %

Title: Re: Add a laser to my CNC
Post by: Pedio on February 03, 2016, 08:18:53 PM
Got to play with the laser a little more today. The spindle start on each feed move was causing the toolpaths to be a little jerky. I replaced these with a laser on for a plunge and a laser off for a retract. I have changed my machine to exact stop instead of constant velocity. I plan on playing with this a little more in the next few days.

I still can't figure out how to turn off the laser on an eStop. Also, I tried making a button to turn on the spindle but did not get it to work. Any suggestions?

Here is the post processor code I am currently using. Will let you know how it goes.

Code: [Select]
+================================================
+                                               
+ Mach2/3 - Vectric machine output configuration file   
+                                               
+================================================
+                                               
+ History                                       
+                                               
+ Who      When       What                         
+ ======== ========== ===========================
+ Tony     15/11/2005 Written
+ Tony     06/01/2006 Added ATC option   
+ Tony     14/05/2006 Fixed G20 inch in header   
+ Tony     24/07/2006 Added G2 & G3 Arc support + removed (( ))
+ Tony     18/06/2007 Replaced the Tool comment       
+ Mark     14/08/2008 Added G1 to Feed moves, added New_Segment
+                     Removed 2nd G20 in header.
+ Mark     28/08/2009 Added G91.1 to force use of incremental arcs
+                     Added Substitution, File & Toolpath Notes.
+ Mark     30/11/2009 Added TOOLPATHS_OUTPUT.
+ Brian    15/12/2009 Remove M05 from NEW_SEGMENT
+ Mark     18/01/2014 Added Dwell
+Peter     2/1/16     Converted to Laser
+Peter     2/3/16     Used plunge and retract commands instead of spindle start on each move to avoid jerkey moves
+================================================

POST_NAME = "Mach Laser Arcs (inch) (*.txt)"

FILE_EXTENSION = "txt"

UNITS = "inches"

DIRECT_OUTPUT = "Mach|Mach4.Document"

SUBSTITUTE = "({)}"

+------------------------------------------------
+    Line terminating characters                 
+------------------------------------------------

LINE_ENDING = "[13][10]"

+------------------------------------------------
+    Block numbering                             
+------------------------------------------------

LINE_NUMBER_START     = 0
LINE_NUMBER_INCREMENT = 10
LINE_NUMBER_MAXIMUM = 999999

+================================================
+                                               
+    Formating for variables                     
+                                               
+================================================

VAR LINE_NUMBER = [N|A|N|1.0]
VAR SPINDLE_SPEED = [S|A|S|1.0]
VAR FEED_RATE = [F|C|F|1.1]
VAR X_POSITION = [X|A|X|1.4]
VAR Y_POSITION = [Y|A|Y|1.4]
VAR Z_POSITION = [Z|A|Z|1.4]
VAR ARC_CENTRE_I_INC_POSITION = [I|A|I|1.4]
VAR ARC_CENTRE_J_INC_POSITION = [J|A|J|1.4]
VAR X_HOME_POSITION = [XH|A|X|1.4]
VAR Y_HOME_POSITION = [YH|A|Y|1.4]
VAR Z_HOME_POSITION = [ZH|A|Z|1.4]
VAR SAFE_Z_HEIGHT = [SAFEZ|A|Z|1.4]
VAR DWELL_TIME = [DWELL|A|P|1.2]
+================================================
+                                               
+    Block definitions for toolpath output       
+                                               
+================================================

+---------------------------------------------------
+  Commands output at the start of the file
+---------------------------------------------------

begin HEADER
"[N]M05"
"( [TP_FILENAME] )"
"( File created: [DATE] - [TIME])"
"( for Mach2/3 from Vectric )"
"( Material Size)"
"( X= [XLENGTH], Y= [YLENGTH], Z= [ZLENGTH])"
"([FILE_NOTES])"
"(Toolpaths used in this file:)"
"([TOOLPATHS_OUTPUT])"
"(Tools used in this file: )"
"([TOOLS_USED])"
"[N]G00G20G17G90G40G49G80"
"[N]G70G91.1"
"[N] (Tool: [TOOLNAME])"
"[N](Toolpath:- [TOOLPATH_NAME])"
"[N]([TOOLPATH_NOTES])"
"[N]G94"
"[N][XH][YH][F]"

+---------------------------------------------------
+  Commands output for rapid moves
+---------------------------------------------------

begin RAPID_MOVE

"[N]M05"
"[N]G00[X][Y]"


+---------------------------------------------------
+  Commands output for the first feed rate move
+---------------------------------------------------

begin FIRST_FEED_MOVE

"[N]G1[X][Y][F]"


+---------------------------------------------------
+  Commands output for feed rate moves
+---------------------------------------------------

begin FEED_MOVE

"[N]G1[X][Y]"

+---------------------------------------------------
+  Commands output for the first clockwise arc move
+---------------------------------------------------

begin FIRST_CW_ARC_MOVE

"[N]G2[X][Y][I][J][F]"

+---------------------------------------------------
+  Commands output for clockwise arc  move
+---------------------------------------------------

begin CW_ARC_MOVE

"[N]G2[X][Y][I][J]"

+---------------------------------------------------
+  Commands output for the first counterclockwise arc move
+---------------------------------------------------

begin FIRST_CCW_ARC_MOVE

"[N]G3[X][Y][I][J][F]"

+---------------------------------------------------
+  Commands output for counterclockwise arc  move
+---------------------------------------------------

begin CCW_ARC_MOVE

"[N]G3[X][Y][I][J]"


+---------------------------------------------------
+  Commands output for a new segment - toolpath
+  with same toolnumber but maybe different feedrates
+---------------------------------------------------

begin NEW_SEGMENT

"([TOOLPATH_NAME])"
"([TOOLPATH_NOTES])"

+ ---------------------------------------------------
+  Commands output for Retract Moves
+ ---------------------------------------------------
begin PLUNGE_MOVE

"[N][S]M03"

+ ---------------------------------------------------
+  Commands output for Retract Moves
+ ---------------------------------------------------
begin RETRACT_MOVE

"[N]M05"

+---------------------------------------------
+  Commands output for a dwell move
+---------------------------------------------

begin DWELL_MOVE

"[N]G04 [DWELL]"

+---------------------------------------------------
+  Commands output at the end of the file
+---------------------------------------------------

begin FOOTER

"[N]M05"
"[N]G00[ZH]"
"[N]G00[XH][YH]"
"[N]M09"
"[N]M30"
%



Title: Re: Add a laser to my CNC
Post by: Pedio on February 11, 2016, 04:18:29 PM
I found out what was going on with the manual spindle control of the laser. If you set the spindle too high the laser does not see the PWM signal. The slider bar for spindle is defaulted 0-250%. Not sure why it goes that high? I changed this to 0-100%

Title: Re: Add a laser to my CNC
Post by: bob_at_pmdx on February 11, 2016, 09:01:19 PM
I found out what was going on with the manual spindle control of the laser. If you set the spindle too high the laser does not see the PWM signal. The slider bar for spindle is defaulted 0-250%. Not sure why it goes that high? I changed this to 0-100%
Are you sure that the slider wasn't the "spindle speed override" and not plain "spindle speed".  Specially since it is marked in percent.  In the wxMach screen set, the slider in the "Spindle" group is marked "SRO%" and the values go from 1 to 250.  In the wx4 screen set, the slider in the spindle group is marked "SRO" and goes from 50% to 150%.  Those take the currently commanded spindle speed and increase it or decrease it by a percentage.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 11, 2016, 10:27:37 PM
I am using the wxMach screenset as the basis for my screen set.

So what does the SRO% represent when you don't have a g code file loaded. I use this slider and the Spindle CW button to turn on my laser so I can focus it to the right level.

Also, when I hit eStop the laser will stay on (it looks like a lower output) is there anyway I can turn off the laser (spindle) on an eStop?
Title: Re: Add a laser to my CNC
Post by: bob_at_pmdx on February 12, 2016, 12:14:31 PM
So what does the SRO% represent when you don't have a g code file loaded. I use this slider and the Spindle CW button to turn on my laser so I can focus it to the right level.
SRO is "spindle rate override" and changes the spindle speed to the given PERCENTAGE of the currently commanded spindle speed.  For example, with SRO = 100%, enter 1000 as the spindle RPM (presuming that is a valid RPM for you setup).  The spindle should turn at 1000 RPM, or in your case the PWM should reflect a duty cycle of ((commanded RPM) / (maximum RPM)) * 100.  Now if you slide the SRO slider up to 150%, the actual spindle speed will change to (1000 * 150%) = 1500 RPM.  The "commanded" spindle speed is still 1000 RPM.

So I am presuming that you set *some* non-zero spindle speed ("S" command) before you try sliding the SRO slider.  Because if the current spindle speed is zero, the SRO slider shouldn't change anything until a non-zero spindle speed is entered.

You can edit the screen set (please copy wxMach.set to some other name and use/edit that so you don't loose your changes in the next Mach4 upgrade/install) and change the SRO slider to be "spindle RPM".  Select the slider and change the "Code" field to "Spindle RPM".  You should also change the name and label, and min/max limits.  I would suggest configuring your spindle range as "1 to 100" in the "Spindle" tab of the normal Mach4 configuration dialog.

Quote
Also, when I hit eStop the laser will stay on (it looks like a lower output) is there anyway I can turn off the laser (spindle) on an eStop?
Something definitely isn't right here.  EStop (or Mach4 Disable) should turn off ALL outputs, including PWM.  It may be that the PWM is getting set to 0% duty cycle as it should, which maybe the laser interprets and "on but very dim"?  But I thought you also had some output signal controlling the on/off signal (or was it turning power on and off).  If you do, THAT output should also go "in-active" during EStop and turn the laser off.  If that is not happening, it sounds like a possible bug in the SmoothStepper plug-in or something unconventional in your configuration that prevents the laser from turning off.

For example, when I try this with our plug-in, when EStop is activated I see messages from the Mach4 core to turn off my "Spindle On" output and it sets the spindle speed to 0.  All the outputs on our board turn off and the PWM output goes to steady-state zero volts (0% duty cycle).

Bob
Title: Re: Add a laser to my CNC
Post by: Pedio on February 13, 2016, 02:39:21 PM
Bob - thanks. I got to play with the spindle a little more today and it works as you said. The problem I am having is I want to position the laser at the 0,0 point of my work piece. Until I run the g code file Mach 4 does not have a laser setting so I can not turn the laser on using the spindle control to center the work piece. Is there any way I can make a button that turns on the spindle to a known setting?

The other problem is with eStop. Sometimes it turns off the spindle and sometimes it does not. The LED on Mach 4 even shows the spindle on when it does not turn off the spindle. I am using Mach 4 (not the latest but one rev back) and PMDX 410 with a PMDX 132 breakout board.
Title: Re: Add a laser to my CNC
Post by: bob_at_pmdx on February 13, 2016, 10:43:11 PM
Bob - thanks. I got to play with the spindle a little more today and it works as you said. The problem I am having is I want to position the laser at the 0,0 point of my work piece. Until I run the g code file Mach 4 does not have a laser setting so I can not turn the laser on using the spindle control to center the work piece. Is there any way I can make a button that turns on the spindle to a known setting?
Yes, there are a couple of ways to do this.

(1) In my test screen sets I've added a DRO near the "Spindle CW" button.  I set the "DRO Code" to "Spindle RPM", and set the "Format" field to "%.1f" which displays 1 fractional digit.  I don't remember why I did that as I don't need that kind of resolution.  Setting to "%.0f" will display no fractional decimal digits.

or...

(2) Add a button. Then edit the button's "Left Up Script" to something like this (UNTESTED!!!!):

local inst = mc.mcGetInstance();
local rpm = 1000;    -- Set this to the actual RPM you want as your starting point
mc.mcSpindleSetCommandRPM( inst, rpm );
mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse

Quote
The other problem is with eStop. Sometimes it turns off the spindle and sometimes it does not. The LED on Mach 4 even shows the spindle on when it does not turn off the spindle. I am using Mach 4 (not the latest but one rev back) and PMDX 410 with a PMDX 132 breakout board.
Rats.  I don't know *WHY* I thought you had an ESS.  I could have sworn I read that earlier in this thread, but (now) obviously not.  Well then, I guess in all fairness I need to say that maybe this is an issue in OUR plug-in.  So I'm going to get niggly here:

- Exactly which version of Mach4 are you running
- Exactly which versions of our plug-in are you running
- Which LED on the Mach4 screen is on when the spindle is still on during EStop?
- Which Mach4 output signal do you have controlling the spindle on/off (ex "Spindle On" or "Spindle Fwd")?
- Which SmartBOB output pin do you have that Mach4 signal mapped to (ex "Pin1", "Pin11", etc.)?

I'm sure I'll have more questions later, but this is a start.

Bob
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 10:09:58 AM
Bob - In answer to your questions:

Mach 4 - v 2797
Smart Bob - V 33.159
The LED that is on when eStop is pressed is the Spindle CW LED on the main page of wxMach screen set
It appears this LED is driven by the 'Spindle Fwd'
I am using Pin 16 on the PMDX 132 for the PWM

I will try the code for turning on the spindle today and let you know how it goes.

thanks
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 11:05:28 AM
The spindle (laser) on worked fine. I tried setting the power to 0 to turn off the laser but that did not work. The spindle CW button on the normal wxMach screen toggles the spindle on and off so this will work for my laser off.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 12:15:59 PM
Bob - also, are you sure the PWM works the way you indicated? If I set the PWM slider for 100% and turn on the laser to the max I have the spindle set for (100) it is very dull. If I set the slider for 250% everything works well. It seems 250% is actually 100% of the laser. It could be that I am confused.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 12:33:30 PM
The spindle (laser) on worked fine. I tried setting the power to 0 to turn off the laser but that did not work. The spindle CW button on the normal wxMach screen toggles the spindle on and off so this will work for my laser off.

Oops - spoke too soon. The code to position the laser works to turn on the laser at a very low power; however, after I use the code to position the laser the laser power stays at that level when I run the G code file. Even if I reload the G code file the laser stays at the lower level of the test. I have to restart Mach to get the laser power back to normal.
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 01:44:44 PM
Bob - I added this code to the Spindle CW button and it seems to work.

local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);

if (sigState == 1) then
    mc.mcSpindleSetDirection(inst, 0);
else
    mc.mcSpindleSetDirection(inst, 1);
    local rpm = 100;    -- Set this to the actual RPM you want as your starting point
    mc.mcSpindleSetCommandRPM( inst, rpm );
    mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse

end
Title: Re: Add a laser to my CNC
Post by: Pedio on February 14, 2016, 02:48:28 PM
Bob - I added this code to the Spindle CW button and it seems to work.

local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);

if (sigState == 1) then
    mc.mcSpindleSetDirection(inst, 0);
else
    mc.mcSpindleSetDirection(inst, 1);
    local rpm = 100;    -- Set this to the actual RPM you want as your starting point
    mc.mcSpindleSetCommandRPM( inst, rpm );
    mc.mcSpindleSetDirection( inst, 1 );    -- 1 == forward, 0 == off, -1 == reverse

end
Nope still does not work. The laser will stay at a lower power. Hmmmmmmm????
Title: Re: Add a laser to my CNC
Post by: bob_at_pmdx on February 14, 2016, 10:32:03 PM
First - you have two calls to mc.mcSpindleSetDirection( inst, 1 ) in you code.  You only need one.  The second shouldn't cause any problems, but is not needed and for the sake of code clarity should be removed.

Second - *IF* you want a spindle RPM of "100" to be the maximum intensity, then you need to edit the spindle RPM range to be from 0 to 100.  Go to the Mach4 "configure" menu and select "Mach...".  Then click on the "Spindle" tab.  In the first row, marked "0", make sure the MinRPM is zero and the MaxRPM is 100 (or whatever RPM you want to correspond to the maximum laser intensity).  If your mc.mcSpindleSetCommandRPM() call sets the RPM to the maximum value, then the SRO slider should NOT be able to make it brighter.  It should be able to make it dimmer.

Third - the documentation for your laser's PWM input (that I found at the link you poster earlier) says that the PWM input will control the laser intensity from 15% to 100%.  That implies (to me) that the lowest power setting attainable via PWM control is 15% of max brightness.  Outputting 0% PWM apparently *still* gives you 15% brightness.  So you need some other control to turn the laser off.

Are you using any other signal to control the laser on/off?  Or are you only using the PWM signal on Pin16?

Regarding the EStop not turning off the spindle/laser - when you say "the LED is on when estop is pressed", do you mean when you press an external EStop button (that is wired into the EStop input on the PMDX-132)?  Or do you mean when you click the "Disable" button in the lower left corner of the Mach4 screen?

Finally - please generate a Mach4 profile package (go to Mach4 "Help" and select "Support" and then "Package Current Profile").  Save the file somewhere that you can find it and then either email it to me at bob at this domain, or upload it here.  In order to upload the profile package, you will need to either (a) change the file extension from ".m4prof" to something like ".zip", or zip the profile package into a zip file.  This will hopefully make it so I don't have to keep asking questions about your configuration.

Bob
Title: Re: Add a laser to my CNC
Post by: Tweakie.CNC on February 15, 2016, 01:44:27 AM
Quote
Nope still does not work. The laser will stay at a lower power. Hmmmmmmm?


Pedio,

It is still very early days with Mach4 and the development of motion controllers and although it may some while into the future, one day, I expect they will all support the M62/M63 commands.
From your testing it is apparent that you cannot switch your laser beam on/off by using the PWM signal so why not just use an imaginary axis direction signal as mentioned and demonstrated here…  http://www.machsupport.com/forum/index.php/topic,31495.msg218362.html#msg218362

Tweakie.
Title: Re: Add a laser to my CNC
Post by: bob_at_pmdx on February 15, 2016, 02:47:48 AM
From your testing it is apparent that you cannot switch your laser beam on/off by using the PWM signal so why not just use an imaginary axis direction signal as mentioned and demonstrated here…  http://www.machsupport.com/forum/index.php/topic,31495.msg218362.html#msg218362
The danger in using an otherwise unused motor "direction" signal to turn the laser on and off is that EStop will NOT necessarily turn off the laser.  EStop halts motion but does not return any motor "direction" signal to a per-determined, known state.  Certainly not on the SmartBOB boards, and I'd bet coffee money not on any other motion controller device.

Bob
Title: Re: Add a laser to my CNC
Post by: Tweakie.CNC on February 15, 2016, 04:50:25 AM
Hi Bob,

Perhaps all the more reason for motion controller developers to support the M62/M63 commands ??

In my case (as shown in the linked video) I am combining the A axis direction signal (a modified logic AND) with the PWM on an Output# (as a laser power control method this is described in a bit more detail in my Laser thread). As a result Estop turns off the Output# and also the laser (the A axis direction signal is not passed through without the Output# being active). I appreciate that not everyone would want to use this method but it is just one way of achieving the desired result when I only had limited tools available.

Tweakie.

(I had to check a few things for accuracy so this post was deleted, corrected, then re-posted)
Title: Re: Add a laser to my CNC
Post by: TOTALLYRC on February 15, 2016, 06:35:12 PM
E-stop should cut power to the laser via a relay or hardwire the laser power thru the estop switch, not rely on the motion controller.

Mike
Title: Re: Add a laser to my CNC
Post by: Pedio on February 15, 2016, 09:10:46 PM
Gang - I added the laser to the spindle control because it was much easier for me to change my post processor for the CAD program (Vcarve Pro). My theory was that I could set up tools to use different feeds and speeds to handle different levels of laser. What I actually found is it was easier to leave the laser (3W) on full power all of the time and vary the feed rate or the depth (number of passes) to get the level of darkness I desired. Also, I have used the offset tool to make the lines thicker. I can add shadowing with offset and depth of cut (number of passes). The spindle control works very well. Not sure how I would use the A axis with my CAD program (Note - I tend to over think things).

The only problem I am having now are

Here is a leather jacket I made today. Really amazing what you can get for $5 at GoodWill and turn into a $*********+ jacket!!! Speed 7 in/min, three passes, and 3 W laser at 100%.
Title: Re: Add a laser to my CNC
Post by: TOTALLYRC on February 16, 2016, 05:47:09 AM
Nice work with a 3W laser.

Mike
Title: Re: Add a laser to my CNC
Post by: Pedio on February 16, 2016, 07:49:58 AM

Regarding the EStop not turning off the spindle/laser - when you say "the LED is on when estop is pressed", do you mean when you press an external EStop button (that is wired into the EStop input on the PMDX-132)?  Or do you mean when you click the "Disable" button in the lower left corner of the Mach4 screen?


Bob- I have a toggle switch that turns on and off the 12V to the laser. It gives me absolute control over activating the laser. Once the 12V switch is on I can then control the laser with the PWM from Mach 4. If something happens I can turn off the laser with the toggle switch. I also have the 12 going through the mushroom button for eStop. I have two NC contacts on the mushroom button so when I push it I disable Mach and the laser / spindle. The laser and spindle are both on the same side of the button (can't find a three contact NO mushroom button). Since I am using the toggle switch for both the laser and the spindle it works now.

The problem I am having is the when I use the ShuttlePro to stop the motion the laser sometimes works and sometimes does not. It works about 40% of the time. I believe I told you guys it was the disable button that was not working all of the time. I will see what the eStop on the ShuttlePro is mapped to and let you know.

Title: Re: Add a laser to my CNC
Post by: Pedio on February 16, 2016, 05:02:53 PM
I looked at the ShuttlePro set up and the command is CycleStop. There are no other eStop type commands for the ShuttlePro.