Arduino based Laser Control

A forum for the Arduino based Mach4/Darwin Laser Control Panel
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Hi Guys:

  Just thought Id let you know I have modified the laser panels code to change engraving mode
so the pot which controls power for a diagnostics shot  now controls the NGrave photo power as well.
Since my photos seemed to only need a power of 20 I was only getting 20 levels at most of power for
the shot, so I implemented a 100 level power array selection in the panel and modified Darwin to send
a power request of 0 - 100% for every step or pixel in the photo. the panel then makes that 0-100% of the
pot's current selected power. This means even if your engraving with 20% max power, that 20% will have
100 levels from 0 - 20%... so .2 percent of laser power per grey scale level in the image.
  Im not sure yet exactly how granular my synrad is yet.. it may limit to 1us or 20us..I havent yet  tested
but this change should allow for greater grey scale levels that I was getting before. Ill keep you posted.

I wont bother posting code for the changes Im making until others are running a control panel, then Ill
start posting the code Im using and we can discuss better methods when more people are testing.. Ive
also been in touch with Greg for the SmoothStepper and Steve Stallings for the PMDX usb driver for early
discussions on a standard for signal output so no matter what motion device is used with mach, perhaps this panel will work at some point in the future.Any code I use or methods I use I will keep open sourced to maximize the number of people that can engrave using this method of laser control.

Art
User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Art,

I have read all the posts again (and again) and I am still missing the set-up you are using to get the required signals to and from Mach4 / Darwin.  :'(
You have shown in your earlier diagram ?step flag", "serial data", "serial clock", "PWM output to laser?, etc. but I really have no idea how these signals are received or sent.
It seems everybody else understands how it has been done but I must have a brain block or something - any chance of a dumbo?s guide to your Mach4 / Darwin configuration please.

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Hi Tweakie:

  Sorry, my fault really. There should be a full explainatin out there, so here it is as a white paper type of explanation..
 
  To control a laser in Darwin, one can either use a PWM spindle output as in the past for power, or the new serial clk,data and step flags I currently use. So there are basically 3 ways in Darwin to use the laser.

PWM with spindle On/Off:

  If one wishes PWM, you simply setup a spindle as PWM and set your spindle range in Mach4 from 0 -100 with ( in my case) 50hz PWM. It all depends on your hardware of course. In the case of the Arduino Laser Panel the 50hz PWM is taken and converted to 5Khz pwm to be sent to the laser. The Spindle On/Off signal is then used to control power on or off, again, depending on hardware. In my case with the Aduino panel there is no need of real time on/off signals as the laser only fires on a step pulse, but one can use M62/M62 commands for rapid on/off ( those commands are untested as of yet and we're waiting on confirmation as to how to use them) if you have on/off hardware of some sort on your laser control.

Serial Data control:

In this control method you need the arduino panel, or hardware that can accept the data provided. In Darwin, output signals 126, 127 and 128 are hardwired to control the serial clk, serial data and step flag. The use of these items are controlled by the "Laser mode" selection in Darwins M4 diagnostics config.  When selected, you can use 2 differing modes, Image linked mode, or normal GCode. In Normal GCode, you set the power as above but with no need of PWM. For example, if you execute an M3S50 , youll be telling Darwin to enable the laser at a power of 50%, the power will be sent as 50 to the arduino using the SerialClk and Serial Data lines. There is a protocol to this which can be seen in the arduino code. When the Arduino see's a step is taken it will fire the laser at the requested power. Further to that, Darwin will check to see how many steps are going to be taken on each waypoint. It will adjust the power of the current shot to ensure the power is as close as possible to the power per step on the fastest motion to be seen in the program. For example, if you have a F3000 in the program, Darwin knows that at full speed a 5khz laser will see 1 shot span over say.. 10 steps. Thats simply the movement the gantry will do as the laser takes one shot. So if Darwin sees a waypoint that moves only 1 step, it will reduce the power of that shot to 10%, in this way trying to ensure the line is burned evenly even though your moving slower at the beginning of a line than at the end. SO its important you have Feedrate command before the M3 command as Darwin does its computation of this at M3 time. This is the CNC mode of the arduino panel, its simply fires each step pulse at the power and count of pulses dialed up on the panel with Darwin modifying the power as above.

NGrave mode:

  The NGrave mode is Darwins Photo only mode. In this mode you link a photo (In Darwins Diagnostics menu). This photo linkage will load G code at the same time as it links to an image data file created by the same dialog. ( Or by gearotic which can manipulate the gray scales in various ways to enhance the engraving by matching power levels to various mathematical curvatures that reflect true power dissipation in various materials. ). The G code put out by the image processor may be manipulated by the user in any way he wishes, it is not critical. The way it works is that Darwin will monitor all motion while in linkage mode, If the current position of the  axis are within the size of the photo data file ( you specify in inches or mm's the actual size of the engraving at creation time), Darwin will look into the photo file, find a power level ( 0 - 100% from the 0-255 grey scale) and send it via serial data to the arduino. The arduino will then find a power level from 0-100% of the currently selected maximum from the pot on the panel. For example if the panel has selected 50% power and Darwin send 50%, then 25% will be put out for this current set of way-point steps. If 100% was selected on the panel, then 50% power would come out. The power for NGrave is not yet corrected as the previous method to correct for acceleration, which is why the RAMP selection is available for image file creation, this RAMP variable tells the G Code generator to add motion before and after a photo line to allow the gantry to come up to stable speed so the photos power is consistent across the image. This cannot be done in Spiral mode though, so eventually I will likely do a correction as in the previous mode for way-point distance power correction. Spiral mode allows for greater resolution, one of the problems with raster engraving of an image is that constant linear motion has a tendency to remove or burn out linear image information which occurs naturally in many types of images. In the end its likely a much better G Code routine could be created to give high resolution in some areas and lower in others to speed up the process of making an engraving. For example one could simply not scan white area's.. we'll see what the future brings... If the axis are outside the image boundaries in NGrave mode, zero power level is sent to the arduino panel and the laser is not triggered.


Hope this all helps, ask any questions you like, Im hoping this laser project will be community driven and good ideas from any quarter are appreciated, this is all an area which requires a vast amount of experimentation, both in code and materials/Power.. ( thats what makes it fun. ). That having been said I know making something like an Arduino panel takes time , initiative and desire, so until others have one, Ill continue to play with mine and the code base will morph over time. I wont publish such code changes till such time as others have the original panel working so as to not confuse the issue.

Thx
Art

User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Art,

Thanks for the detailed explanation - it is all much clearer now.

The Output Signals 126, 127 & 128 was the key part I was missing.  ;)

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Tweakie:

  Good. I stuck the signals up there because Mach4 users can access only the first 64 signals of input or output. Darwin was written for Mach4 , it was written to be generic, its why its capabilities arent all used by Mach4. M4 use is limited to 4 axis, 64 inputs and 64 outputs, so when I have something special to add I'll always use the upper end of the range.

  The protocol is a simple one and unidirectional. 0xfnnf is sent, with nn being the hex control byte. ( 0-100 in decimal) and the byte must be received identically twice before being considered valid. That will probably change if I ever upgrade to a faster processor like a beagle board or something where I could really get complex. :)

Art
User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Art,

I have just looked at Output Signals 126, 127, 128 - I had to configure them to output pins on Port 2 (all outputs on Port 1 are taken) but as yet I am not getting anything at all showing up on the scope.  :'(
I will have a look again tomorrow and see if I can discover what it is that I am not doing right. :)

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Hi Tweaky:

  Port shouldnt matter.. it has to be enabled of course, but the port shouldnt matter.. I have only 1 so its hard for me
to test that..but I have checked the code just in case. All "looks" well.

Steve confirms the M62/M63 has broken, a fix is underway on that as well.

Art
User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Art,

Yes, I can confirm that ports 1 or 2 don't matter - they both behave OK.

Because Outputs above #64 are unavailable for our use may I suggest that:- serial clk, serial data and step flag are re-allocated to lower values ??

Thanks for the info re: M62/M63 - I will await a later relase of Mach4.  ;)

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Tweakie:

Sorry, I explained that badly. I put those signal at 126-128 so that users wouldnt change them form what I set their names to. YOu CAN use them, I do so they should work. If enabled and set to pins you should see them work. In the case of the step flag for example, you should see it pulse whenever a step is taken, no matter if its port 1 or 2. This should work for anyone , even if unlicensed.  You cannot use the toggle button on the setup to test it though, the step flag will only work when steps are actually taken by a motor. The Serial CLK output will also work but canot be tested with toggle either..and it will only work when laser mode is on, spindle is on, a spindle speed is set from 0 - 100 ( with range set 0 - 100) and steps are taken. SO it too is hard to test..
Serial data is the same, unless your actually using it properly setup , its hard to test..

  So stepflag is the easiest to test, just run any program and watch that it toggles, it should pulse on any step from any motor.. so its a great fire trigger..

Art
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Tweakie:

  Cant find your post.. ( Was it deleted? ). I ll recreate it here as  I think it needs a public answer..

Original Post:

In Darwin pp driver I open a .bmp image, set the size, arduino laser mode etc. then create and save the .dim file. I then link the image which creates the Mach4 raster. So far so good. When I run the Gcode (Cycle Start) having set M3 S50 I seem to get the correct signals on StepFlag and SerialClo ck but the SerialDat a is just a 460uS square wave. What am I doing wrong please ??

  The protocol of the serial data transmission is a bit odd.. this is due to my system being a bit noisy, but also because the arduino is too slow for all the activity at high speeds. Ive found a max of 30Khz here simply due to all the interrupt traffic. So I implemented the protocol in a fairly weird way, one that likely should be modified when more of us do it.

  In Darwin ( like most plugins) a cycle time tells M4 how much data to send each waypoint. ( update loop of the plugin). M4 sends darwin no more than 16 steps at a time , thats at full speed at any frequency. Darwin then tacks on a Power level when appropriate to that packet. It tags the power word with a frame to indicate to the driver that its a power command. This looks in hex like this.. 0xfnnf , where nn is the power word from 0 - 100. This entire word is sent to the arduino and when the arduino see's 0xfnnf it will accept the nn part as a power command only if the word is framed by f's, AND it is repeated twice. This is also slowed so the serial is sent at 1/2 kernal frequency. This too was done to try to make the interrupts work better in the arduino.. ( it didnt help much so I may go back to full frequency sending after more experiments. ). 

  So the end result is a power word that will control typically every 64 steps. In my system I do 250 steps per mm, so thats a base resolution of .25mm per power word. If we go back to the full kernal frequency that will make it .125mm
per power word on my system. Ill wait on that till there are more users of this to improve the protocol..

  So if your scoping, the data stream will be 0xfnnf with nn being power. This will be zero when not in an image or when in a white part of an image, it will be 0-100 representing 0-255 of the image data.

  Since shifting any f's serially would create a false reading in the nn section , any power divisable by 16 will be bumped by 1 to ensure the protocol is as error free as it can be. Its my thinking a bump of 1 level will be unseen so I havent tried to come up with a tighter protocol. My servos inject a bit more noise than Id like so stepper users should find a higher speed works fine. This is a primary area that needs improving.. so hopefully we'll get some hardware guys with better ideas..


Art


User avatar
tweakie
Old Timer
Posts: 170
Joined: Wed Dec 01, 2010 12:58 am

Re: Arduino based Laser Control

Post by tweakie »

Hi Art,

Yes, I deleted the original post - I was too hasty - after Mach4 had been running longer and got further into the image then the serial data in the waveform became evident so my post became redundant. I should have chosen an image where the detail meets all the edges.

Looks like I have to connect up an Adruino now.  :)

Tweakie.
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Tweakie:

  Np, its good to have the protocol listed as someone else may want to build an interface far different than my arduino...beagle board maybe, or TI boards. Ill keep no secrets on how things operate and try very hard to get other motion devices to accept such a protocol..or adapt mine to match one the community decides on.
 

Art
DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

sorry if this sounds a bit daft but her goes
I am a bit confused about what output to use I am using a G540 so only have 3 outputs and one of them is pwm what is 50Hz so I am just unsure what to use for what
User avatar
ArtF
Global Moderator
Global Moderator
Posts: 4593
Joined: Sun Sep 05, 2010 6:14 am
Contact:

Re: Arduino based Laser Control

Post by ArtF »

Dan:

  A G540 wouldnt work I dont think. Its outputs are prescribed. 
  Id add a second printer port and use only that for the laser outputs. Thats probably the best solution..

Art

DanL
Old Timer
Posts: 362
Joined: Wed Sep 10, 2014 1:35 pm

Re: Arduino based Laser Control

Post by DanL »

cool thanks for that art
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests