Drive Configuration
The drive configuration sample provides an example how to change the drive parameters during runtime. A lot of times only a small portion of parameters needs to be changed out of the structure. Since the complete structure is written every time it is recommended to read the structure first, then copy the data to the parameter structure, change the parameters and then write the changes back to the drive. After changing the drive parameters the PLC must be reboot for the changes to take affect. The function block MC_BR_ProcessConfig used in this example does not check parameter values for correctness. It is therefore necessary to check the axis for errors after writing new parameters through the PLC logger or the function block MC_ReadAxisError.
![]() |
![]() |
Also see
- Automation Studio help for a description of MC_BR_ProcessConfig (9c2eadae-8494-4e9a-b305-0afa2dabf1d4)
- Automation Studio help for changing ACOPOS settings at runtime (5b68d099-f8aa-45de-9c86-e8e8f3907850)
Repo Link
Here is the link to the repository.
Interface structure
The sample uses a variable structure to communicate with the outside world that can also be used to interact with other tasks. The structure looks as follows:
Parameter | Function |
---|---|
CmdSetDrive | Set the new drive parameters |
CmdGetDrive | Get the active drive parameters |
CmdReboot | Reboot PLC |
MpLink | The axis reference establishes the connection between the function block and an axis |
ParDrive | Parameters for the set command |
StaDrive | Parameters for the get command |
ErrId | Error ID |
Error handling
The sample generates the following list of error messages. All other error numbers are generated from included libraries that can be found in the Automation Studio help.
No | Constant | Text |
---|---|---|
10000 | ERR_AXISDRIVECFG_LOC_EMPTY | Axis location is empty |
10001 | ERR_AXISDRIVECFG_LOC_INVALID | Axis location is invalid |
10002 | ERR_AXISDRIVECFG_AX_FEATURE | Axis feature configuration is invalid |
Program structure
![]() |
The drive parameter can be outsourced into an extra file with just the drive parameters. This has the advantage that the drive configuration can be changed easily without changing any source code in the proto type. |
The program consists of a state machine to execute the commands. The B&R function block that changed the motor configuration needs a name path and not just the MpLink. This name is constructed automatically in the step STATE_DRIVE_CFG_PRE_SET. From this step the state machine goes to the read or write state. The drive parameter can be provided as a separate file and action (see example). It is also possible to set the parameters directly in the structure ParDrive.
After changing the drive parameters the PLC must be reboot for the changes to take affect.
Sample code
Here is a sample snippet that can be used as a starting point.
Program init
PROGRAM _INIT
// --------------------------------------------------------------------------
// Drive configuration
AxisDriveCfg.MpLink := ADR(gAxis_1); // MpLink for axis
END_PROGRAM
Program cyclic
// --------------------------------------------------------------------------
// When drive configuration command was triggered
// - Read configuration first to get all actual values
// - Copy the actual values into the parameter structure to get a template
// - Overwrite the parameters that need to be changed
// - Trigger drive configuration write command
// - Reset local write command when done
IF EDGEPOS(cmdChangeDriveConfig) THEN
AxisDriveCfg.CmdGetDrive := TRUE;
END_IF
IF EDGENEG(AxisDriveCfg.CmdGetDrive) THEN
IF cmdChangeDriveConfig THEN
brsmemcpy(ADR(AxisDriveCfg.ParDrive), ADR(AxisDriveCfg.StaDrive), SIZEOF(AxisDriveCfg.ParDrive));
AxisConfigSample; // Drive sample configuration
AxisDriveCfg.CmdSetDrive := TRUE; // Set changed parameters
END_IF
END_IF
IF EDGENEG(AxisDriveCfg.CmdSetDrive) THEN
cmdChangeDriveConfig := FALSE; // Reset local command
END_IF
AxisDriveCfgAction; // Call drive configuration action used for this drive
Revision
Version 3
- Update mappMotion to 5.24
- Removed obsolete hardware
- Added axis feature pointer auto correction
Version 2
- Removed dependency from common
- New internal structure
Version 1
- First release