RSLogix Math/Floating Point Issues

Dan123

Member
Join Date
Sep 2014
Location
California
Posts
17
I'm working on a math-heavy project on CompactLogix L45 (Rev. 20) and am running into some issues with a calculation to determine the angle between two vectors. Is there any way to do floating point calculations with more than 9 significant digits in RSLogix5000?

Here's some background. I am trying to make two planes as parallel as possible with each other -- and I am considering them "aligned" when the angle between them is around 0.005 degrees (ideally I'd want to be able to measure up to 0.001 degrees). However, due to floating point limitations, RSLogix is restricting me to a resolution of 0.05 degrees.

The reason I am so limited is because I am using the equation "arccos(A.B/|A|*|B|)" to determine the angle (where the numerator is the dot product of the vectors and the denominator is the product of the vector magnitudes). With arccosine, my numerator and denominator can be exactly the same until the 8th or 9th digit, but a difference in that 9th digit can lead to a completely different result.

An example:

If I take arccos(176250000000000000/176250000090000000), where everything is equal until the 11th digit -- the result is 0.001831 degrees. This is where I want my accuracy to be, so if we assume that 11th digit is garbage I'm still off by about 0.002 degrees at most. But if we assume that 10th digit is garbage: arccos(176250000000000000/176250000990000000) = 0.0061 degrees. And if we assume the 9th digit is garbage: arccos(176250000000000000/176250009990000000) = 0.0193 degrees.

So basically I need that 10th digit of accuracy (would be nice to have more), but it appears that RSLogix floating point can only give me 8 or 9 (per IEEE 754).

There's a LREAL data type in the documentation, but I do not have it as a predefined data type, and can hardly find any additional documentation about this (looks like Micro800s have it, if only I had such a high-end PLC). Is it possible to perform floating point calculations (arccosine) on LINT tags? Is there any other way to get this precision?
 
Is there any way to do floating point calculations with more than 9 significant digits in RSLogix5000?
I wrote an integral calculation routine for 8085 cpu using just assembler, 15 years ago. So I suppose it's possible to write 64bits math on Logix. However, it could be a long task and it's difficult to say if the final code will be efficient.

In any case, wait for other opinions: maybe another user has saved a magic trick in the toolbox.

There's a LREAL data type in the documentation, but I do not have it as a predefined data type, and can hardly find any additional documentation about this (looks like Micro800s have it, if only I had such a high-end PLC). Is it possible to perform floating point calculations (arccosine) on LINT tags? Is there any other way to get this precision?

TN677451 LREAL data type size (Access Level: Everyone)

There is no LREAL datatype available for general programming. At the moment there are no plans to add LREAL support to Studio 5000 software.
 
Seems like you are doing a difficult calculations that lose precision when you don't need too. For one, why calculate the arcos of the number? If you don't need the number, but are only comparing the number to see if you are at a small enough angle, then rather than seeing if the if arcos(x) < 0.005, see if X > cos(0.005). Next, simple things down even further. Rather than calculate the length of A and B, use the quadrance of A and B. The formula simple down to A.B/Q(A)*Q(B) > cos(.005)^2. With this formula you don't need to calculate square roots or arcos.
 
Seems like you are doing a difficult calculations that lose precision when you don't need too. For one, why calculate the arcos of the number? If you don't need the number, but are only comparing the number to see if you are at a small enough angle, then rather than seeing if the if arcos(x) < 0.005, see if X > cos(0.005). Next, simple things down even further. Rather than calculate the length of A and B, use the quadrance of A and B. The formula simple down to A.B/Q(A)*Q(B) > cos(.005)^2. With this formula you don't need to calculate square roots or arcos.

Man, a trigonometry class broke out in here today....🍺
 
Seems like you are doing a difficult calculations that lose precision when you don't need too. For one, why calculate the arcos of the number? If you don't need the number, but are only comparing the number to see if you are at a small enough angle, then rather than seeing if the if arcos(x) < 0.005, see if X > cos(0.005). Next, simple things down even further. Rather than calculate the length of A and B, use the quadrance of A and B. The formula simple down to A.B/Q(A)*Q(B) > cos(.005)^2. With this formula you don't need to calculate square roots or arcos.

I run into the same issue with cosine that I do with arccosine, except instead of acos(0.99999999) resulting in 0, cos(0.005) will result in 1. I've tested this, and it loses accuracy below 0.05 degrees, and by 0.015 it just rounds to 1.

For the vector calculations -- I haven't even heard of quadrance, but I will definitely look into this -- it looks like you're still do the dot product though, so I will continue to run into precision issues there. I also found LINT math functions from the Rockwell support site, so I think I can this part of my problem working.

I'm beginning to think that implementing a lookup table for angles below 0.05 degrees would be the easiest way to solve the cosine/arccosine issue.
 
I don't think you'll be able to do this with 32-bit FP math no matter how you do it. Quadrance thing is a good idea, but even so, cos(.005) = 0.999999996192282 which will be recognized as 1 in 32-bit FP (which is really only good to 6-7 digits). Have any nearby hardware that can do 64-bit FP math? :/
 
For the vector calculations -- I haven't even heard of quadrance, but I will definitely look into this

Quadrance is the sqare of length.

Depending on how the vector are measured, you may be able to use DINTs to have more accuracy. Some other tricks could be used as well. For instance, instead of dividing two very large numbers that are relatively close together, The smaller could be subtracted from the larger, then the magnitude could be compared.
 

Similar Topics

Hello everybody I'm new to plc programming and i'm trying to program some simple math operations to convert some measurments for a project. The...
Replies
8
Views
5,597
Hi Gurus I have an issue with 2 similar programs. One faults and the other doesnt. When i enter a number on the HMI larger than 546 ( MUL x 60 =...
Replies
3
Views
3,409
Hi my problem may have a simple solution but i cant work it out. I need to use the Divide function but it wont let me use a decimal point in...
Replies
3
Views
1,742
Hi I need help solving this Fault Code 20h (Math Overflow Trap S5:0). I download the code into the ML 1400 PLC. When choosing RUN it gives me a...
Replies
22
Views
17,221
I am trying to use the CPT instruction and apparently I can't quit get it right. I am trying to accomplish this equation. (( N25:4 * 1000 ) +...
Replies
10
Views
2,922
Back
Top Bottom