chand345 Posted June 18, 2019 Report Share Posted June 18, 2019 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! Link to comment Share on other sites More sharing options...
Saragani Posted June 19, 2019 Report Share Posted June 19, 2019 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now