-
Notifications
You must be signed in to change notification settings - Fork 14
/
MatrixExponential.cpp
77 lines (59 loc) · 2.09 KB
/
MatrixExponential.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
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include "MatrixExponential.hpp"
#include <yarp/os/LogStream.h>
#include "LogComponent.hpp"
#include "ScrewTheoryTools.hpp"
using namespace roboticslab;
// -----------------------------------------------------------------------------
namespace
{
inline KDL::Rotation operator-(const KDL::Rotation & lhs, const KDL::Rotation & rhs)
{
return KDL::Rotation(lhs(0, 0) - rhs(0, 0), lhs(0, 1) - rhs(0, 1), lhs(0, 2) - rhs(0, 2),
lhs(1, 0) - rhs(1, 0), lhs(1, 1) - rhs(1, 1), lhs(1, 2) - rhs(1, 2),
lhs(2, 0) - rhs(2, 0), lhs(2, 1) - rhs(2, 1), lhs(2, 2) - rhs(2, 2));
}
}
// -----------------------------------------------------------------------------
MatrixExponential::MatrixExponential(motion _motionType, const KDL::Vector & _axis, const KDL::Vector & _origin)
: motionType(_motionType),
axis(_axis),
origin(_origin)
{
axis.Normalize();
}
// -----------------------------------------------------------------------------
KDL::Frame MatrixExponential::asFrame(double theta) const
{
KDL::Frame H;
switch (motionType)
{
case ROTATION:
H.M = KDL::Rotation::Rot2(axis, theta);
H.p = (KDL::Rotation::Identity() - H.M) * (axis * origin * axis);
break;
case TRANSLATION:
H.p = axis * theta;
break;
default:
yCWarning(ST) << "Unrecognized motion type:" << motionType;
}
return H;
}
// -----------------------------------------------------------------------------
void MatrixExponential::changeBase(const KDL::Frame & H_new_old)
{
axis = H_new_old.M * axis;
if (motionType == ROTATION)
{
origin = H_new_old * origin;
}
}
// -----------------------------------------------------------------------------
MatrixExponential MatrixExponential::cloneWithBase(const KDL::Frame & H_new_old) const
{
MatrixExponential exp(*this);
exp.changeBase(H_new_old);
return exp;
}
// -----------------------------------------------------------------------------