OffsetFilter.cpp
Go to the documentation of this file.
1#include "OffsetFilter.h"
2
5
7
8namespace armarx::filters
9{
10
12 {
13 firstRun = true;
14 windowFilterSize = 1;
15 }
16
18 OffsetFilter::calculate(const Ice::Current&) const
19 {
20 std::unique_lock lock(historyMutex);
21
22 VariantPtr newVariant;
23
24 if (initialValue && dataHistory.size() > 0)
25 {
26 VariantTypeId type = dataHistory.begin()->second->getType();
27 VariantPtr currentValue = VariantPtr::dynamicCast(dataHistory.rbegin()->second);
28
29 if (currentValue->getType() != initialValue->getType())
30 {
31 ARMARX_ERROR_S << "Types in OffsetFilter are different: "
32 << Variant::typeToString(currentValue->getType()) << " and "
33 << Variant::typeToString(initialValue->getType());
34 return nullptr;
35 }
36
37 if (type == VariantType::Int)
38 {
39 int newValue = dataHistory.rbegin()->second->getInt() - initialValue->getInt();
40 newVariant = new Variant(newValue);
41 }
42 else if (type == VariantType::Long)
43 {
44 long newValue = dataHistory.rbegin()->second->getLong() - initialValue->getLong();
45 newVariant = new Variant(newValue);
46 }
47 else if (type == VariantType::Float)
48 {
49 float newValue =
50 dataHistory.rbegin()->second->getFloat() - initialValue->getFloat();
51 newVariant = new Variant(newValue);
52 }
53 else if (type == VariantType::Double)
54 {
55 double newValue =
56 dataHistory.rbegin()->second->getDouble() - initialValue->getDouble();
57 newVariant = new Variant(newValue);
58 }
59 else if (type == VariantType::FramedDirection)
60 {
62 FramedDirectionPtr::dynamicCast(currentValue->get<FramedDirection>());
63 FramedDirectionPtr intialVec =
64 FramedDirectionPtr::dynamicCast(initialValue->get<FramedDirection>());
65 Eigen::Vector3f newValue = vec->toEigen() - intialVec->toEigen();
66
67 newVariant = new Variant(new FramedDirection(newValue, vec->frame, vec->agent));
68 }
69 else if (type == VariantType::FramedPosition)
70 {
72 FramedPositionPtr::dynamicCast(currentValue->get<FramedPosition>());
73 FramedPositionPtr intialPos =
74 FramedPositionPtr::dynamicCast(initialValue->get<FramedPosition>());
75 Eigen::Vector3f newValue = pos->toEigen() - intialPos->toEigen();
76 newVariant = new Variant(new FramedPosition(newValue, pos->frame, pos->agent));
77 }
78 else if (type == VariantType::MatrixFloat)
79 {
80 MatrixFloatPtr matrix =
81 MatrixFloatPtr::dynamicCast(currentValue->get<MatrixFloat>());
82 MatrixFloatPtr initialMatrix =
83 MatrixFloatPtr::dynamicCast(initialValue->get<MatrixFloat>());
84 Eigen::MatrixXf newMatrix = matrix->toEigen() - initialMatrix->toEigen();
85 newVariant = new Variant(new MatrixFloat(newMatrix));
86 }
87 }
88
89 return newVariant;
90 }
91
92 ParameterTypeList
93 OffsetFilter::getSupportedTypes(const Ice::Current&) const
94 {
95 ParameterTypeList result;
96 result.push_back(VariantType::Int);
97 result.push_back(VariantType::Long);
98 result.push_back(VariantType::Float);
99 result.push_back(VariantType::Double);
100 result.push_back(VariantType::FramedDirection);
101 result.push_back(VariantType::FramedPosition);
102 result.push_back(VariantType::MatrixFloat);
103 return result;
104 }
105
106 void
107 OffsetFilter::update(Ice::Long timestamp, const VariantBasePtr& value, const Ice::Current& c)
108 {
110
111 if (firstRun)
112 {
113 std::unique_lock lock(historyMutex);
114
115 if (dataHistory.size() == 0)
116 {
117 return;
118 }
119
120 initialValue = VariantPtr::dynamicCast(dataHistory.begin()->second);
121 firstRun = false;
122 }
123 }
124
125} // namespace armarx::filters
std::string timestamp()
constexpr T c
void update(Ice::Long timestamp, const VariantBasePtr &value, const Ice::Current &c=Ice::emptyCurrent) override
Adds the given value to the data map, erases old values if maximum size was reached,...
TimeVariantBaseMap dataHistory
FramedDirection is a 3 dimensional direction vector with a reference frame.
Definition FramedPose.h:87
The FramedPosition class.
Definition FramedPose.h:158
The MatrixFloat class.
The Variant class is described here: Variants.
Definition Variant.h:224
static std::string typeToString(VariantTypeId typeId)
Return the name of the registered type typeId.
Definition Variant.cpp:848
ParameterTypeList getSupportedTypes(const Ice::Current &) const override
void update(Ice::Long timestamp, const VariantBasePtr &value, const Ice::Current &c) override
VariantBasePtr calculate(const Ice::Current &=Ice::emptyCurrent) const override
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216
const VariantTypeId FramedPosition
Definition FramedPose.h:38
const VariantTypeId FramedDirection
Definition FramedPose.h:37
const VariantTypeId Int
Definition Variant.h:917
const VariantTypeId Long
Definition Variant.h:918
const VariantTypeId MatrixFloat
const VariantTypeId Double
Definition Variant.h:920
const VariantTypeId Float
Definition Variant.h:919
IceInternal::Handle< FramedDirection > FramedDirectionPtr
Definition FramedPose.h:84
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< MatrixFloat > MatrixFloatPtr
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
Ice::Int VariantTypeId
Definition Variant.h:43
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr