Jump to content
Sign in to follow this  
chand345

The best way to perform complicated calculations

Recommended Posts

Hi everyone,

We were given a lot of calculations to perform based off of the input values from our sensors. These calculations include square roots, arc tans, etc. as well as decimal constants such as 0.3874638 for example. We've tried to scale all our numbers so we can work with everything in integers but the function on the screen is getting very large and complicated. Performing these calculations in coding languages like python would be very straightforward. I'm wondering if there is a simpler way in unilogic to perform these large calculations or any tips to keep our screen from becoming so full that it will be impossible to debug errors.

Thanks!

Share this post


Link to post
Share on other sites

You can use the "Formula" feature. (Look it in the solution explorer).

You can create a formula, and then use it in ladder (using the formula element) and pass the parameters.

 

One note about the calculation: When you divide numbers, if both numbers are integer then the result would be integer (unless some other part in the formula forced the number to be converted to float).

This means that 5 / 3   (or A /B, if both A and B are integers and have the values 5 and 3 accordingly) would result 1 and not 1.6666666666666

This is how other programming languages work, and people tend to hit that issue and tell that the formula doesn't work properly.

 

As I said, there are cases when the division will be calculated as float division. If one or more of the numbers is a float then it will force it to be a float division.
I think that if the result is also a float , meaning you define A / B where A and B are integers, but you also define that the result tag is of type of float (but don't take my word on this).

 

An easy way to force float calculation is to write 5.0 instead of 5 (for example), or when you divide 2 integer parameters, then write: A * 1.0 / B

This way you are forcing the division to be in float.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...