reflex.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 <mutex>
27
28#include <Eigen/Core>
29#include <Eigen/Geometry>
30
32
33namespace armarx
34{
36
37 class Reflex
38 {
39 public:
41 {
42 this->interval = interval;
43
44 task = new PeriodicTask<Reflex>(
45 this, &Reflex::calc, interval, false, "HeadStabilizationTask");
46 task->setDelayWarningTolerance(5);
47 }
48
49 virtual ~Reflex()
50 {
51 stop();
52 }
53
54 void
56 {
57 if (!task->isRunning())
58 {
59 task->start();
60 }
61 }
62
63 void
65 {
66 if (task->isRunning())
67 {
68 task->stop();
69 }
70
71 onStop();
72
73 jointAngles.clear();
74 }
75
76 void
77 setEnabled(bool enabled)
78 {
79 if (enabled)
80 {
81 start();
82 }
83 else
84 {
85 stop();
86 }
87 }
88
89 std::map<std::string, float>
91 {
92 std::scoped_lock lock(mutex);
93
94 std::map<std::string, float> result(jointAngles);
95
96 //if (( currentTime - updateTime) > xxx) {
97
98 //result.swap(jointAngles);
99 // }
100
101 return result;
102 }
103
104 float
105 getWeight() const
106 {
107 return weight;
108 }
109
110 void
111 setWeight(float weight)
112 {
113 this->weight = weight;
114 }
115
116 virtual std::string getName() const = 0;
117
118
119 protected:
120 Eigen::Vector3f
122 {
123 Eigen::Vector3f euler;
124
125 euler(0) = -std::atan2(2.0 * (q.w() * q.x() - q.y() * q.z()),
126 1.0 - 2.0 * (q.x() * q.x() + q.y() * q.y())); //roll
127 euler(1) = std::asin(2.0 * (q.w() * q.y() - q.z() * q.x())); //pitch
128 euler(2) = std::atan2(2.0 * (q.w() * q.z() + q.x() * q.y()),
129 1.0 - 2.0 * (q.y() * q.y() + q.z() * q.z())); //yaw
130
131 return euler;
132 }
133
134 virtual void calc() = 0;
135
136 virtual void onStop() = 0;
137
138 std::mutex mutex;
139
140 std::map<std::string, float> jointAngles;
141
143
145
146 IceUtil::Time updateTime;
147
148 std::string name;
149
150
151 private:
153
154 float weight;
155 };
156
157 using ReflexPtr = std::shared_ptr<Reflex>;
158} // namespace armarx
The periodic task executes one thread method repeatedly using the time period specified in the constr...
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
Brief description of class ReflexCombination.
std::mutex mutex
Definition reflex.h:138
Eigen::Vector3f quaternionToRPY(Eigen::Quaternionf q)
Definition reflex.h:121
void setEnabled(bool enabled)
Definition reflex.h:77
std::map< std::string, float > getJoints()
Definition reflex.h:90
Reflex(int interval)
Definition reflex.h:40
virtual void onStop()=0
void start()
Definition reflex.h:55
float getWeight() const
Definition reflex.h:105
void setWeight(float weight)
Definition reflex.h:111
void stop()
Definition reflex.h:64
IceUtil::Time updateTime
Definition reflex.h:146
std::string name
Definition reflex.h:148
virtual ~Reflex()
Definition reflex.h:49
virtual std::string getName() const =0
bool isEnabled
Definition reflex.h:144
std::map< std::string, float > jointAngles
Definition reflex.h:140
virtual void calc()=0
#define q
Quaternion< float, 0 > Quaternionf
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< Reflex > ReflexPtr
Definition reflex.h:157