14 unsigned i_largest = 0;
15 for (
unsigned i = 1; i < 4; ++i) {
16 if (fabsf(q[i]) > fabsf(q[i_largest])) {
24 unsigned negate = q[i_largest] < 0;
28 float const SMALL_MAX = 1.0 / sqrt(2);
31 uint32_t comp = i_largest;
32 for (
unsigned i = 0; i < 4; ++i) {
34 unsigned negbit = (q[i] < 0) ^ negate;
35 unsigned mag = ((1 << 9) - 1) * (fabsf(q[i]) / SMALL_MAX) + 0.5f;
36 comp = (comp << 10) | (negbit << 9) | mag;
47 float const SMALL_MAX = 1.0 / sqrt(2);
48 unsigned const mask = (1 << 9) - 1;
50 int const i_largest = comp >> 30;
51 float sum_squares = 0;
52 for (
int i = 3; i >= 0; --i) {
54 unsigned mag = comp & mask;
55 unsigned negbit = (comp >> 9) & 0x1;
57 q[i] = SMALL_MAX * ((float)mag) / mask;
61 sum_squares += q[i] * q[i];
64 q[i_largest] = sqrtf(1.0f - sum_squares);
68 float x,
float y,
float z,
69 float vx,
float vy,
float vz,
70 float ax,
float ay,
float az,
71 float qx,
float qy,
float qz,
float qw,
72 float rollRate,
float pitchRate,
float yawRate)
86 float q[4] = {
qx,
qy,
qz, qw };
88 this->
omegax = s * rollRate;
89 this->
omegay = s * pitchRate;
134 size_t groupLen = strlen(group);
135 size_t nameLen = strlen(name);
140 memcpy(&
data[idx], group, groupLen + 1);
143 memcpy(&
data[idx], name, nameLen + 1);
146 data[idx] = paramType;
149 memcpy(&
data[idx], value, valueSize);
160 const uint8_t&
value)
178 const uint16_t&
value)
187 const int16_t&
value)
196 const uint32_t&
value)
205 const int32_t&
value)
crtpPositionSetpointRequest(float x, float y, float z, float yaw)
void quatdecompress(uint32_t comp, float q[4])
crtpHoverSetpointRequest(float vx, float vy, float yawrate, float zDistance)
crtpFullStateSetpointRequest(float x, float y, float z, float vx, float vy, float vz, float ax, float ay, float az, float qx, float qy, float qz, float qw, float rollRate, float pitchRate, float yawRate)
crtpParamSetByNameRequest(const char *group, const char *name, const T &value)
static uint32_t quatcompress(float const q[4])