-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathposefilter.cpp
136 lines (115 loc) · 2.82 KB
/
posefilter.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "posefilter.h"
using namespace Eigen;
PoseFilter::Motion::Motion()
{
reset();
}
PoseFilter::Motion::Motion(const Vector3d & linear,
const Quaterniond & angular):
linear(linear),
angular(angular)
{
}
void PoseFilter::Motion::reset()
{
linear.setZero();
angular.setIdentity();
}
PoseFilter::Pose::Pose()
{
reset();
}
PoseFilter::Pose::Pose(const Vector3d & position,
const Quaterniond & rotation):
position(position),
rotation(rotation)
{
}
void PoseFilter::Pose::reset()
{
position.setZero();
rotation.setIdentity();
}
PoseFilter::Motion PoseFilter::Pose::getMotion(const PoseFilter::Pose & next) const
{
return Motion(next.position - position, next.rotation * rotation.conjugate());
}
PoseFilter::Pose PoseFilter::Pose::getNext(const PoseFilter::Motion & motion) const
{
return Pose(position + motion.linear, motion.angular * rotation);
}
PoseFilter::Pose PoseFilter::Pose::mix(const PoseFilter::Pose & pose, double k_position, double k_angular) const
{
return Pose(position * (1.0 - k_position) + pose.position * k_position,
rotation.slerp(k_angular, pose.rotation));
}
PoseFilter::PoseFilter():
m_positionWeights(100.0, 1.0),
m_rotationWeights(100.0, 1.0)
{
reset();
}
Vector2d PoseFilter::positionWeights() const
{
return m_positionWeights;
}
void PoseFilter::setPositionWeights(const Vector2d & positionWeights)
{
m_positionWeights = positionWeights;
}
Vector2d PoseFilter::rotationWeights() const
{
return m_rotationWeights;
}
void PoseFilter::setRotationWeights(const Vector2d & rotationWeights)
{
m_rotationWeights = rotationWeights;
}
void PoseFilter::reset()
{
m_currentStep = 0;
m_pose.reset();
m_motion.reset();
}
void PoseFilter::reset(const Pose & pose)
{
m_currentStep = 1;
m_pose = pose;
m_motion.reset();
}
const PoseFilter::Pose & PoseFilter::currentPose() const
{
return m_pose;
}
const PoseFilter::Motion & PoseFilter::currentMotion() const
{
return m_motion;
}
const PoseFilter::Pose & PoseFilter::next(const PoseFilter::Pose & rawPose)
{
if (m_currentStep == 0)
{
m_pose = rawPose;
++m_currentStep;
}
else if (m_currentStep == 1)
{
m_motion = m_pose.getMotion(rawPose);
m_pose = rawPose;
++m_currentStep;
}
else
{
Pose simulated_next = m_pose.getNext(m_motion);
Pose next = rawPose.mix(simulated_next,
m_positionWeights.y() / (m_positionWeights.x() + m_positionWeights.y()),
m_rotationWeights.y() / (m_rotationWeights.x() + m_rotationWeights.y()));
m_motion = m_pose.getMotion(next);
m_pose = next;
}
return m_pose;
}
int PoseFilter::currentStep() const
{
return m_currentStep;
}