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 
28 #include <ArmarXCore/core/FramedPose.h>
29 
30 namespace armarx
31 {
33  public ConditionCheck
34  {
35  public:
37  {
38  setNumberParameters(1);
39  addSupportedType(VariantType::FramedPosition, createParameterTypeList(1, VariantType::FramedPosition);
40  addSupportedType(VariantType::FramedOrientation, createParameterTypeList(1, VariantType::FramedOrientation);
41  addSupportedType(VariantType::Vector3, createParameterTypeList(1, VariantType::Vector3);
42  addSupportedType(VariantType::Quaternion, createParameterTypeList(1, VariantType::Quaternion);
43  addSupportedType(VariantType::Pose, createParameterTypeList(1, VariantType::Pose);
44  }
45 
47  {
48  return new ConditionCheckEqualsPose(*this);
49  }
50 
51  bool evaluate(const StringVariantMap& dataFields)
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  Variant& value = dataFields.begin()->second;
60  VariantTypeId type = value.getType();
61 
62  if (type == VariantType::Vector3)
63  return (sqrt(((value.x - getParameter(0).getClass<Vector3>().x) * (value.x - getParameter(0).getClass<Vector3>().x)) +
64  ((value.y - getParameter(0).getClass<Vector3>().y) * (value.y - getParameter(0).getClass<Vector3>().y)) +
65  ((value.z - getParameter(0).getClass<Vector3>().x) * (value.x - getParameter(0).getClass<Vector3>().z))) == 0);
66 
67  if (type == VariantType::FramedPosition)
68  return (sqrt(((value.x - getParameter(0).getClass<FramedPosition>().x) * (value.x - getParameter(0).getClass<FramedPosition>().x)) +
69  ((value.y - getParameter(0).getClass<FramedPosition>().y) * (value.y - getParameter(0).getClass<FramedPosition>().y)) +
70  ((value.z - getParameter(0).getClass<FramedPosition>().x) * (value.x - getParameter(0).getClass<FramedPosition>().z))) == 0);
71 
72  if (type == VariantType::Quaternion)
73  return (sqrt(((value.qw - getParameter(0).getClass<Quaternion>().qw) * (value.qw - getParameter(0).getClass<Quaternion>().qw)) +
74  ((value.qx - getParameter(0).getClass<Quaternion>().qx) * (value.qx - getParameter(0).getClass<Quaternion>().qx)) +
75  ((value.qy - getParameter(0).getClass<Quaternion>().qy) * (value.qy - getParameter(0).getClass<Quaternion>().qy)) +
76  ((value.qz - getParameter(0).getClass<Quaternion>().qx) * (value.qx - getParameter(0).getClass<Quaternion>().qz))) == 0);
77 
79  return (sqrt(((value.qw - getParameter(0).getClass<FramedOrientation>().qw) * (value.qw - getParameter(0).getClass<FramedOrientation>().qw)) +
80  ((value.qx - getParameter(0).getClass<FramedOrientation>().qx) * (value.qx - getParameter(0).getClass<FramedOrientation>().qx)) +
81  ((value.qy - getParameter(0).getClass<FramedOrientation>().qy) * (value.qy - getParameter(0).getClass<FramedOrientation>().qy)) +
82  ((value.qz - getParameter(0).getClass<FramedOrientation>().qx) * (value.qx - getParameter(0).getClass<FramedOrientation>().qz))) == 0);
83 
84  if (type == VariantType::Pose)
85  return (sqrt(((value.x - getParameter(0).getClass<Pose>().x) * (value.x - getParameter(0).getClass<Pose>().x)) +
86  ((value.y - getParameter(0).getClass<Pose>().y) * (value.y - getParameter(0).getClass<Pose>().y)) +
87  ((value.z - getParameter(0).getClass<Pose>().x) * (value.x - getParameter(0).getClass<Pose>().z))) +
88  sqrt(((value.qw - getParameter(0).getClass<Pose>().qw) * (value.qw - getParameter(0).getClass<Pose>().qw)) +
89  ((value.qx - getParameter(0).getClass<Pose>().qx) * (value.qx - getParameter(0).getClass<Pose>().qx)) +
90  ((value.qy - getParameter(0).getClass<Pose>().qy) * (value.qy - getParameter(0).getClass<Pose>().qy)) +
91  ((value.qz - getParameter(0).getClass<Pose>().qx) * (value.qx - getParameter(0).getClass<Pose>().qz))) == 0);
92 
93  return false;
94  }
95  };
96 }
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::ConditionCheckEqualsPose::evaluate
bool evaluate(const StringVariantMap &dataFields)
Evaluate the condition based on the current data field values.
Definition: ConditionCheckEqualsPose.h:51
armarx::StringVariantMap
std::map< std::string, Variant > StringVariantMap
Definition: Variant.h:748
armarx::ConditionCheckEqualsPose::ConditionCheckEqualsPose
ConditionCheckEqualsPose()
Definition: ConditionCheckEqualsPose.h:36
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:926
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::ConditionCheck
Definition: ConditionCheck.h:56
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:40
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::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:28