Orientation - Quaternions

Orientation of the tag can be sent as a quaternion. This payload is sent in the following TLV structure.

type

length [B]

value

0x0009

4

q0, q1, q2, q3

where:

Item

Description

q0

w element of quaternion in fixed point Q8 format

q1

x element of quaternion in fixed point Q8 format

q2

y element of quaternion in fixed point Q8 format

q3

z element of quaternion in fixed point Q8 format


The quaternions are sent in Q8 fixed-point format, so if there is needed to convert it to the floating-point representation, the following C code can be used:

float w = (q0 >= 128) ? (((float)q0-256.f) / 128.f) : ((float)q0/ 128.f);
float x = (q1 >= 128) ? (((float)q1-256.f) / 128.f) : ((float)q1/ 128.f);
float y = (q2 >= 128) ? (((float)q2-256.f) / 128.f) : ((float)q2/ 128.f);
float z = (q3 >= 128) ? (((float)q3-256.f) / 128.f) : ((float)q3/ 128.f);

It is recommended to normalize a quaternion after converting to floating-point, because of a low dynamic range fixed-point format.


Structure of value part of TLV in C code:

typedef struct {
	int8_t q0;                      /**<Quaternion member Q0. Fixed point representation Q8.*/
	int8_t q1;                      /**<Quaternion member Q1. Fixed point representation Q8.*/
	int8_t q2;                      /**<Quaternion member Q2. Fixed point representation Q8.*/
	int8_t q3;                      /**<Quaternion member Q3. Fixed point representation Q8.*/
} quaternion_msg_t;