PoseAverageFilter.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2018
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "PoseAverageFilter.h"
25 
27 
28 
29 namespace armarx::filters
30 {
31 
32  VariantBasePtr PoseAverageFilter::calculate(const Ice::Current& c) const
33  {
34  std::unique_lock lock(historyMutex);
35 
36  if (dataHistory.size() == 0)
37  {
38  return NULL;
39  }
40 
41  VariantTypeId type = dataHistory.begin()->second->getType();
42 
44  {
45 
46  Eigen::Vector3f vec;
47  vec.setZero();
48  std::string frame = "";
49  std::string agent = "";
50  VariantPtr var = VariantPtr::dynamicCast(dataHistory.begin()->second);
51 
52  if (type == VariantType::FramedDirection)
53  {
54  FramedDirectionPtr p = var->get<FramedDirection>();
55  frame = p->frame;
56  agent = p->agent;
57  }
58  else if (type == VariantType::FramedPosition)
59  {
60  FramedPositionPtr p = var->get<FramedPosition>();
61  frame = p->frame;
62  agent = p->agent;
63  }
64  Eigen::MatrixXf keypointPositions(dataHistory.size(), 3);
65  int i = 0;
66  for (auto& v : dataHistory)
67  {
68  VariantPtr v2 = VariantPtr::dynamicCast(v.second);
69  Eigen::Vector3f value = v2->get<Vector3>()->toEigen();
70  keypointPositions(i, 0) = value(0);
71  keypointPositions(i, 1) = value(1);
72  keypointPositions(i, 2) = value(2);
73  i++;
74  }
75  vec = keypointPositions.colwise().mean();
76 
77 
78  if (type == VariantType::Vector3)
79  {
80  Vector3Ptr vecVar = new Vector3(vec);
81  return new Variant(vecVar);
82  }
83  else if (type == VariantType::FramedDirection)
84  {
85 
86  FramedDirectionPtr vecVar = new FramedDirection(vec, frame, agent);
87  return new Variant(vecVar);
88  }
89  else if (type == VariantType::FramedPosition)
90  {
91  FramedPositionPtr vecVar = new FramedPosition(vec, frame, agent);
92  return new Variant(vecVar);
93  }
94  else
95  {
96  ARMARX_WARNING_S << "Implementation missing here";
97  return NULL;
98  }
99  }
100  else if (type == VariantType::Double)
101  {
102  // auto values = SortVariants<double>(dataHistory);
103  // return new Variant(values.at(values.size()/2));
104  }
105  else if (type == VariantType::Int)
106  {
107  // auto values = SortVariants<int>(dataHistory);
108  // return new Variant(values.at(values.size()/2));
109  }
110 
111  return AverageFilter::calculate(c);
112  }
113 
114 
115 
116 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::viz::toEigen
Eigen::Matrix4f toEigen(data::GlobalPose const &pose)
Definition: Interaction.h:46
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
IceInternal::Handle<::armarx::VariantBase >
armarx::filters
Definition: AverageFilter.h:31
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
PoseAverageFilter.h
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::filters::AverageFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: AverageFilter.cpp:32
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::filters::PoseAverageFilter::calculate
VariantBasePtr calculate(const Ice::Current &c) const override
Definition: PoseAverageFilter.cpp:32
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::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
Logging.h
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:39