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
31namespace armarx
32{
34 {
35 public:
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
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
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
#define ARMARXCORE_IMPORT_EXPORT
ConditionCheck * clone() override
Clones the current check.
bool evaluate(const StringVariantMap &dataFields) override
Evaluate the condition based on the current data field values.
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 FramedOrientation class.
Definition FramedPose.h:216
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
std::string getFrame() const
The Quaternion class.
Definition Pose.h:174
The Variant class is described here: Variants.
Definition Variant.h:224
The Vector3 class.
Definition Pose.h:113
const VariantTypeId FramedPosition
Definition FramedPose.h:38
const VariantTypeId FramedOrientation
Definition FramedPose.h:39
const VariantTypeId Quaternion
Definition Pose.h:39
const VariantTypeId FramedPose
Definition FramedPose.h:36
const VariantTypeId Vector3
Definition Pose.h:38
const VariantTypeId Float
Definition Variant.h:919
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T > > &src, Thrower thrower)
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
Ice::Int VariantTypeId
Definition Variant.h:43
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
std::map< std::string, Variant > StringVariantMap
Definition Variant.h:748