M-Function with parameter

Hi everyone!

I’m currently trying to replace a M-Function with a set variable with a function like expression.

Now:

MyVar = 500
M_MOVE_SOMETHING

Goal:

M_MOVE_SOMETHING[500]

I tried using the preprocessor replacements but I think that the “Is pattern” option there (which states “regular expression”) doesn’t understand matches / grouping.

If I configure

M_MOVE_SOMETHING\[[0-9]+\]

it will replace the string, but as soon as I add () to the expression, since I need to keep the number, it won’t even match anymore. “Unexpected open bracket”

M_MOVE_SOMETHING\[([0-9]+)\]

Anyone has another solution I could try to achieve my goal? (@michael.bertsch ? :slight_smile:)

Best regards!

With the help of @sven.toensjost ( :pray:) I found the following solution:

Create a new code for this in the mcipubr file:

<?xml version="1.0" encoding="UTF-8"?>
<Root LangModule="ailgcode" Version="1.0">
	<BuiltInProcs>
		<MOVE_SOMETHING MinArgs="1" MaxArgs="1">
			<!-- G172 -->
			#next_motion.Command = MPCMD_IP_SYNCH_PATH; 
    		PushPacket(::); 
    		DispatchAndWait(:IPCMD_SYNC_PATH_CONT:);
			<!-- Pass value and set M-Function -->
			%MyVar = $[1];
		    #next_motion.Command = MPCMD_SET_PREDEFINED_M_FCT;
		    #next_motion.Data.I4_value = 50; <!-- M NUMBER -->
		    PushPacket(::);
			DispatchMPList(::);
		</MOVE_SOMETHING>
	</BuiltInProcs>
</Root>

MyVar needs to be the already existing variable, to which the value should be written.
I also included the G172, since it’s required anyway…

Remaining:
How can I check if the argument is passed in th AIL code?
So if there is no parameter, I don’t want to set the variable value.

Best regards!

Hello Marcel,

I am not an expert for regular expressions so i can’t tell you if you aproach with the preprocessor replacements would be possible.

The G-Code File is read by the Interpreter.
There is a default Configuration from B&R for the System Statements. But we can insert coustom Configuration which can extend the Language the Interpreter can understand.
This allows us to use the more advanced text interpreter functionality which is based on Tokens and Expected Objects.

This is not the easiest Task as the Documation for this in AS-Help is not the easiest to read.

AIL-Configuration Files ARNC0
AIL-Language

The Template User Configuration Files can be found in an Zip-File in the McProgInt Library.
image
(Hint: The Package File in it is not Valid, so you can’t import it directly.)

  1. Use a CNC-Datamodul (CNC-Program) and rename it to the names for the Configuration File.

  2. Add them to the Software Configuration. (Names must match!)

  3. Declare the Variable in the mcipvar

<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
  <VARIABLES>
   <PV Synch="ip" Type="UDINT" Alias="MyVar">Test:MyVar</PV>
  </VARIABLES>
</CONFIG>

image
image
image

  1. Create a BuiltInProcs in the mcipubr
<?xml version="1.0" encoding="UTF-8"?>
<Root LangModule="ailgcode" Version="1.0">

	<!--****************************************************************************
    *
    *  Additional definitions for the G-code B&R language
    *
    ****************************************************************************-->

	<BuiltInProcs>
		<M_MOVE_SOMETHING MinArgs="1" MaxArgs="1">
		
			beginpathsynch
				%MyVar = $[1]; 
			endpathsynch
			
			<!-- Call M-Function --> 
			#next_motion.Command = MPCMD_SET_M_FCT;
			#next_motion.Data.I4_value = 50;
			PushPacket(::);
			
		</M_MOVE_SOMETHING>
	</BuiltInProcs>
		
</Root>
  1. You Cnc Programm looks now like this
    image

Greetings
Michael Bertsch

2 Likes

Thanks @michael.bertsch! Exactly what I was looking for and exactly the same as Svens approach! I guess the preprocessor can’t handle real regex :stuck_out_tongue:

Hello,

You can compare the two variants now… i think the G172 in Svens code is not nessesary if you use the Pathsynch Statment.

I try to prevent the G172 because mapp Motion currently can have stops up to 300 ms du to the hold of the interpreter and the emptying of the buffers … depending by the calculation power.


Short addition:
If you need to run more than one AxesGroupInstance you have to improve the AIL-Macros and check the current Instance. There is an function for it available.

Greetings
Michael

1 Like

That was my mistake then, I added the G172 :slight_smile:
Good to know, thanks for the hint, I’ll update this!

And I had the impression that, if I used MPCMD_SET_M_FCT, it was somehow “blocking” again, even if the M-function configured in the axis group is not! When I changed it to MPCMD_SET_PREDEFINED_M_FCT it works now.

Thanks again!

Hello,

This ist the default macro from B&R. So i rather not think is caused by the command.

Could it be that you reconfigured it and missed the restart after transfer?

Greetings
Michael

You’re right. I just gave it another try and it works fine!
There probably was something else wrong with my code back then!

Thanks a lot Michael!

My final solution:

          <MOVE_SOMETHING MinArgs="1" MaxArgs="1">
			beginpathsynch
				%MyVar = $[1];
			endpathsynch
		    #next_motion.Command = MPCMD_SET_M_FCT;
		    #next_motion.Data.I4_value = 50;
		    PushPacket(::);
		</MOVE_SOMETHING >
1 Like

Hello Marcel,
as i went back through the thread i found this requirement…

You can use the “Defined(::)” Function to check if a Parameter was set within the G-Code
If you set the MinArgs to 0 it can be used with empty brakets. But as far as i know it needs brakets.

MOVE_SOMETHING[]
        <MOVE_SOMETHING MinArgs="0" MaxArgs="1">
	       if (Defined(:$[1]:))		
               beginpathsynch
				%MyVar = $[1];
			endpathsynch
                   endif
		    #next_motion.Command = MPCMD_SET_M_FCT;
		    #next_motion.Data.I4_value = 50;
		    PushPacket(::);
		</MOVE_SOMETHING >

Greetings
Michael

1 Like