A method and system for splitting a floating point number based on a PLC

CN122777084APending Publication Date: 2026-09-18HUARUAN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610810888.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-05
Publication Date
2026-09-18

AI Technical Summary

Technical Problem

[0014]为此,本发明实施例提供一种基于PLC的浮点数拆分方法及系统,以解决现有技术难以在PLC端自动完成浮点数的格式转换,并以整数形式通过现有通信接口可靠地传输至机器人控制器的技术问题

Benefits of technology

[0041] 1. High-precision transmission: Through a rigorous format checking, splitting, and restoration process, we ensure that floating-point numbers do not suffer precision loss during transmission, thus guaranteeing the accuracy of the robot's actions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122777084A_ABST
    Figure CN122777084A_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a floating-point number splitting method and system based on PLC. The embodiment of the application acquires floating-point number data to be transmitted at the PLC end; judges the positive and negative of the floating-point number and records a sign flag bit; splits the floating-point number into an integer part and a decimal part, which are respectively converted into an integer form, wherein the decimal part is obtained by multiplying a preset precision coefficient and then rounding; encapsulates the integer part, the decimal part and the sign flag bit into multiple byte data; and according to a communication protocol between the PLC and a robot, sends the encapsulated byte data to the robot through a communication interface. The application realizes high-precision, high-efficiency and reliable floating-point number transmission from the PLC to the robot, and enhances the compatibility between different devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial automation control technology, specifically to a method and system for floating-point number decomposition based on a PLC. Background Technology

[0002] In modern industrial automated production lines, the collaborative operation of programmable logic controllers (PLCs) and industrial robots is very common. The PLC is typically responsible for collecting and initially processing on-site data, while the robot executes corresponding actions based on the received data, such as material handling, processing operations, and vision-guided positioning. In many applications, it is necessary to transmit floating-point data (such as workpiece coordinates, offsets, and angles output by the vision system) collected or calculated by the PLC to the robot controller.

[0003] Currently, data interaction between PLCs and robots is mainly achieved through industrial Ethernet protocols, such as EtherNet / IP, Profinet, ModbusTCP, and OPCUA. These protocols theoretically support the transmission of floating-point numbers (IEEE 754 single-precision or double-precision format). However, in practical engineering applications, direct transmission of floating-point numbers may face difficulties due to the following reasons:

[0004] 1. Limitations at the Communication Protocol Implementation Level

[0005] When some PLCs and specific robot controllers exchange data using certain communication protocols (such as specific versions of EtherNet / IP), their protocol stacks or communication function blocks may only support integer data mapping. For example, the data sending function block on the PLC side (such as T_Send) or the receiving interface on the robot side may not be able to directly parse or receive IEEE 754 format floating-point data under default configurations or specific firmware versions. In this case, even if the communication protocol itself supports floating-point numbers, the actual functionality of the device may still be limited.

[0006] 2. Constraints of Data Mapping and Address Space

[0007] In some PLC programming environments (such as Siemens TIAPortal), when sending data to external devices via specific communication methods (such as open user communication or specific drives), the send buffer may be defined as a byte array or an integer array. Directly writing floating-point numbers into such a buffer may result in endianness parsing errors or data type mismatches, thus requiring explicit format conversion at the application layer.

[0008] 3. Shortcomings of existing manual conversion solutions

[0009] To address these limitations, field engineers typically use a manual method to split floating-point numbers into integer and fractional parts for separate transmission, then reconstruct them at the receiving end. However, this manual method has the following problems:

[0010] Accuracy loss risk: If the rounding rules are not strictly controlled during manual splitting, it may lead to loss of precision of the decimal part or accumulation of errors;

[0011] Low development efficiency: Each floating-point parameter requires independent splitting and restoration logic, which increases the workload of program development;

[0012] Poor maintainability: The split logic is scattered across different program blocks, making later modification or debugging difficult;

[0013] Lack of unified verification: Manual solutions usually do not include a data integrity verification mechanism, making it difficult to detect transmission errors in a timely manner. Summary of the Invention

[0014] To address this, embodiments of the present invention provide a PLC-based floating-point number splitting method and system to solve the technical problem that existing technologies struggle to automatically convert floating-point numbers to integer form at the PLC end and reliably transmit them to the robot controller via existing communication interfaces.

[0015] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0016] According to a first aspect of the present invention, a PLC-based floating-point number decomposition method is provided, the method being used by a programmable logic controller to transmit floating-point data to a robot, comprising:

[0017] Obtain the floating-point data to be transmitted at the PLC end;

[0018] Detect the sign of the floating-point data and record the sign flag.

[0019] The floating-point data is split into an integer part and a fractional part, and then converted into integer form. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding it.

[0020] The integer part, fractional part, and sign flag obtained from the split are encapsulated into multiple bytes of data;

[0021] According to the communication protocol between the PLC and the robot, the encapsulated byte data is sent to the robot through the communication interface.

[0022] Furthermore, the preset precision coefficient is 100, so that the decimal part retains two significant digits.

[0023] Furthermore, the preset precision coefficient is dynamically configured according to the robot's requirements for decimal precision.

[0024] Furthermore, the sign flag occupies one bit in a byte and is used to indicate whether the floating-point number is positive or negative.

[0025] Furthermore, the floating-point data is split into an integer part and a fractional part, and converted into integer form respectively. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding down, including:

[0026] When converting the integer part of a floating-point number to an integer form, rounding is used to round it to the nearest integer.

[0027] Furthermore, the floating-point data is split into an integer part and a fractional part, and converted into integer form respectively. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding. The method also includes:

[0028] The specific method for extracting the decimal part is as follows: subtract the value of the integer part converted back to a floating-point number from the absolute value of the original floating-point number to obtain the floating-point representation of the decimal part.

[0029] Furthermore, the integer part, fractional part, and sign flag obtained from the split are encapsulated into multiple bytes of data, including:

[0030] The encapsulated byte data occupies a total of 5 bytes, of which the integer part occupies 2 bytes, the fractional part occupies 2 bytes, and the sign flag occupies one bit of 1 byte.

[0031] Furthermore, the communication protocol is the EtherNet / IP protocol.

[0032] According to a second aspect of the present invention, a PLC-based floating-point number splitting system is provided, the system comprising:

[0033] The data acquisition module is used to acquire floating-point data to be transmitted at the PLC end;

[0034] The sign processing module is used to determine the sign of a floating-point number and generate a sign flag.

[0035] The integer splitting module is used to extract the integer part of a floating-point number and convert it into an integer format;

[0036] The decimal splitting module is used to extract the decimal part of a floating-point number, multiply it by a preset precision coefficient, and then round it down.

[0037] The data encapsulation module is used to encapsulate the integer part, the fractional part, and the sign flag into byte data;

[0038] The communication module is used to send encapsulated byte data to the robot according to the communication protocol.

[0039] Furthermore, the decimal splitting module also includes a precision compensation unit for correcting rounding errors during floating-point conversion.

[0040] The embodiments of the present invention have the following advantages:

[0041] 1. High-precision transmission: Through a rigorous format checking, splitting, and restoration process, we ensure that floating-point numbers do not suffer precision loss during transmission, thus guaranteeing the accuracy of the robot's actions.

[0042] 2. High-efficiency transmission: By adopting appropriate communication protocols and transmission strategies, the efficiency of data transmission is improved, transmission delay is reduced, and the overall operating efficiency of the production line is enhanced.

[0043] 3. Strong compatibility: The system supports multiple communication protocols and can be adapted to different models of PLCs and robots, exhibiting good versatility and compatibility.

[0044] 4. High reliability: It is equipped with a retransmission mechanism and data verification function, which can promptly detect and correct errors in the transmission process, ensuring the reliability of data transmission. Attached Figure Description

[0045] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.

[0046] The structures, proportions, sizes, etc. illustrated in this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed herein, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.

[0047] Figure 1 A schematic diagram of the logic structure of a PLC-based floating-point number splitting system provided for an embodiment of the present invention;

[0048] Figure 2 A flowchart illustrating a PLC-based floating-point number decomposition method provided in an embodiment of the present invention;

[0049] Figure 3A schematic diagram of data splitting in a PLC-based floating-point number splitting method provided in an embodiment of the present invention;

[0050] Figure 4 This is a schematic diagram illustrating the assignment of floating-point numbers after splitting them in a PLC-based floating-point number splitting method provided in an embodiment of the present invention.

[0051] Figure 5 This diagram illustrates the function FC_Date in a PLC-based floating-point number splitting method provided in an embodiment of the present invention. Detailed Implementation

[0052] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0053] refer to Figure 1 This invention discloses a PLC-based floating-point number splitting system, which includes: a data acquisition module 1; a symbol processing module 2; an integer splitting module 3; a decimal splitting module 4; a data encapsulation module 5; and a communication module 6.

[0054] Corresponding to the above-disclosed PLC-based floating-point number splitting system, this invention also discloses a PLC-based floating-point number splitting method. The following details a PLC-based floating-point number splitting method disclosed in this invention, in conjunction with the above-described PLC-based floating-point number splitting system.

[0055] refer to Figures 2 to 5 This invention discloses a PLC-based floating-point number decomposition method. Before implementing this method, the following hardware connections and software configurations must be completed:

[0056] Hardware connection: Connect the PLC's Ethernet interface to the KUKA robot's Ethernet interface using a standard network cable, ensuring that the electrical parameters meet EtherNet / IP communication requirements.

[0057] Software configuration: Create a new program block in the PLC programming software (such as TIAPortal) to prepare for writing the floating-point number splitting function block.

[0058] This embodiment takes the transmission of a single-precision floating-point number 3.6 as an example, and performs the splitting and sending according to the following steps.

[0059] Step S1: Obtain the floating-point data to be transmitted at the PLC end.

[0060] The PLC obtains the floating-point data to be transmitted through internal calculations or by reading from sensors, such as variable g_fDeviationX=3.6. This data is in 32-bit single-precision floating-point format.

[0061] Step S2: Determine the sign of the floating-point number and record the sign flag.

[0062] In a PLC program, conditional statements are used to detect the sign of a floating-point number:

[0063] If the input value is less than 0, the sign flag will be set to 1, and the absolute value of the input value will be stored in the temporary variable h.

[0064] Otherwise, the sign flag is set to 0, and the input value is directly stored in h.

[0065] For the value 3.6, since 3.6>=0, the sign :=0, and h :=3.6.

[0066] The sign flag occupies one bit in a byte (e.g., the least significant bit of the byte), while the remaining bits can be used for other purposes or set to zero.

[0067] Step S3: Split the floating-point number into an integer part and a fractional part, and convert them into integer form respectively.

[0068] This step is further broken down into the following sub-steps (all of which process the absolute value h):

[0069] Extract the integer part:

[0070] Assign the value of h to the temporary floating-point variable a (a:=h).

[0071] Use the REAL_TO_INT function to convert a to an integer b, using a rounding method (e.g., 3.6 is rounded to 4, but this needs to be adjusted later).

[0072] To accurately obtain the integer part, this embodiment employs the following compensation logic:

[0073] Convert b back to a floating-point number: c:=INT_TO_REAL(b).

[0074] Compare c and a: If c > a, it means that rounding has resulted in the integer part being taken by 1 more, in which case g:=c-1; otherwise, g:=c.

[0075] For 3.6, b=4, c=4.0. Since 4.0>3.6, g:=4.0-1=3.0.

[0076] Finally, convert g to an integer for output: integer part := REAL_TO_INT(g), resulting in 3.

[0077] Extracting the decimal part:

[0078] Calculate d:=hg to obtain the decimal part. For 3.6, d=3.6-3.0=0.6.

[0079] Based on the preset precision coefficient (100 is used in this embodiment to retain two significant digits), e:=d×100 is calculated, resulting in e=60.0.

[0080] Use REAL_TO_INT to convert e to an integer f, in this example f=60.

[0081] Then, normalize f: decimal part := f / 10, resulting in 6.

[0082] Dividing by 10 here is to match the robot's parsing habits for decimal parts. In actual implementation, f can also be sent directly and parsed by the robot according to the agreement.

[0083] It should be noted that the preset accuracy coefficient can be dynamically configured according to the actual needs of the robot. For example, if three decimal places are required, the coefficient can be set to 1000 and then divided by 100 at the end. In this embodiment, the coefficient 100 corresponds to two decimal places, which is sufficient to meet the accuracy requirements of most industrial handling scenarios.

[0084] Step S4: Encapsulate the integer part, fractional part, and sign flag obtained from the splitting into multiple bytes of data.

[0085] According to a preferred embodiment of the present invention, the split data occupies a total of 5 bytes, specifically allocated as follows:

[0086] Integer part: occupies 2 bytes (16 bits), with a value range of 0 to 65535. In this embodiment, the integer part 3 is stored in the lower 16 bits.

[0087] The fractional part occupies 2 bytes (16 bits) and has a value range of 0 to 65535. In this embodiment, the fractional part 6 is stored in the next 2 bytes.

[0088] Sign flag: Occupies the least significant bit (bit 0) of one byte, with the remaining bits filled with 0. In this embodiment, the sign bit is 0.

[0089] When encapsulating, the bytes are stored sequentially according to the PLC's byte order (little-endian mode): bytes 0-1 are the integer part, bytes 2-3 are the fractional part, and byte 4 is the sign flag byte.

[0090] Step S5: According to the communication protocol, send the encapsulated byte data to the robot through the communication interface.

[0091] This embodiment uses the EtherNet / IP protocol for data transmission. The PLC calls the EtherNet / IP send function block to write the encapsulated 5 bytes of data into the robot's pre-configured input data area. The robot controller parses the integer part, fractional part, and sign bit according to the agreed byte order, and reconstructs the absolute value of the original floating-point number according to the internal algorithm (such as integer part + fractional part / 10), and then combines it with the sign bit to obtain the final floating-point number.

[0092] For example, if the robot receives: integer = 3, decimal = 6, sign = 0, then the reconstructed floating-point number is 3 + 6 / 10 = 3.6, which is consistent with the original data.

[0093] Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.

Claims

1. A method for splitting a floating-point number based on a PLC, characterized by, The method is used for a programmable logic controller to transmit floating-point data to a robot, and includes: Obtain the floating-point data to be transmitted at the PLC end; Detect the sign of the floating-point data and record the sign flag. The floating-point data is split into an integer part and a fractional part, and then converted into integer form. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding it. The integer part, fractional part, and sign flag obtained from the split are encapsulated into multiple bytes of data; According to the communication protocol between the PLC and the robot, the encapsulated byte data is sent to the robot through the communication interface.

2. The method of claim 1, wherein, The preset precision coefficient is 100, so that the decimal part retains two significant digits.

3. The method for decomposing floating-point numbers based on PLC as described in claim 1, characterized in that, The preset accuracy coefficient is dynamically configured according to the robot's requirements for decimal precision.

4. The method for decomposing floating-point numbers based on PLC as described in claim 1, characterized in that, The sign flag occupies one bit in a byte and is used to indicate whether the floating-point number is positive or negative.

5. The method for splitting floating-point numbers based on PLC as described in claim 1, characterized in that, The floating-point data is split into an integer part and a fractional part, and then converted into integer form. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding down, including: When converting the integer part of a floating-point number to an integer form, rounding is used to round it to the nearest integer.

6. The method for decomposing floating-point numbers based on PLC as described in claim 1, characterized in that, The floating-point data is split into an integer part and a fractional part, and each part is converted into an integer form. The fractional part is obtained by multiplying by a preset precision coefficient and then rounding. The process also includes: The specific method for extracting the decimal part is as follows: subtract the value of the integer part converted back to a floating-point number from the absolute value of the original floating-point number to obtain the floating-point representation of the decimal part.

7. The method for decomposing floating-point numbers based on PLC as described in claim 1, characterized in that, The integer part, fractional part, and sign flag obtained from the split are encapsulated into multiple bytes of data, including: The encapsulated byte data occupies a total of 5 bytes, of which the integer part occupies 2 bytes, the fractional part occupies 2 bytes, and the sign flag occupies one bit of 1 byte.

8. The method for decomposing floating-point numbers based on PLC as described in claim 1, characterized in that, The communication protocol is EtherNet / IP.

9. A PLC-based floating-point number decomposition system, characterized in that, The system includes: The data acquisition module is used to acquire floating-point data to be transmitted at the PLC end; The sign processing module is used to determine the sign of a floating-point number and generate a sign flag. The integer splitting module is used to extract the integer part of a floating-point number and convert it into an integer format; The decimal splitting module is used to extract the decimal part of a floating-point number, multiply it by a preset precision coefficient, and then round it down. The data encapsulation module is used to encapsulate the integer part, the fractional part, and the sign flag into byte data; The communication module is used to send encapsulated byte data to the robot according to the communication protocol.

10. A PLC-based floating-point number splitting system as described in claim 9, characterized in that, The decimal splitting module also includes a precision compensation unit, which is used to correct rounding errors during floating-point conversion.