Vijolica555
Member
Hi guys,
I am using TwinCAT 3 and I have a laser sensor that sends me data in Array. At the beginning of the measurement I run reference scan where I calculate mean value of 100 received arrays. In the moment we have some weird surface and received values in the array are sometimes very wrong. Idea is to change those values with next good value. So we set some limits what is bad and what is good. Unfortunately what i wrote for conditions, bad values are not changed with the NEXT good one but with the LAST good one. If i use WHILE loop instead the inner IF is not good. Any ideas what could be changed? Thank you.
I am using TwinCAT 3 and I have a laser sensor that sends me data in Array. At the beginning of the measurement I run reference scan where I calculate mean value of 100 received arrays. In the moment we have some weird surface and received values in the array are sometimes very wrong. Idea is to change those values with next good value. So we set some limits what is bad and what is good. Unfortunately what i wrote for conditions, bad values are not changed with the NEXT good one but with the LAST good one. If i use WHILE loop instead the inner IF is not good. Any ideas what could be changed? Thank you.
Code:
nHeight := REAL;
nTolerance := REAL
j := INT;
n := INT;
ArrLen := INT;
arrReceive := : ARRAY [0..ArrLen] OF REAL;
Code:
FOR j:=0 TO ArrLen DO
IF (arrReceive[j] < nHeight*(1-nTolerance)) OR (arrReceive[j] > nHeight*(1+Tolerance)) THEN
FOR n := j+1 TO ArrLen DO // find next value that meets the conditions
IF (arrReceive[n] > nHeight*(1-nTolerance) AND arrReceive[n] < nHeight*(1+nTolerance)) THEN
arrReceive[j] := arrReceive[n]; //value that meets the conditions is writen in the j value that didnt meet the conditions
END_IF
END_FOR
ELSE arrReceive[j] := arrReceive[j];
END_IF
END_FOR