Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE® and XFC® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Overview

TwinCAT PLC Library: TcMath

概述

TcMath.lib PLC 库包括TwinCAT PLC的扩展的数学功能。该库随TwinCAT（从2.9 Build 1000版开始）提供。

功能

FLOOR | FLOOR功能取小于或等于一个浮点数的整数值。
FRAC | FRAC功能取一个浮点数的小数部分。
LMOD | LMOD功能做模数除法并返回带符号的余数。
LTRUNC | LTRUNC功能取一个浮点数的整数部分。
MODABS | MODABS功能做模数除法并在模数范围内取无符号的模数值。
MODTURNS | MODTURNS功能做模数除法并取带符号的整数部分。
F_GetVersionTcMath | 返回库版本信息。


FLOOR

功能 FLOOR

FLOOR功能取小于或等于一个浮点数的整数值。结果数是LREAL类型，因此其结果并不限定在整型变量的数值范围内。

例子

FLOOR(2.8) = 2

FLOOR(-2.8) = -3

相似功能： TRUNC, LTRUNC

注： 不像 FLOOR， LTRUNC功能取一个数的整数部分。对于正数，其值小于等于输入值；对于负数，其值大于等于输入值。

FUNCTION FLOOR : LREAL

VAR_INPUT
    lr_in : LREAL;
END_VAR

lr_in : 功能的参数类型 LREAL

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.9.0 build 1000 以上版本 | PC or CX (x86) | TcMath.Lib
TwinCAT v2.10.0 Build >= 1301 | CX (ARM)


FRAC

功能 FRAC

FRAC功能取一个浮点数的小数部分。

例子

FRAC(2.8) = 0.8

FRAC(-2.8) = -0.8

FUNCTION FRAC : LREAL

VAR_INPUT
    lr_in : LREAL;
END_VAR

lr_in : 功能的参数类型 LREAL

Development environment | Target system type | PLC libraries to be linked


LMOD

功能 LMOD

LMOD功能做模数除法并返回带符号的余数。

例子

LMOD( 400.56, 360) = 40.56

LMOD( -400.56, 360) = -40.56

相似功能： MOD, MODABS

注： 不像 MOD， LMOD功能处理浮点变量并且取非整型余数。在NC轴的情况下，模值通常取无符号型。这种情况下可以用MODABS 功能。

FUNCTION LMOD : LREAL

VAR_INPUT
    lr_Value : LREAL;
    lr_Arg : LREAL;
END_VAR

lr_Value : 输入值

lr_Arg : 模数范围


LTRUNC

功能 LTRUNC

LTRUNC功能取一个浮点数的整数部分。

例子

LTRUNC(2.8) = 2

LTRUNC(-2.8) = -2

相似功能： TRUNC, FLOOR

注： 不像 TRUNC，LTRUNC的结果是LREAL型的，因此其结果并不限于整型变量的数据范围。

FUNCTION LTRUNC : LREAL

VAR_INPUT
    lr_in : LREAL;
END_VAR

lr_in : 功能的参数类型 LREAL


MODABS

功能 MODABS

MODABS功能做模数除法并在模数范围内取无符号的模数值。

例子

MODABS( 400.56, 360) = 40.56

MODABS( -400.56, 360) = 319,44

相似功能： MOD, LMOD

注： MODABS功能可由NC轴的绝对设定位置计算出其模数设定位置。

ModuloSetPosition := MODABS( NcToPlc.fPosSoll, 360 );

FUNCTION MODABS : LREAL

VAR_INPUT
    lr_val : LREAL;
    lr_mod : LREAL;
END_VAR

lr_val : 输入值

lr_mod : 模数范围


MODTURNS

功能 MODTURNS

MODTURNS功能做模数除法并取带符号的整数部分（模周期， 模旋转）。

例子

MODTURNS ( 800.56, 360) = 2

MODTURNS ( -400.56, 360) = -2

注：MODTURNS功能可由NC轴的绝对设定位置计算出其模旋转数。

ModuloSetTurns := MODTURNS ( NcToPlc.fPosSoll, 360 );

FUNCTION MODTURNS : LREAL

VAR_INPUT
    lr_Value : LREAL;
    lr_Arg : LREAL;
END_VAR

lr_Value : 输入值

lr_Arg : 模数范围


F_GetVersionTcMath

功能 F_GetVersionTcMath

该功能返回库的版本信息。

FUNCTION F_GetVersionTcMath : UINT

VAR_INPUT
    nVersionElement : INT;
END_VAR

nVersionElement : 版本参数：

  • 1 : 主要编号；
  • 2 : 次要编号；
  • 3 : 修订编号。
Development environment | Target system type | PLC libraries to include