blob: d925c0a8992b02213268badd73878d8a159ee521 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#pragma once
#include <utility>
#include <algorithm>
#include "./quat.hpp"
#include "./plugin-api.hpp"
class Pose {
private:
static constexpr double pi = 3.141592653;
static constexpr double d2r = pi/180.0;
static constexpr double r2d = 180./pi;
double axes[6];
public:
Pose() : axes {0,0,0, 0,0,0 } {}
inline operator double*() { return axes; }
inline operator const double*() const { return axes; }
inline double& operator()(int i) { return axes[i]; }
inline double operator()(int i) const { return axes[i]; }
Quat quat() const
{
return Quat(axes[Yaw]*d2r, axes[Pitch]*d2r, axes[Roll]*d2r);
}
static Pose fromQuat(const Quat& q)
{
Pose ret;
q.to_euler_degrees(ret(Yaw), ret(Pitch), ret(Roll));
return ret;
}
Pose operator-(const Pose& B) const
{
const Quat q = (quat() * B.quat().inv());
Pose ret = fromQuat(q);
for (int i = TX; i < Yaw; i++)
ret(i) = B(i);
return ret;
}
Pose operator+(const Pose& B) const
{
const Quat q = quat() * B.quat();
Pose ret = fromQuat(q);
for (int i = TX; i < Yaw; i++)
ret(i) = B(i);
return ret;
}
Pose operator|(const Pose& replacement) const
{
Pose ret = *this;
for (int i = 0; i < 6; i++)
{
static constexpr double eps = 1e-3;
// NB replace zero-valued elements with argument's
if (std::abs(ret(i)) < eps)
ret(i) = replacement(i);
}
return ret;
}
};
|