Macro programs in KMotionCNC

Moderators: TomKerekes, dynomotion

Post Reply
Alexanders
Posts: 27
Joined: Wed May 03, 2023 12:54 am

Macro programs in KMotionCNC

Post by Alexanders » Fri May 03, 2024 12:53 pm

Does KMotionCNC support macro programming on Macro B ?
I am trying to apply operators such as IF, WHILE .... However, KMotionCNC produces various syntax-related errors.

User avatar
TomKerekes
Posts: 2561
Joined: Mon Dec 04, 2017 1:49 am

Re: Macro programs in KMotionCNC

Post by TomKerekes » Fri May 03, 2024 7:41 pm

Hi Alexanders,

No 'IF' and 'WHILE' aren't supported. But the similar functionality can be achieved with looping subroutine calls. See the example SubroutineWithConditionals.ngc shown below:

Code: Select all

G20
#100 = 5

(examples of logical operations)
(result is 1 if condition is true)
(result is 0 if condition is false)

#101 = [#100 >  5]
#102 = [#100 >= 5]
#103 = [#100 <  5]
#104 = [#100 <= 5]
#105 = [#100 =  5]
#106 = [#100 <> 5]

(subroutine call can be looped a number of times)
(the L or Q word may be used to specify the count)
(if neither L or Q is specified a count of 1 is used)
(if the count is 0 the subroutine will not be called at all)

M98 P1 L3  (example using L to specify the loop count)
M98 P1 Q3  (example using Q to specify the loop count)

M98 P1 L#100  (example using a variable loop count)

M98 P1 L[5 > 4]  (example using a conditional as a loop count)
M2

O1
#200 = [#200+1]
M99
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply