Servosila-SC-25-Programming-Guide

Data Types
Data Type Size in bytes Comments
BOOL 1 Same as UINT8.
UINT8 1 Byte.
INT8 1 Signed byte.
UINT16 2 Little-endian format.
INT16 2 Little-endian format.
UINT32 4 Little-endian format.
INT32 4 Little-endian format.
FLOAT32 4 IEEE 32-bit floating point value. Little-endian format.
FLOAT16 2 This is a proprietary floating number format defined by Servosila. See a description below.
FLOAT16
The FLOAT16 type is transmitted the same way as INT16, a signed integer. However, upon
receiving, the signed integer value needs to be linearly scaled to range [-128, +128] to extract an
encoded floating point value. This is a special data type that allows to fit this particular range of
floating point numbers into 2 bytes instead of 4 bytes. This is just a data compression technique
that allows to transmit more data in the limited 8byte-long CAN payload.
A C++ example of decoding or encoding a FLOAT16 number:
#define MAX_FLOAT16 ( 128.0f)
#define MIN_FLOAT16 (-MAX_FLOAT16)
float decode_float16 (int16_t bits)
{
//de-scaling
const float f32 = float(bits) * (MAX_FLOAT16 / 32767.0f); //LINEAR SCALING FORMULA
return f32;
}
int16_t encode_float16 (float f32)
{
//clipping the value
if(f32 > MAX_FLOAT16) f32 = MAX_FLOAT16;
if(f32 < MIN_FLOAT16) f32 = MIN_FLOAT16;
//scaling
const int16_t bits = lroundf(f32 * (32767.0f / MAX_FLOAT16)); //LINEAR SCALING FORMULA
return bits;
}
19 www.servosila.com