Floating Point Number Transmission Between Robots and PLCs

HELLO everyone, a few days ago someone asked if Profinet can transmit floating point numbers?

Today, let’s talk about how robots send and receive floating point numbers.

If you already know how to do it, please take a look at my implementation and see how it differs from yours.

Quick Navigation:

1 What is a floating point number

2 How binary represents floating point numbers

3 32-bit floating point numbers

4 How robots read floating point numbers

5 How robots send floating point numbers

6 Summary and next issue preview

Click here to follow

1 What is a floating point number

A floating point number is a way to represent real numbers (i.e., numbers that include a decimal point, such as 3.14159, -0.001, 6.02e23) in computers. Its core idea is to use scientific notation to store numbers, allowing for the representation of very large, very small, or highly precise values.

The term “floating” in floating point refers to the fact that the position of the decimal point is not fixed and can “float” based on the size of the number.

2 How binary represents floating point numbers

A floating point number (using the most common IEEE 754 standard as an example) consists of three parts in computer memory, similar to the three parts of scientific notation:Sign bit (Sign)Function: Indicates whether the number is positive or negative.Length: 1 bit.Rule: 0 represents positive, 1 represents negative.Exponent (Exponent)Function: Represents the “exponent” part in scientific notation (i.e., the 8 in 10^8), determining how the decimal point “floats”.Length: Single precision floating point (float) is usually 8 bits, double precision floating point (double) is usually 11 bits.Rule: To also represent negative exponents (very small numbers), the exponent value is stored with an offset (Exponent bias). For example, the offset for an 8-bit exponent is 127, so the actual exponent = stored value – 127.Significand (Mantissa/Significand)Function: Represents the “significant digits” part in scientific notation (i.e., 3.00 or 9.1093837), determining the precision of the value.Length: Single precision (float) is usually 23 bits, double precision (double) is usually 52 bits.Rule: In binary scientific notation, the highest bit of the significand is always 1 (for example, the binary number 101.11 can be represented as 1.0111 × 2^2), so to save space, this leading 1 is implicitly stored, and only the fractional part (.0111) is actually stored.

3 32-bit floating point numbers

Floating Point Number Transmission Between Robots and PLCs

The binary division of a 32-bit floating point number is shown in the image above.

Position: From bit 22 to bit 0 (the lowest 23 bits).

Length: 23 bits.Meaning: These 23 bits store the fractional part of the significant digits.

Position: From bit 30 to bit 23.

Length: 8 bits.

Meaning: These 8 bits store anunsigned integer, ranging from 0 to 255.

Position: Bit 31 (the highest bit, the leftmost bit).

Length: 1 bit.Meaning: 0 indicates this is a positive number. 1 indicates this is a negative number.

KUKA robots use 32-bit floating point numbers, utilizing IO endpoints for binary transmission. The system provides us with conversion functions for 32-bit floating point numbers. We just need to write according to KRL logic.

4 How robots read floating point numbers

First, declare the signal endpoint:

In the .dat file, declare SIGNAL gi_32bit $IN[1] TO $IN[32]

(Note that high-low conversion is required between Siemens PLC and KUKA.)

Then write the following program

GLOBAL DEFFCT REAL Bit32ToReal(signalVar:IN) INT offset, signalVarREAL realVarCHAR buffer[8]    offset=0    CAST_TO(buffer[],offset,signalVar)     offset=0    CAST_FROM(buffer[],offset,realVar)    RETURN (realVar)ENDFCT

I used CAST_TO and CAST_FROM here; the overall structure should be similar. I wrote this conversion as a function block for easy calling.

Call it as follows:

REAL rr = Bit32ToReal(gi_32bit)

5 How robots send floating point numbers

First, declare the signal endpoint:

In the .dat file, declare SIGNAL go_32bit $OUT[1] TO $OUT[32]

(Note that high-low conversion is required between Siemens PLC and KUKA.)

Then write the following program

GLOBAL  DEFFCT INT RealTO32Bit(realVar:IN) INT offset,ourVarREAL realVarCHAR buffer[8]    offset = 0    cast_to(buffer[],offset,realVar)    offset = 0    CAST_FROM(buffer[],offset,ourVar)    RETURN (ourVar)ENDFCT

Call it as follows:

go_32bit = RealTO32Bit(3.14159)

6 Summary and next issue preview

32-bit floating point numbers are a representation method using binary scientific notation, and robots utilize input and output endpoints to replace binary for 32-bit floating point transmission. Note that high-low conversion is required for Siemens PLC.

I have written this program as a standard block, placed in the same src file, and I recommend you do the same for convenient future programming.

Next time, we will discuss the transmission of strings, which is often used in data transfer between robots and industrial computers.

Share, View, Follow Like

Leave a Comment