Calculation of the Distance of Two Point of the Cartesian Coordinate System
How can I calculate the distance "D" between two points in a rectangular system of coordinates with STEP 7?
Enclosed sample program implements the calculation of distance "D" between two points in a rectangular system of coordinates. The calculated distances (return value "RET_VAL") are saved one after the other in a data block. The program in FC10 consists of two parts:
- Part 1:
For the calculation of distances between both points FC10 expects coordinates X1 and Y1 for point 1 and coordinates X2 and Y2 for point 2 of input parameters. Output parameter RET_VAL returns the calculated distance between two points. The input tags X1, X2, Y1 and Y2 as well as output tag RET_VAL are of type REAL.
Fig. 1: Calculation of Distance "D" between Point 1 and Point 2
- Part 2:
Here the values of RET_VAL (calculated distances) are saved in the data block DB10. DB10 has 10 addresses (DB10.DBD0, DB10.DBD4, ...). Every address is reserved for one RET_VAL. If the address already is filled with a RET_VAL, the new (modified) Ret_Val is entered in the next address. In FC10 the query is run first as to which address of DB10 is free next. When it is found, the new current RET_VAL is written in this address (except for value 0) and this program is finished.
The entered value RET_VAL is not overwritten, and the next new, changing value RET_VAL is then written into the next address. If all 10 addresses of DB10 are occupied, in FC10 a reset must be done. All addresses in DB10 are then set to zero.
FC10 is called in OB1 and parametrized as follows:
Fig. 2: Calling FC10 in OB1
The enclosed download contains the STEP 7 Project with the above mentioned block to calculate the distance "D" between two points in a rectangular system of coordinates.
Copy file "Distance_Coor.exe" into a separate directory and then start the file per double click. The STEP 7 V5.2 project is now automatically unpacked with all related sub directories. Subsequently you can open and edit the unpacked project with the SIMATIC Manager.
Runtime Ability and Test Environment:
The example can be used on all CPU Variants of the SIMATIC S7-300, S7-400 , C7 and WinAC.
In the following table the components are listed, with which this entry was created and the feature described above was verified:
|PC System||PG 740 Pentium III|
|PC Operating System||Microsoft Windows 2000 SP3|
|STEP 7||STEP 7 V5.2 SP1|
|Options Package||S7-PLCSIM V5.2|
- You have a technical question / problem: Ask the Technical Support
- You want to discuss in our forum and exchange experiences with other users
- You want to create CAx data for one or more products
- You would like to send us feedback on this Entry