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
30namespace armarx
31{
33 {
34 public:
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
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
#define ARMARXCORE_IMPORT_EXPORT
bool evaluate(const StringVariantMap &dataFields)
Evaluate the condition based on the current data field values.
ConditionCheck * clone()
Clones the current check.
A ConditionCheck implements a check on the sensor data stream of a Sensor-Actor Unit.
static ParameterTypeList createParameterTypeList(int numberTypes,...)
void setNumberParameters(int numberParameters)
Sets the number of paramaters required for this check.
const Variant & getParameter(int index)
Retrieve parameters of check.
ConditionCheck()
Creates and initializes a ConditionCheck instance.
void addSupportedType(VariantTypeId dataFieldType=0, ParameterTypeList parameterTypes=ParameterTypeList())
Add a supported type for elementary condition check marks pairs of (dataFieldType,...
The Variant class is described here: Variants.
Definition Variant.h:224
const VariantTypeId FramedPosition
Definition FramedPose.h:38
const VariantTypeId FramedOrientation
Definition FramedPose.h:39
const VariantTypeId Pose
Definition Pose.h:40
const VariantTypeId Quaternion
Definition Pose.h:39
const VariantTypeId Vector3
Definition Pose.h:38
This file offers overloads of toIce() and fromIce() functions for STL container types.
Ice::Int VariantTypeId
Definition Variant.h:43
std::map< std::string, Variant > StringVariantMap
Definition Variant.h:748