ConditionCheckEqualsPose.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 
26 #include <ArmarXCore/core/FramedPose.h>
29 
30 namespace armarx
31 {
33  {
34  public:
36  {
37  setNumberParameters(1);
38  addSupportedType(VariantType::FramedPosition, createParameterTypeList(1, VariantType::FramedPosition);
39  addSupportedType(VariantType::FramedOrientation, createParameterTypeList(1, VariantType::FramedOrientation);
40  addSupportedType(VariantType::Vector3, createParameterTypeList(1, VariantType::Vector3);
41  addSupportedType(VariantType::Quaternion, createParameterTypeList(1, VariantType::Quaternion);
42  addSupportedType(VariantType::Pose, createParameterTypeList(1, VariantType::Pose);
43  }
44 
47  {
48  return new ConditionCheckEqualsPose(*this);
49  }
50 
51  bool
52  evaluate(const StringVariantMap& dataFields)
53  {
54  if (dataFields.size() != 1)
55  {
56  printf("Size of dataFields: %d\n", (int)dataFields.size());
57  throw InvalidConditionException("Wrong number of datafields for condition equals ");
58  }
59 
60  Variant& value = dataFields.begin()->second;
61  VariantTypeId type = value.getType();
62 
63  if (type == VariantType::Vector3)
64  return (sqrt(((value.x - getParameter(0).getClass<Vector3>().x) *
65  (value.x - getParameter(0).getClass<Vector3>().x)) +
66  ((value.y - getParameter(0).getClass<Vector3>().y) *
67  (value.y - getParameter(0).getClass<Vector3>().y)) +
68  ((value.z - getParameter(0).getClass<Vector3>().x) *
69  (value.x - getParameter(0).getClass<Vector3>().z))) == 0);
70 
71  if (type == VariantType::FramedPosition)
72  return (sqrt(((value.x - getParameter(0).getClass<FramedPosition>().x) *
73  (value.x - getParameter(0).getClass<FramedPosition>().x)) +
74  ((value.y - getParameter(0).getClass<FramedPosition>().y) *
75  (value.y - getParameter(0).getClass<FramedPosition>().y)) +
76  ((value.z - getParameter(0).getClass<FramedPosition>().x) *
77  (value.x - getParameter(0).getClass<FramedPosition>().z))) == 0);
78 
79  if (type == VariantType::Quaternion)
80  return (sqrt(((value.qw - getParameter(0).getClass<Quaternion>().qw) *
81  (value.qw - getParameter(0).getClass<Quaternion>().qw)) +
82  ((value.qx - getParameter(0).getClass<Quaternion>().qx) *
83  (value.qx - getParameter(0).getClass<Quaternion>().qx)) +
84  ((value.qy - getParameter(0).getClass<Quaternion>().qy) *
85  (value.qy - getParameter(0).getClass<Quaternion>().qy)) +
86  ((value.qz - getParameter(0).getClass<Quaternion>().qx) *
87  (value.qx - getParameter(0).getClass<Quaternion>().qz))) == 0);
88 
90  return (sqrt(((value.qw - getParameter(0).getClass<FramedOrientation>().qw) *
91  (value.qw - getParameter(0).getClass<FramedOrientation>().qw)) +
92  ((value.qx - getParameter(0).getClass<FramedOrientation>().qx) *
93  (value.qx - getParameter(0).getClass<FramedOrientation>().qx)) +
94  ((value.qy - getParameter(0).getClass<FramedOrientation>().qy) *
95  (value.qy - getParameter(0).getClass<FramedOrientation>().qy)) +
96  ((value.qz - getParameter(0).getClass<FramedOrientation>().qx) *
97  (value.qx - getParameter(0).getClass<FramedOrientation>().qz))) == 0);
98 
99  if (type == VariantType::Pose)
100  return (sqrt(((value.x - getParameter(0).getClass<Pose>().x) *
101  (value.x - getParameter(0).getClass<Pose>().x)) +
102  ((value.y - getParameter(0).getClass<Pose>().y) *
103  (value.y - getParameter(0).getClass<Pose>().y)) +
104  ((value.z - getParameter(0).getClass<Pose>().x) *
105  (value.x - getParameter(0).getClass<Pose>().z))) +
106  sqrt(((value.qw - getParameter(0).getClass<Pose>().qw) *
107  (value.qw - getParameter(0).getClass<Pose>().qw)) +
108  ((value.qx - getParameter(0).getClass<Pose>().qx) *
109  (value.qx - getParameter(0).getClass<Pose>().qx)) +
110  ((value.qy - getParameter(0).getClass<Pose>().qy) *
111  (value.qy - getParameter(0).getClass<Pose>().qy)) +
112  ((value.qz - getParameter(0).getClass<Pose>().qx) *
113  (value.qx - getParameter(0).getClass<Pose>().qz))) ==
114  0);
115 
116  return false;
117  }
118  };
119 } // namespace armarx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::ConditionCheckEqualsPose::evaluate
bool evaluate(const StringVariantMap &dataFields)
Evaluate the condition based on the current data field values.
Definition: ConditionCheckEqualsPose.h:52
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::ConditionCheckEqualsPose::ConditionCheckEqualsPose
ConditionCheckEqualsPose()
Definition: ConditionCheckEqualsPose.h:35
armarx::ConditionCheckEqualsPose
Definition: ConditionCheckEqualsPose.h:32
armarx::VariantType::Vector3
const VariantTypeId Vector3
Definition: Pose.h:38
armarx::ConditionCheckEqualsPose::clone
ConditionCheck * clone()
Clones the current check.
Definition: ConditionCheckEqualsPose.h:46
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
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
ImportExport.h
ConditionCheck.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38
armarx::VariantType::Pose
const VariantTypeId Pose
Definition: Pose.h:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27