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 
28 
30 
31 namespace armarx
32 {
34  {
35  public:
37  {
38  setNumberParameters(3);
39  addSupportedType(
41  createParameterTypeList(2, VariantType::FramedPosition, VariantType::Float));
42  addSupportedType(
44  createParameterTypeList(2, VariantType::FramedOrientation, VariantType::Float));
45  addSupportedType(VariantType::Vector3,
46  createParameterTypeList(2, VariantType::Vector3, VariantType::Float));
47  addSupportedType(
49  createParameterTypeList(2, VariantType::Quaternion, VariantType::Float));
50  addSupportedType(
52  createParameterTypeList(
54  }
55 
57  clone() override
58  {
59  return new ConditionCheckApproxPose(*this);
60  }
61 
62  bool
63  evaluate(const StringVariantMap& dataFields) override
64  {
65  if (dataFields.size() != 1)
66  {
67  printf("Size of dataFields: %d\n", (int)dataFields.size());
68  throw InvalidConditionException("Wrong number of datafields for condition equals ");
69  }
70 
71  const Variant& value = dataFields.begin()->second;
72  VariantTypeId type = value.getType();
73 
74  if (type == VariantType::Vector3)
75  {
76  const Vector3Ptr& typedValue = value.getClass<Vector3>();
77  const Vector3Ptr& param = getParameter(0).getClass<Vector3>();
78  return (sqrt(((typedValue->x - param->x) * (typedValue->x - param->x)) +
79  ((typedValue->y - param->y) * (typedValue->y - param->y)) +
80  ((typedValue->z - param->x) * (typedValue->x - param->z))) <
81  getParameter(1).getFloat());
82  }
83 
84  if (type == VariantType::Quaternion)
85  {
86  const QuaternionPtr& typedValue = value.getClass<Quaternion>();
87  const QuaternionPtr& param = getParameter(0).getClass<Quaternion>();
88  Eigen::Matrix3f diffRot = typedValue->toEigen() * param->toEigen().transpose();
89  Eigen::AngleAxisf aa(diffRot);
90  return fabs(aa.angle()) < getParameter(1).getFloat();
91  }
92 
93 
94  if (type == VariantType::FramedPosition)
95  {
96  const FramedPositionPtr& typedValue = value.getClass<FramedPosition>();
97  const FramedPositionPtr& param = getParameter(0).getClass<FramedPosition>();
98  return param->getFrame() == typedValue->getFrame() &&
99  (sqrt(((typedValue->x - param->x) * (typedValue->x - param->x)) +
100  ((typedValue->y - param->y) * (typedValue->y - param->y)) +
101  ((typedValue->z - param->x) * (typedValue->x - param->z))) <
102  getParameter(1).getFloat());
103  }
104 
105 
106  if (type == VariantType::FramedOrientation)
107  {
108  const FramedOrientationPtr& typedValue = value.getClass<FramedOrientation>();
109  const FramedOrientationPtr& param = getParameter(0).getClass<FramedOrientation>();
110  Eigen::Matrix3f diffRot = typedValue->toEigen() * param->toEigen().transpose();
111  Eigen::AngleAxisf aa(diffRot);
112  return fabs(aa.angle()) < getParameter(1).getFloat();
113  }
114 
115 
116  if (type == VariantType::FramedPose)
117  {
118  const PosePtr& typedValue = value.getClass<FramedPose>();
119  const PosePtr& param = getParameter(0).getClass<FramedPose>();
120  bool positionOk = (sqrt(((typedValue->position->x - param->position->x) *
121  (typedValue->position->x - param->position->x)) +
122  ((typedValue->position->y - param->position->y) *
123  (typedValue->position->y - param->position->y)) +
124  ((typedValue->position->z - param->position->x) *
125  (typedValue->position->x - param->position->z))) <
126  getParameter(1).getFloat());
127 
128  Eigen::Matrix3f diffRot = typedValue->toEigen().block<3, 3>(0, 0) *
129  param->toEigen().block<3, 3>(0, 0).transpose();
130  Eigen::AngleAxisf aa(diffRot);
131  bool orientationOk = fabs(aa.angle()) < getParameter(2).getFloat();
132  return positionOk && orientationOk;
133  }
134 
135  return false;
136  }
137  };
138 } // namespace armarx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:280
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:36
armarx::FramedPosition::getFrame
std::string getFrame() const
Definition: FramedPose.cpp:736
armarx::ConditionCheckApproxPose::ConditionCheckApproxPose
ConditionCheckApproxPose()
Definition: ConditionCheckEqualsPoseWithTolerance.h:36
armarx::ConditionCheckApproxPose
Definition: ConditionCheckEqualsPoseWithTolerance.h:33
armarx::ConditionCheckApproxPose::clone
ConditionCheck * clone() override
Clones the current check.
Definition: ConditionCheckEqualsPoseWithTolerance.h:57
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:855
FramedPose.h
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
armarx::Vector3
The Vector3 class.
Definition: Pose.h:112
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:215
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:43
armarx::ConditionCheck
Definition: ConditionCheck.h:54
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:704
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:39
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:63
ImportExport.h
ConditionCheck.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38
armarx::transpose
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T >> &src, Thrower thrower)
Definition: SimoxCSpace.cpp:772
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27