MLProfileBuild
Function - Creates a CAM Profile from application data that can be executed by a CAM block in Pipe Network or PLCopen.
Inputs
Input |
Data Type |
Range |
Unit |
Default |
Description |
---|---|---|---|---|---|
Enable |
BOOL |
FALSE, TRUE |
N/A |
No default |
Enables execution. Starts on the rising edge. |
Cam_Props |
CamProps_ref |
No range |
N/A |
No default |
Structures containing the CAM Profile properties. |
Cam_Data |
CamData_ref |
N=3 to 20,000 elements |
N/A |
No default |
Array of structures containing the CAM Profile data. |
CamDataCount |
UINT |
3 - 20,000 |
Elements |
No default |
Number of elements in the Cam_Data array to be used. |
ProfileID |
DINT |
-2147483648 to 2147483647 |
N/A |
No default |
ID number of an initialized CAM Profile. |
Cyclic |
BOOL |
FALSE, TRUE |
N/A |
No default |
|
Options |
INT |
|
N/A |
No default |
Describes the combinations of segments that can be used to build a cam profile. |
Outputs
Output |
Data Type |
Range |
Unit |
Description |
---|---|---|---|---|
Done |
BOOL |
FALSE, TRUE |
N/A |
Indication of whether or not the profile was successfully compiled and built. |
Busy |
BOOL |
FALSE, TRUE |
N/A |
Indication that the function block is executing.
|
Err |
BOOL |
FALSE, TRUE |
N/A |
Indication that the function did not execute correctly. ErrorID output is valid and indicate the reason. |
ErrorID |
INT |
No range |
N/A |
Indicates the reason for the failure. See the Error Codes table. |
ErrorElem |
UINT |
No range |
N/A |
The array element number of the CAM data where an error is detected. |
Remarks
- This function block takes input as CAM data and CAM Profile properties from application data memory and compile the input data to a form the controller can use to calculate cam positions.
- See CAM Profile Editor's CAM Table for information.
- The input CAM data and CAM Profile properties are similar to the CAM data entered in the IDE’s CAM Editor and the runtime’s CAM Profile Properties dialog.
MLProfileBuild internally performs these functions:
- Compile the CAM data (like the cam editor performs in the IDE).
- Puts the compiled profile into the profile object so it can be used by other Profile Function Blocks.
Provides similar functionality to MLProfileInit.
-
-
Prior to using MLProfileBuild, you must call MLProfileCreate to create the profile object.
The ID output of MLProfileCreate is used as theProfileID
input to MLProfileBuild.
MLProfileCreate must be performed in the application before the MLMotionStart command is executed.
- MLProfileBuild compiles the CAM Profile data specified at the
CamData
input and writes the resulting profile to the CAM Profile object specified at inputProfileID
. - The created profile can be used as an input to PLCopen CAM Function Blocks (e.g., MC_CamTblSelect, MC_CamIn, MC_CamOut), or any Pipe Network CAM Profile Function/Function Blocks.
- When the operation is complete, the
Done
output is high.- If an error is encountered, the
Error
output is high and theErrorID
output returns an error code. - If the Error can be attributed to a specific profile element in the
CamData
array,ErrorElem
attempts to indicate the element in error.
- If an error is encountered, the
CamProps_Ref Structure
See Master/Input offset about the parameters which transform the CAM Profile.
The CAM properties structure (CamProps_Ref) contains these data members:
Parameter |
Type |
Description |
---|---|---|
InputScale |
LREAL |
The input amplitude or master axis multiplier applied to the CAM Profile. |
OutputScale |
LREAL |
The output amplitude or slave axis multiplier applied to the CAM Profile. |
InputOffset |
LREAL |
input offset or master axis shift applied to the CAM Profile. |
OutputOffset |
LREAL |
The output offset or slave axis shift applied to the CAM Profile. |
CamData_Ref Structure
The Cam_Data function block input is an array of CamData_Ref structures.
Each element of the structure contains these data members:
Parameter |
Type |
Description |
---|---|---|
Accel |
LREAL |
CAM_SEGMENT_TYPE_POINT
CAM_SEGMENT_TYPE_LINE and CAM_SEGMENT_TYPE_PARABOLIC
|
MasterIn |
LREAL |
Master position (in the unit range [0 - InputScale]). |
SegType |
UINT |
Defines the segment type for the segment following the master positions defined by MasterIn.
See Cam Profile Segment Overview about the segment types. |
SlaveOut |
LREAL |
Slave position (in the unit range [0 - OutputScale]). |
Vel |
LREAL |
CAM velocity at the master position specified by MasterIn. Units: |
- The type of the Nth CAM segment is defined by the Nth Cam_Data element.
- The CAM is constructed with one less segment than the Cam_Data elements.
- The last element's SegType is not used.
- See CAM Profile Editor's CAM Table.
Figure 1: MLProfileBuild Cam Segments graph
Error Codes
-
-
If Cyclic is TRUE and the Vel/Accel of the first and last elements do not match, MLProfileBuild automatically copies the first element's Vel/Accel to the last element's.
A log warning message is posted indicating that this change has occurred.
ErrorID |
Description |
---|---|
100 |
The |
101 |
Invalid master or slave scale. The scale cannot be less than zero. |
102 |
Element master or slave position is outside the range defined by |
103 |
A segment type was specified that is not supported by the value of the |
104 |
Master position of an element is too close to the master position of a previous element.
|
106 |
Invalid ProfileID. This can occur if the ProfileID:
|
107 |
|
108 |
Profile cannot be released because it is in use by the motion engine or currently selected by an active CAM block. |
109 |
Attempting to build a profile already containing elements. Profile needs to be released first using MLProfileRelease. |
110 |
The controller is running low on memory and could not allocate memory to hold the cam table data. |
111 |
The minimum allowed value is 3. |
112 |
CAM_PROFILE_OPTION_PARABOLIC
|
113 |
CAM_SEGMENT_TYPE_PARABOLIC
Figure 2: MLProfileBuild Cam Velocity Profile graph |
200 |
First element's |
201 |
Last element's |
202 |
Cannot modify the first element in the cam element table.
|
203 |
Cannot modify the last element in the cam element table.
|
Example: Use MLProfileBuild
This example has these procedure steps:
1. Create a Profile
-
- Prior to using MLProfileBuild, you must first create a profile.
This must be done prior to MLMotionStart.
// Allocate space for a profile that will be built later
profileID := MLProfileCreate('ProfileName');
2. Define the Profile Data
- Create an array of CamData_Ref structures in the data dictionary.
- Enter each of the elements into that newly created structure.
In this example,ProfileData
is the name of the CamData_Ref structure.
// Define the profile data ProfileData[0].MasterIn := 0.0; ProfileData[0].SlaveOut := 180.0; ProfileData[0].SegType := CAM_SEGMENT_TYPE_POINT; ProfileData[0].Velocity := 0.0; ProfileData[0].Acceleration := 0.0; ProfileData[1].MasterIn := 180.0; ProfileData[1].SlaveOut := 324.0; ProfileData[1].SegType := CAM_SEGMENT_TYPE_POINT; ProfileData[1].Velocity := 0.5; ProfileData[1].Acceleration := -0.025; ProfileData[2].MasterIn := 360.0; ProfileData[2].SlaveOut := 240.0; ProfileData[2].SegType := CAM_SEGMENT_TYPE_POINT; ProfileData[2].Velocity := 0.0; ProfileData[2].Acceleration := 0.0;
3. Define the Profile Properties
- Create a CamProps_Ref structure in the data dictionary.
- Enter each of the properties into the newly created structure.
In this example,ProfileProps
is the name of the CamProps_Ref structure.
// Define the profile properties ProfileProps.InputScale := 360.0; // Must be Positive! ProfileProps.OutputScale := 360.0; // Must be Positive! ProfileProps.InputOffset := 0.0; ProfileProps.OutputOffset := 0.0;
4. Call the MLProfileBuild Function Block
Use the IEC language of choice.
As part of this call it is recommended that you validate the Done
and Error
output before proceeding.
// Build the profile Inst_MLProfileBuild( TRUE, ProfileProps, ProfileData, 3, ProfileID, TRUE, CAM_PROFILE_OPTION_DEFAULT);
5. Use the New Profile
After verifying that MLProfileBuild is Done
and there are no errors, you can use the newly generated profile.
The next step depends on the motion engine in use.
- PLCopen: call MC_CamTblSelect.
- Pipe Network: call either MLCamInit or MLCamSwitch.
-
- Pipe Network: To correctly set the CAM scales and offsets (defined by the Cam_Props argument) MLPrfWriteIScale, MLPrfWriteOScale, MLPrfWriteIOffset and MLPrfWriteOOffset must be called before calling MLCamSwitch.
// Switch Pipe Network Profile MLPrfWriteIScale(profileID, ProfileProps.InputScale); MLPrfWriteOScale(profileID, ProfileProps.OutputScale); MLPrfWriteIOffset(profileID, ProfileProps.InputOffset); MLPrfWriteOOffset(profileID, ProfileProps.OutputOffset); MLCamSwitch(PipeNetwork.CAM, profileID);
Example: Building a Parabolic Cam Profile
To build a parabolic CAM Profile, your CAM data elements must use CAM_SEGMENT_TYPE_PARABOLIC
or CAM_SEGMENT_TYPE_LINE
when defining the cam data array.
// Define the profile data ProfileData[0].MasterIn := 0.0; ProfileData[0].SlaveOut := 0.0; ProfileData[0].SegType := CAM_SEGMENT_TYPE_PARABOLIC; ProfileData[0].Velocity := 0.0; ProfileData[0].Acceleration := 0.5; ProfileData[1].MasterIn := 50.0; ProfileData[1].SlaveOut := 150.0; ProfileData[1].SegType := CAM_SEGMENT_TYPE_LINE; ProfileData[1].Velocity := 5.0; ProfileData[1].Acceleration := 0.0; // Not used ProfileData[2].MasterIn := 55.0; ProfileData[2].SlaveOut := 175.0; ProfileData[2].SegType := CAM_SEGMENT_TYPE_PARABOLIC; ProfileData[2].Velocity := 5.0; ProfileData[2].Acceleration := 0.0; // No limit to the acceleration rate of the segment. ProfileData[3].MasterIn := 105.0; ProfileData[3].SlaveOut := 250.0; ProfileData[3].SegType := CAM_SEGMENT_TYPE_PARABOLIC; ProfileData[3].Velocity := 0.0; ProfileData[3].Acceleration := 0.5; ProfileData[4].MasterIn := 225.0; ProfileData[4].SlaveOut := 125.0; ProfileData[4].SegType := CAM_SEGMENT_TYPE_PARABOLIC; ProfileData[4].Velocity := -10.0; ProfileData[4].Acceleration := 0.5; ProfileData[5].MasterIn := 360.0; ProfileData[5].SlaveOut := 0.0; ProfileData[5].SegType := CAM_SEGMENT_TYPE_PARABOLIC; // Not used ProfileData[5].Velocity := 0.0; ProfileData[5].Acceleration := 0.0; // Not used
- When calling the MLProfileBuild function block, verify
CAM_PROFILE_OPTION_PARABOLIC
is specified for the Option argument: in the IEC language of choice. - As part of this call, it is recommended that you validate the Done and Error output before proceeding.
// Build the profile
Inst_MLProfileBuild( TRUE, ProfileProps, ProfileData, 3, ProfileID, TRUE, CAM_PROFILE_OPTION_PARABOLIC);
FBD Language Example
FFLD Language Example
IL Language Example
Not available.
ST Language Example
// Build the profile Inst_MLProfileBuild( TRUE, ProfileProps, ProfileData, 3, ProfileID, TRUE, CAM_PROFILE_OPTION_DEFAULT);
See Also