ConditionCheckEqualsPoseWithTolerance.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, 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
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
29 
30 namespace armarx
31 {
33  public ConditionCheck
34  {
35  public:
37  {
38  setNumberParameters(3);
39  addSupportedType(VariantType::FramedPosition, createParameterTypeList(2, VariantType::FramedPosition, VariantType::Float));
40  addSupportedType(VariantType::FramedOrientation, createParameterTypeList(2, VariantType::FramedOrientation, VariantType::Float));
41  addSupportedType(VariantType::Vector3, createParameterTypeList(2, VariantType::Vector3, VariantType::Float));
42  addSupportedType(VariantType::Quaternion, createParameterTypeList(2, VariantType::Quaternion, VariantType::Float));
43  addSupportedType(VariantType::FramedPose, createParameterTypeList(3, VariantType::FramedPose, VariantType::Float, VariantType::Float));
44  }
45 
46  ConditionCheck* clone() override
47  {
48  return new ConditionCheckApproxPose(*this);
49  }
50 
51  bool evaluate(const StringVariantMap& dataFields) override
52  {
53  if (dataFields.size() != 1)
54  {
55  printf("Size of dataFields: %d\n", (int)dataFields.size());
56  throw InvalidConditionException("Wrong number of datafields for condition equals ");
57  }
58 
59  const Variant& value = dataFields.begin()->second;
60  VariantTypeId type = value.getType();
61 
62  if (type == VariantType::Vector3)
63  {
64  const Vector3Ptr& typedValue = value.getClass<Vector3>();
65  const Vector3Ptr& param = getParameter(0).getClass<Vector3>();
66  return (sqrt(((typedValue->x - param->x) * (typedValue->x - param->x)) +
67  ((typedValue->y - param->y) * (typedValue->y - param->y)) +
68  ((typedValue->z - param->x) * (typedValue->x - param->z))) < getParameter(1).getFloat());
69  }
70 
71  if (type == VariantType::Quaternion)
72  {
73  const QuaternionPtr& typedValue = value.getClass<Quaternion>();
74  const QuaternionPtr& param = getParameter(0).getClass<Quaternion>();
75  Eigen::Matrix3f diffRot = typedValue->toEigen() * param->toEigen().transpose();
76  Eigen::AngleAxisf aa(diffRot);
77  return fabs(aa.angle()) < getParameter(1).getFloat();
78  }
79 
80 
81  if (type == VariantType::FramedPosition)
82  {
83  const FramedPositionPtr& typedValue = value.getClass<FramedPosition>();
84  const FramedPositionPtr& param = getParameter(0).getClass<FramedPosition>();
85  return param->getFrame() == typedValue->getFrame()
86  && (sqrt(((typedValue->x - param->x) * (typedValue->x - param->x)) +
87  ((typedValue->y - param->y) * (typedValue->y - param->y)) +
88  ((typedValue->z - param->x) * (typedValue->x - param->z))) < getParameter(1).getFloat());
89  }
90 
91 
93  {
94  const FramedOrientationPtr& typedValue = value.getClass<FramedOrientation>();
95  const FramedOrientationPtr& param = getParameter(0).getClass<FramedOrientation>();
96  Eigen::Matrix3f diffRot = typedValue->toEigen() * param->toEigen().transpose();
97  Eigen::AngleAxisf aa(diffRot);
98  return fabs(aa.angle()) < getParameter(1).getFloat();
99  }
100 
101 
102  if (type == VariantType::FramedPose)
103  {
104  const PosePtr& typedValue = value.getClass<FramedPose>();
105  const PosePtr& param = getParameter(0).getClass<FramedPose>();
106  bool positionOk = (sqrt(((typedValue->position->x - param->position->x) * (typedValue->position->x - param->position->x)) +
107  ((typedValue->position->y - param->position->y) * (typedValue->position->y - param->position->y)) +
108  ((typedValue->position->z - param->position->x) * (typedValue->position->x - param->position->z)))
109  < getParameter(1).getFloat());
110 
111  Eigen::Matrix3f diffRot = typedValue->toEigen().block<3, 3>(0, 0) * param->toEigen().block<3, 3>(0, 0).transpose();
112  Eigen::AngleAxisf aa(diffRot);
113  bool orientationOk =
114  fabs(aa.angle()) < getParameter(2).getFloat();
115  return positionOk && orientationOk;
116  }
117 
118  return false;
119  }
120  };
121 }
122 
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::FramedPosition::getFrame
std::string getFrame() const
Definition: FramedPose.cpp:632
armarx::ConditionCheckApproxPose::ConditionCheckApproxPose
ConditionCheckApproxPose()
Definition: ConditionCheckEqualsPoseWithTolerance.h:36
armarx::ConditionCheckApproxPose
Definition: ConditionCheckEqualsPoseWithTolerance.h:32
armarx::ConditionCheckApproxPose::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckEqualsPoseWithTolerance.h:46
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
IceInternal::Handle< Vector3 >
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
FramedPose.h
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::ConditionCheck
Definition: ConditionCheck.h:56
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:40
armarx::Quaternion
The Quaternion class.
Definition: Pose.h:173
armarx::ConditionCheckApproxPose::evaluate
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
Definition: ConditionCheckEqualsPoseWithTolerance.h:51
ImportExport.h
ConditionCheck.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:39
armarx::transpose
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T >> &src, Thrower thrower)
Definition: SimoxCSpace.cpp:706
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28