Floating point position calculation imprecision drift

Kataeb

Member
Join Date
Jan 2007
Location
www.livelovelebanon.com
Posts
631
I need to check an axis actual travel position, and to compare it to the master travel position.
To do this I have to multiply the axis travel position by the strange ratio of 36/21 , and then add the result to the total calculated value.
This happens at every scan of the plc program, and so I slowly lose the digits after the 7th one. After some time, I notice some differences that are coming from these calculations.
The used Rockwell plc has 7 digits precision for real data type.
36 / 21 = 1.7142857 . . .
 
1) use LREAL. This kicks the can down the road, but it may be far enough down the road to solve the problem.

OR

2) scale the master travel position, presumably a REAL, to an integer (scale by 21/36),
2.1) do the addition in the integer domain,
2.3) and execute the comparison in the integer domain.

OR

3) maintain an integer [leftover] quantity, initialized to 0, then on each scan
3.1) increase measured [per-scan axis travel] by [leftover]
3.2) calculate [per-scan axis travel MODULO 21], save it in [leftover]
3.3) decrease [per-scan axis travel] by [leftover]
3.4) scale [per-scan axis travel] by 36/21 into REAL
3.5) add scaled REAL result to [total calculated value, REAL]
3.6) As long as total calculated value does not exceed 16,777,216, there will be no loss of precision.
 
Last edited:
I have to multiply the axis travel position by the strange ratio of 36/21

This looks like there could be a gearbox or toothed belt in the system with this ratio.

I have used the first method suggested by drbitboy with success. Once you get used to working in counts inside the program it is a much easier way to go. The master position is always in counts and you only do a conversion to REAL do display the position for the operator
 
I would probably do that with integers, and adding the remainder of the previous division to the next division, so the smallest variations are not lost
 
Based on your suggestions, I reached the following solution, which worked well on the simulator, to be tried on the real machine.

MasterCalcDeg = (MasterActDeg * 21) modulo 360
SlaveCalcDeg = (SlaveActDeg * 36) modulo 360
DiffCalcDeg := (MasterCalcDeg - SlaveCalcDeg) / 21
SlaveFinalDeg := MasterActDeg - DiffCalcDeg

Thank you all ...
 

Similar Topics

We have AOIs for projects, which handle material dosing (by hand or by pipes and pumps), obviously they have comparison between setpoint and...
Replies
50
Views
14,181
Hi eveyone. I need transfer signal from system 1 to DCS via modbus. System 1 only can send 32 bit floating point. DCS receive 16 bit integer. How...
Replies
20
Views
10,538
Hi, In my ladder logic, I've got a data register D60 whose value is -0.001 (when using monitor mode to see values). D406 is 0.250. But then...
Replies
5
Views
1,297
Hi, can anybody tell that how can we move floating point data from one Regiter to another register in Fatek PLC.?
Replies
0
Views
1,538
PLC: 1769-L35E Firmware: 16.24 RSLogix 5000 Full Edition V16.06.00 (CPR 9) I'm trying to fix someone else's FBD program that calculates motor...
Replies
15
Views
4,024
Back
Top Bottom