Hello Guest it is August 06, 2020, 03:46:05 PM

### Author Topic: Help! How to write Macro for M11 and M10 in Mach3  (Read 3495 times)

0 Members and 1 Guest are viewing this topic.

#### nguyenan0803

• 2
##### Help! How to write Macro for M11 and M10 in Mach3
« on: November 30, 2016, 07:00:19 AM »
Dear.
I have used a CNC machine to perform spray painting
I use the M11 and M10.
But I have a problem with it, I use M11 and M10 to turn on and turn off the valve nozzle paint.
At points Start spray (sprayed on) and at the end (Spray off) have too much paint.
Now I want to turn on M11 after 1 second (or other values ​​can be changed) and turn off the M10 command before reaching the end point is 1 second (or other values ​​can be changed).

How to write code to install time macros for M11 and M10 command?
Here are Gcode I use for the machine.

g0x0y0z0
m3 (wait material)
x40y10z-80 (starting point - point A)
m11p3
x100y10 (When mach3 run this line will start running X and spray-M11p3 At X40 to X100 - point B)
m10p3
x100y20 (When Mach3 running this line will stop spray-M10 P3, I want to stop spraying before 1sec before stopping at x100y10 X axis) (point A1)
m11p3
x40y20 (point B1)
m10p3
x100y30 (point A2)
m11p3
x40y30 (point B2)
m10p3
x40y40
....
g0x0y0z0
M9
M5
M47
M30

Mach3 can automatically calculate the length from point A to point B (A1-B1 ...)?
if so, I call C the X-axis travel time from A to B (C (second) = Length A-B / motor speed)
How can mach3 M11 and M10 auto calculate time C, macros can make the next line (A1-B1, A2-B2 ...)?

I need help using the M11 & M10

M11 will begin after Xaxis running 1s (time can be change)
M10 will begin before the X-axis runs to the end of the 1s-time can be change (if C = 10s time  M11 to M10 is enabled 10s - 1s -1S = 8s)
And repeat with the next command.
Sorry my english is not very good.

Please help me. Thank you.

#### joeaverage

• 6,195
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #1 on: November 30, 2016, 08:06:58 PM »
Hi nguyenan0803,
I think I understand what you're trying to achieve. You want the spray to start once
the item has accelerated upto speed and stop spraying before it slows down.

I can see one problem with your approach. When Mach3 encounters an 'M' command
it will complete the previous move before it runs the M instructions. Likewise it will
complete an existing move before it runs your M10 (stop spraying) macro.

As your code is written I would guess the item being painted is stationary or at least
moving very slowly at each end of your moves.

One idea I have is to start a move, for instance
G01 X80 Y10
and then query the DRO associated with the X axis to determine if it is moving at constant
speed and if so activate the spray. I believe the DRO is updated every 100ms or so and is near
as damn-it a realtime position.

Gcode cannot contain conditional statements so the entire spray start/stop cycle would have
to be coded in VB within probably a macro. I will do a little experimenting and get back to you.

Craig
My wife left with my best friend...
and I miss him!

#### joeaverage

• 6,195
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #2 on: November 30, 2016, 10:15:42 PM »
Hi,
after a little messing around this macro seems to work, I hope as you intended.....

Sub main()
code ("g1 x100 y0 f300")
While IsMoving()
If getOEMDRO(800)>20 Then DoOEMButton(233)
If getOEMDRO(800)>80 Then DoOEMButton(234)
Wend
End Sub

Where 'getOEMDRO(800)' is the current position of the X axis and because its inside the "While IsMoving()' loop
is continually updated.
'DoOEMButton(233)' turns on output4 if enabled in 'port and pins' and
'DoOEMButton(234) turns output4 off.

I propose you use output4 to control your spray valve.
As I've written it (I use mm) the movement is from 0 to 100mm at 300mm/min but the object to be painted
is only 60mm wide,and occupies the space from X=20mm to X=80mm. Each of your painting moves could be
done in a macro with intervening G0 moves to setup for the next 'live one'

G0 X0 Y0 ;preposition your machine
M100 ;your first paint pass
G0 X0 Y10 ;preposition for your second pass
M101 ;your appropriately coded second paint pass
and so on.....

The idea might be a bit 'clunky' but I think it might achieve what you want.
There is a timer function in VB which might also work, I haven't messed with it.
My reasoning goes that because you've set the acceleration in your motor tuning
setup it is possible to calculate the distance the axis travels by the time it reaches
its constant speed, ie the feedrate.

Hope this gives you some ideas to pursue. Let us know how you make out.

Craig
My wife left with my best friend...
and I miss him!

#### joeaverage

• 6,195
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #3 on: December 01, 2016, 07:28:32 AM »
Hi,
done a little bit more reading both manuals and the forum....

The 'Sub main()' and 'End sub' lines are not required and in fact may make it fail.
While I couldn't get the ActivateSignal(OUTPUTx) and DeActivateSignal(OUTPUTx) to work for me
this afternoon I have since got them to work and could be substituted for DoOEMButton(*********) which
would add some flexibility as to which output you wish to use.

Also I had a brief exchange with Tweakie on another thread which suggests that my original premise
for doing the whole thing in a macro is unnecessary.
The way he explained M10 and M11 to work is that they become active at the start of the next move.
Also the P~ argument is in milliseconds. A reasonable delay would put P500 for a half second delay.

M10 P500 ; the start signal is primed and waits for the next move
G01 X100 Y0 ; the spray starts 500ms after the move starts

Not entirely convinced this would work yet but worth experimenting some. Even if it does not sure that the same
strategy would work to turn the spray off.

Craig

My wife left with my best friend...
and I miss him!

#### chuck767

• 78
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #4 on: August 24, 2018, 09:39:28 AM »
I would like to use M10 and M11 For laser cutting acrylic signs.
I use master cam X5  and I’m wondering how I do the post processing to create the G code that would include M10/11  commands along with the P/delay command

Thanks,
Chuck

#### Tweakie.CNC

• 8,399
• Super Kitty
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #5 on: August 24, 2018, 10:47:59 AM »
I would like to use M10 and M11 For laser cutting acrylic signs.
I use master cam X5  and I’m wondering how I do the post processing to create the G code that would include M10/11  commands along with the P/delay command
Thanks,
Chuck

As far as I am aware no one has created a Mastercam Post Processor which supports the M11/M10 command set so you would be on your own and you would need some knowledge of how the Mastercam pp works.
If you decide to create your own Post Processor then your laser should be turned ON for all Feed-Rate moves and OFF for all Rapid Moves...
Basically, every Rapid Move (G00) should be prefixed with M10Px  and every Feed-Rate Move (G01,G02,G03) should be prefixed With M11Px ( where x is the Output# controlling your laser trigger ).

Hope this helps,

Tweakie.
KEEP SAFE !

#### chuck767

• 78
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #6 on: August 25, 2018, 01:15:15 AM »
Thanks Tweakie   Appreciate your input.
I thought I had already responded to this but apparently not.

I will not attempt to build a PPf for mastercam  so does that mean that I will have to manually put the M10 /11 Px  into the G code?

I saw a response  of yours on one of the forums were you were suggesting putting an autocad DXF file into lazy cam in order to get the proper post processing with the M codes.

I use solidworks and I suppose I could try putting a solid Works file in lazy cam to generate the Gcode.

What do you think?
Chuck

#### Tweakie.CNC

• 8,399
• Super Kitty
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #7 on: August 25, 2018, 01:59:34 AM »
Editing an existing Gcode is not that difficult. Using Notepad Replace function all Z+ moves can be replaced with M10Px and all Z- moves replaced with M11Px (x being the Output# used to trigger your laser).

LazyCam would also work, using the laser post processor, but LazyCam is a very basic program and does not always handle all .dxf files that well. You would just have to try it and see if it works for you.

Tweakie.
KEEP SAFE !

#### chuck767

• 78
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #8 on: August 25, 2018, 08:39:44 AM »
Thanks Tweakie,
Good point, editing existing code looks pretty easy  for these laser  commands.

FYI
if you have not downloaded it yet, Notepad++,  really works well for modifying code.

BTW
I Added air assist on my 150 W laser and WOW what a difference it makes.
initially I only had a slight airflow to keep the lens  clean, I upped it to 60 PSI.

Thanks again for your help,
Chuck

#### chuck767

• 78
##### Re: Help! How to write Macro for M11 and M10 in Mach3
« Reply #9 on: September 03, 2018, 05:53:49 PM »
Hi Tweakie

I was just reviewing your inputs and I have a question.

You provided two responses on how to use M 10/M 11 To control Laser power.

The first response related to G movements :
“If you  decide to create your own Post Processor then your laser should be turned ON for all Feed-Rate moves and OFF for all Rapid Moves...
Basically, every Rapid Move (G00) should be prefixed with M10Px  and every Feed-Rate Move (G01,G02,G03) should be prefixed With M11Px ( where x is the Output# controlling your laser trigger ).”

The second response related to Z movements:
“Editing an existing Gcode is not that difficult. Using Notepad Replace function all Z+ moves can be replaced with M10Px and all Z- moves replaced with M11Px (x being the Output# used to trigger your laser).”

Which method would you recommend?

Thank you,
Chuck