Task
A roundness measurement shall be performed for a working piece. The working piece is placed on a rotary disk, which is driven by an uncontrolled motor with a speed of 5 s/rotation. During this rotation 720 measurement values in 0,5°-steps shall be sampled.
An incremental encoder providing 3600 increments is placed in between the motor and the disk. The working piece is measured using two inductive probes.
The incremental encoder is connected to measurement input T12, the inductive probes are connected to T4 and T5.
Example "position-triggered dynamic measurement"
Preliminary considerations
Based on the resolution of the incremental encoder of 3600 increments / rotation and the step-size of 0,5°, the step-size between two samples is 5 increments.
Example-Code
// Write channel list 1 using the measurement channels T4 and T5
ansiString = “#1;T4;T5#”;
WriteCommandStr(opcWCL, ansiString);
if (ansiString != “#0#”) return -1; // An error occured: cancel starting measurement
// Define trigger:
// TriggerNo 1; position-triggered; trigger-channel = measurement channel T12; divisor = 1;
// step-size = 5; start = 0; end: * = without end
ansiString = “#1;P;T12;1;5;0;*#”;
WriteCommandStr(opcDT, ansiString);
if (ansiString != “#0#”) return -2; // An error occured: cancel starting measurement
// Define dynamic measurement 1:
// TriggerNo 1; channel list 1; dyn. measurement active; 720 measurement values
ansiString = “#1;1;1;720#”;
WriteCommandStr(opcDDM1, ansiString);
if (ansiString != “#0#”) return -3; // An error occured: cancel starting measurement
// Setup data transfer channel for dynamic measurement values
result = MSC_SetupExtendedDynamicChannel(pDevice, opcRDM1, 2, 1, NULL);
if (result != MSC_STATUS_SUCCESS) return -4;
// Allocate 2 buffers, each having a size of 720 * 4 Bytes = 2880 Bytes for the
// measurement values; assign these buffers to the MscDll
for (i = 0; i < 2; i++) {
buffer[i] = malloc(720*4);
result = MSC_AttachSubChannelBuffer(pDevice, opcRDM1, i, 720*4, &buffer[i]);
if (result != MSC_STATUS_SUCCESS) return -5;
}
// Activate trigger
ansiString = “#1#”;
WriteCommandStr(opcAT, ansiString);
if (ansiString != “#0#”) return -6; // An error occured: cancel starting measurement
// An error occured: cancel starting measurement
do {
result = MSC_GetPosition(pDevice, opcRDM1, &nSamples);
if (result != MSC_STATUS_SUCCESS) return -7;
Sleep(50); // Take a break for 50ms
} while (nSamples < 720);
// Inactivate trigger
ansiString = “#1#”;
WriteCommandStr(opcIT, ansiString);
// The measurement values are available now and can be used for further processing
Starting the dynamic measurement
A common problem with such measurements is the start of the dynamic measurement. In the example above, the start position 0 is expected. This works only, if the rotational disk is turned backwards, until the incremental encoder T12 has a negative value. This neither always possible, nor does it make sense.
In order to solve this problem, the position of the incremental encoder T12 can be set to a negative value by software. The function MSC_WriteCommand together with the opcode opcSP (0x35) must be used for this purpose. If the incremental encoder has an index signal, the following solution is a good choice:
a)Before starting the measurement, the position of the incremental encoder is set to a negative value, e.g. -100.000. Simultaneously the index evaluation is activated.
b)Measurement is started. The drive starts turning.
c)If the incremental encoder crosses the index signal, the position of the incremental encoder is set to 0. The dynamic measurement now starts sampling the measurement values.
Using the code example from above, the following code must be executed before activating the trigger:
// Set position of incremental encoder ("-100000") and activate index pulse ("REFON")
ansiString = “#T12;-100000;REFON#”;
WriteCommandStr(opcSP, ansiString);
if (ansiString != “#0#”) return -8; // An error occured: cancel starting measurement
For some applications this solution has the disadvantage, that the position of the incremental encoder is set to 0 again after 1 rotation (in the example 3600 incremenets). In case this is a problem, the index pulse can be deactivated during the measurement without affecting the position of the incremental encoder. In order to do this, the do-while-loop of the example must be changed as follows:
// An error occured: cancel starting measurement
flagOnce = true;
do {
result = MSC_GetPosition(pDevice, opcRDM1, &nSamples);
if (result != MSC_STATUS_SUCCESS) return -7;
if ((flagOnce == true) && (staticValueT12 > 0)) {
flagOnce = false;
ansiString = “#T12;*;REFOFF#”;
WriteCommandStr(opcSP, ansiString);
if (ansiString != “#0#”) return -9; // An error occured: cancel measurement
}
Sleep(50); // Take a break for 50ms
} while (nSamples < 720);
It is assumed that the static measurement is running in parallel. The variable staticValueT12 contains the measurement value T12, which is cyclically updated via static measurement.