Call Function (FC)
A function is called by specifying the function name (FC, SFC identifier) and the parameter list. The function name that identifies the return value can be specified in absolute or symbolic form:
FC31 (X1:=5, Q1:=Checksum); // Absolute form
DISTANCE (X1:=5, Q1=:Checksum); // Symbolic form
After calling, the result of the function is available as return value or as output and input/output parameters (actual arguments).
In contrast to function blocks, functions provide a result as a return value. For this reason, functions can be treated as addresses (except for functions of type VOID).
A function computes a return value with the same name as the function, and returns it to the block that called it. There, the value replaces the function call.
For example, in the following assignment, the DISTANCE function is called and the result is assigned to the LENGTH variable.
LENGTH:= DISTANCE (X1:=-3, Y1:=2);
Return values can be used in the following function or function block elements:
-
In an assignment statement,
-
In a logical, arithmetic, or comparison expression or
-
As parameter for further function blocks or function calls.
Function Parameters
In contrast to function blocks, functions do not have any memory in which they store parameter values. Local data is only temporarily stored when the function is activated. For this reason, when calling a function, all formal input, in/out and output parameters defined in the function declaration must be assigned actual parameters.
Example
The call with assignments for input, output and in/out parameters is as follows:
FC32 (E_Pa1:=5,D_Param1:=LENGTH,
A_Param1:=Checksum)
Function call example:
Function to be called
The function DISTANCE that calculates the distance between two points (X1, Y1) and (X2, Y2) in the same plane using a Cartesian coordinate system can be of the following form (this example assumes that the symbol DISTANCE has been declared in the symbol table as FC37).
FUNCTION DISTANCE: REAL
// 符号
VAR_INPUT
X1 : REAL;
X2 : REAL;
Y1 : REAL;
Y2 : REAL;
END_VAR
VAR_OUTPUT
Q2 : REAL;
END_VAR
BEGIN
开始
DISTANCE := SQRT( (X2-X1)**2 + (Y2-Y1)**2 );
Q2 := X1+X2+Y1+Y2;
END_FUNCTION
Calling Block
The following example shows some alternative forms of using function values:
FUNCTION_BLOCK CALL
VAR
LENGTH : REAL ;
CHECKSUM : REAL ;
RADIUS : REAL;
Y : REAL;
END_VAR
BEGIN
. . .
// Call in an assignment statement:
LENGTH := DISTANCE (X1:=3, Y1:=2, X2:=8.9, Y2:= 7.4, Q2:=CHECKSUM) ;
// Call in an arithmetic or logical expression, e.g.:
Y := RADIUS + DISTANCE (X1:=-3, Y1:=2, X2:=8.9, Y2:=7.4, Q2:=Checksum)
// For parameterizing further called blocks
FB32.DB32 (DIST:= DISTANCE (X1:=-3, Y1:=2, X2:=8.9, Y2:=7.4), Q2:=Checksum)
. . .
END_FUNCTION_BLOCK
Reviewing Editor: Li Qian
Previous article:What are the capabilities of the 25kg large-load collaborative robot that was first put into mass production?
Next article:Kasite 4060 ER-S丨Industrial Robot Automotive Parts Cutting Processing Spindle One Axis Universal
- Popular Resources
- Popular amplifiers
- Using IMU to enhance robot positioning: a fundamental technology for accurate navigation
- Researchers develop self-learning robot that can clean washbasins like humans
- Universal Robots launches UR AI Accelerator to inject new AI power into collaborative robots
- The first batch of national standards for embodied intelligence of humanoid robots were released: divided into 4 levels according to limb movement, upper limb operation, etc.
- New chapter in payload: Universal Robots’ new generation UR20 and UR30 have upgraded performance
- Humanoid robots drive the demand for frameless torque motors, and manufacturers are actively deploying
- MiR Launches New Fleet Management Software MiR Fleet Enterprise, Setting New Standards in Scalability and Cybersecurity for Autonomous Mobile Robots
- Nidec Drive Technology produces harmonic reducers for the first time in China, growing together with the Chinese robotics industry
- DC motor driver chip, low voltage, high current, single full-bridge driver - Ruimeng MS31211
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Can RTthread be ported to nrf51822?
- I want to control the on and off of NMOS through a 3.3V microcontroller
- Domestic FPGA brand Anlu
- The load is a 3000W heating plate, controlled by two 16A relays
- "Detailed Explanation of Embedded Linux System Development Technology--Based on ARM (Full Version)" e-book free
- Essential controlSUITE Software Suite for C2000 Microcontrollers
- [National Technology N32 MCU Development Package] --N32G031 Series
- If signal modulation was like this back then, would you still not be able to learn it?
- Components Science Popularization: Pressure Sensor
- Question: How to accurately measure the duty cycle of a 100MHZ square wave? Thank you!