PoseMedianFilter.cpp
Go to the documentation of this file.
1 #include "PoseMedianFilter.h"
2 
4 #include <RobotAPI/interface/core/PoseBase.h>
5 
7 
8 
9 namespace armarx::filters
10 {
11 
13  {
14  this->windowFilterSize = windowSize;
15  }
16 
17 
18  VariantBasePtr PoseMedianFilter::calculate(const Ice::Current& c) const
19  {
20  std::unique_lock lock(historyMutex);
21 
22  if (dataHistory.size() == 0)
23  {
24  return nullptr;
25  }
26 
27  VariantTypeId type = dataHistory.begin()->second->getType();
28 
29  if (type == VariantType::Vector3
31  or type == VariantType::FramedPosition)
32  {
33  Eigen::Vector3f vec;
34  vec.setZero();
35  std::string frame = "";
36  std::string agent = "";
37  VariantPtr var = VariantPtr::dynamicCast(dataHistory.begin()->second);
38 
39  if (type == VariantType::FramedDirection)
40  {
41  FramedDirectionPtr p = var->get<FramedDirection>();
42  frame = p->frame;
43  agent = p->agent;
44  }
45  else if (type == VariantType::FramedPosition)
46  {
47  FramedPositionPtr p = var->get<FramedPosition>();
48  frame = p->frame;
49  agent = p->agent;
50  }
51 
52  for (int i = 0; i < 3; ++i)
53  {
54  std::vector<double> values;
55 
56  for (auto v : dataHistory)
57  {
58  VariantPtr v2 = VariantPtr::dynamicCast(v.second);
59  values.push_back(v2->get<Vector3>()->toEigen()[i]);
60  }
61 
62  std::sort(values.begin(), values.end());
63  vec[i] = values.at(values.size() / 2);
64  }
65 
66  if (type == VariantType::Vector3)
67  {
68  Vector3Ptr vecVar = new Vector3(vec);
69  return new Variant(vecVar);
70  }
71  else if (type == VariantType::FramedDirection)
72  {
73 
74  FramedDirectionPtr vecVar = new FramedDirection(vec, frame, agent);
75  return new Variant(vecVar);
76  }
77  else if (type == VariantType::FramedPosition)
78  {
79  FramedPositionPtr vecVar = new FramedPosition(vec, frame, agent);
80  return new Variant(vecVar);
81  }
82  else
83  {
84  ARMARX_WARNING_S << "Implementation missing here";
85  return nullptr;
86  }
87  }
88  else if (type == VariantType::Double)
89  {
90  // auto values = SortVariants<double>(dataHistory);
91  // return new Variant(values.at(values.size()/2));
92  }
93  else if (type == VariantType::Int)
94  {
95  // auto values = SortVariants<int>(dataHistory);
96  // return new Variant(values.at(values.size()/2));
97  }
98 
99  return MedianFilter::calculate(c);
100  }
101 
102 
103  ParameterTypeList PoseMedianFilter::getSupportedTypes(const Ice::Current& c) const
104  {
105  ParameterTypeList result = MedianFilter::getSupportedTypes(c);
106  result.push_back(VariantType::Vector3);
107  result.push_back(VariantType::FramedDirection);
108  result.push_back(VariantType::FramedPosition);
109  return result;
110  }
111 
112 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::filters::PoseMedianFilter::PoseMedianFilter
PoseMedianFilter(int windowSize=11)
Definition: PoseMedianFilter.cpp:12
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
PoseMedianFilter.h
IceInternal::Handle<::armarx::VariantBase >
armarx::filters
Definition: AverageFilter.h:31
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::filters::MedianFilter::getSupportedTypes
ParameterTypeList getSupportedTypes(const Ice::Current &c=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
Definition: MedianFilter.cpp:67
FramedPose.h
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:83
armarx::DatafieldFilter::dataHistory
TimeVariantBaseMap dataHistory
Definition: DatafieldFilter.h:79
armarx::VariantType::FramedDirection
const VariantTypeId FramedDirection
Definition: FramedPose.h:38
armarx::Vector3::toEigen
virtual Eigen::Vector3f toEigen() const
Definition: Pose.cpp:134
armarx::filters::PoseMedianFilter::getSupportedTypes
ParameterTypeList getSupportedTypes(const Ice::Current &c) const override
This filter supports: Vector3, FramedDirection, FramedPosition.
Definition: PoseMedianFilter.cpp:103
armarx::DatafieldFilter::historyMutex
std::mutex historyMutex
Definition: DatafieldFilter.h:80
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::filters::MedianFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: MedianFilter.cpp:33
armarx::filters::PoseMedianFilter::calculate
VariantBasePtr calculate(const Ice::Current &c) const override
Definition: PoseMedianFilter.cpp:18
Logging.h
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:39