ReflexCombination.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotComponents::ArmarXObjects::ReflexCombination
17 * @author [Author Name] ( [Author Email] )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25
26#include <VirtualRobot/IK/GazeIK.h>
27#include <VirtualRobot/Nodes/RobotNode.h>
28#include <VirtualRobot/Robot.h>
29#include <VirtualRobot/RobotNodeSet.h>
30#include <VirtualRobot/VirtualRobot.h>
31
37
38#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
41
42#include <VisionX/interface/components/ImageSourceSelectionInterface.h>
43
44#include <RobotComponents/interface/GazeStabilizationInterface.h>
45
46#include "feedforward.h"
47#include "jointik.h"
48#include "okr.h"
49#include "reflex.h"
50#include "vor.h"
51
52namespace armarx
53{
59
60 /**
61 * @class ReflexCombinationPropertyDefinitions
62 * @brief
63 */
65 {
66 public:
69 {
71 "VelocityBasedControl", true, "Use velocity based reflexes");
72
73 defineOptionalProperty<float>("kp", 1.0, "p part of regulator");
74 defineOptionalProperty<float>("ki", 0.0, "i part of regulator");
75 defineOptionalProperty<float>("kd", 0.0, "d part of regulator");
76
77 defineOptionalProperty<float>("VOR", 0, "Vestibulo-ocular reflex weight");
78 defineOptionalProperty<float>("OKR", 1, "Opto-kinetic reflex weight");
79 defineOptionalProperty<float>("JointIK", 0, "Joint IK weight");
81 "AdvancedVOR", 0, "Advanced Vestibulo-ocular reflex weight");
82
83 defineOptionalProperty<std::string>("KinematicUnitName",
84 "Armar3KinematicUnit",
85 "Name of the KinematicUnit of the Robot");
87 "IMUObserverName",
88 "InertialMeasurementUnitObserver",
89 "Name of the InertialMeasurementUnitObserver of the Robot");
91 "RobotStateName", "RobotStateComponent", "Name of the RobotState of the Robot");
93 "HeadIKName", "IKVirtualGazeNoEyes", "Name of the HeadIK");
95 "RobotNodeSetName", "Robot", "Name of the RobotNodeSet");
96
97 defineOptionalProperty<std::string>("ImageSourceSelectionName",
98 "ImageSourceSelection",
99 "Name of the ImageSourceSelection component");
101 "ImageProviders",
102 {"Armar3ImageProvider", "Armar3FovealImageProvider"},
103 "Name of the image provider to choose from. If image quality is high, the second "
104 "provider will be used.");
105
106 defineOptionalProperty<std::string>("DebugObserverName",
107 "DebugObserver",
108 "Name of the topic the DebugObserver listens on");
109
111 "CalibrationFile",
112 "ArmarXSimulation/camera_simulator_640x480.txt",
113 "Camera calibration file, will be made available in the SLICE interface");
114
116 "NeckPerturbation",
117 false,
118 "Add sinusoidal motion in the neck joint to test the reflexes");
119 defineOptionalProperty<bool>("reafferenceCombination",
120 false,
121 "Combined reflexes with IK based on the reafference "
122 "principle (sensory cancelation)");
123 }
124 };
125
126 class Reflex;
127 class VOR;
128 class JointIK;
129 class FeedforwardReflex;
130 class OKR;
131 class AdvancedVOR;
132
133 /**
134 * @defgroup Component-ReflexCombination ReflexCombination
135 * @ingroup RobotComponents-Components
136 * A description of the component ReflexCombination.
137 *
138 * @class ReflexCombination
139 * @ingroup Component-ReflexCombination
140 * @brief Brief description of class ReflexCombination.
141 *
142 * Detailed description of class ReflexCombination.
143 */
145 virtual public armarx::Component,
146 virtual public armarx::GazeStabilizationInterface
147 {
148 public:
149 /**
150 * @see armarx::ManagedIceObject::getDefaultName()
151 */
152 std::string
153 getDefaultName() const override
154 {
155 return "ReflexCombination";
156 }
157
158 void updateWeights(float vor,
159 float okr,
160 float jointIK,
161 const Ice::Current& c = Ice::emptyCurrent) override;
162
163 void setReafferenceMethod(bool isReafference,
164 const Ice::Current& c = Ice::emptyCurrent) override;
165
166
167 protected:
168 /**
169 * @see armarx::ManagedIceObject::onInitComponent()
170 */
171 void onInitComponent() override;
172
173 /**
174 * @see armarx::ManagedIceObject::onConnAdvancedVORectComponent()
175 */
176 void onConnectComponent() override;
177
178 /**
179 * @see armarx::ManagedIceObject::onDisconnectComponent()
180 */
181 void onDisconnectComponent() override;
182
183 /**
184 * @see armarx::ManagedIceObject::onExitComponent()
185 */
186 void onExitComponent() override;
187
188 /**
189 * @see PropertyUser::createPropertyDefiAdvancedVORnitions()
190 */
192
193
194 private:
195 void setImageQuality(float quality);
196
197 std::mutex mutex;
198 std::map<std::string, NameValueMap> reflexValues;
199 std::map<std::string, ReflexPtr> reflexes;
200 std::vector<std::string> headJointNames;
201
202 VOR* vor;
203 FeedforwardReflex* jointIK;
204 OKR* okr;
205
206
207 bool armar4, velocityBased, neckPerturbation;
208 bool vorEnabled, jointIKEnabled, okrEnabled;
209 std::string eye_pitch_left, eye_pitch_right, eye_yaw_left, eye_yaw_right, neck_roll;
210 float vorWeight, okrWeight, jointIKWeight;
211 float kp, ki, kd;
212
213 COMBINATION_METHOD combinationMethod;
214
215 PeriodicTask<ReflexCombination>::pointer_type execCombineReflexesTask;
216
217
218 //required for JointIK
220 VirtualRobot::RobotNodeSetPtr robotNodeSet;
221
222 std::string headIKName;
223 RobotStateComponentInterfacePrx robotStateComponent;
224 Eigen::Quaternionf initial;
225
226 NameValueMap targetJointAngles;
227
228 KinematicUnitInterfacePrx kinUnitPrx;
229 DebugObserverInterfacePrx debugObserver;
231 ImageSourceSelectionInterfacePrx imageSourceSelection;
232 bool newHeadTarget;
233 //RobotStateComponentInterfacePrx robotStateComponent;
234
235 std::map<std::string, IceInternal::Handle<armarx::filters::DerivationFilter>>
236 VelocityFilters;
237 std::map<std::string, IceInternal::Handle<armarx::filters::MedianFilter>> IMU_GyroFilters;
238 std::map<std::string, IceInternal::Handle<armarx::filters::ButterworthFilter>>
239 PreVelocityFilters;
240 std::map<std::string, IceInternal::Handle<armarx::filters::ButterworthFilter>> FlowFilters;
241
242 double t_init;
243
244 // PlatformUnitListener interface
245 public:
246 void reportPlatformVelocity(Ice::Float currentPlatformVelocityX,
247 Ice::Float currentPlatformVelocityY,
248 Ice::Float currentPlatformVelocityRotation,
249 const Ice::Current& c = Ice::emptyCurrent) override;
250 void reportPlatformOdometryPose(Ice::Float,
251 Ice::Float,
252 Ice::Float,
253 const Ice::Current&) override;
254
255 // KinematicUnitListener interface
256 public:
257 void reportControlModeChanged(const NameControlModeMap&,
258 Ice::Long timestamp,
259 bool,
260 const Ice::Current& c = Ice::emptyCurrent) override;
261 void reportJointAngles(const NameValueMap& values,
262 Ice::Long timestamp,
263 bool valueChanged,
264 const Ice::Current& c = Ice::emptyCurrent) override;
265 void reportJointVelocities(const NameValueMap& values,
266 Ice::Long timestamp,
267 bool valueChanged,
268 const Ice::Current& c = Ice::emptyCurrent) override;
269 void reportJointTorques(const NameValueMap&,
270 Ice::Long timestamp,
271 bool,
272 const Ice::Current& c = Ice::emptyCurrent) override;
273 void reportJointAccelerations(const NameValueMap&,
274 Ice::Long timestamp,
275 bool,
276 const Ice::Current& c = Ice::emptyCurrent) override;
277 void reportJointCurrents(const NameValueMap&,
278 Ice::Long timestamp,
279 bool,
280 const Ice::Current& c = Ice::emptyCurrent) override;
281 void reportJointMotorTemperatures(const NameValueMap&,
282 Ice::Long timestamp,
283 bool,
284 const Ice::Current& c = Ice::emptyCurrent) override;
285 void reportJointStatuses(const NameStatusMap&,
286 Ice::Long timestamp,
287 bool,
288 const Ice::Current& c = Ice::emptyCurrent) override;
289
290
291 private:
292 void combineReflexes();
293 Eigen::Vector3f quaternionToRPY(Eigen::Quaternionf q);
294
295 // OpticalFlowListener interface
296 public:
297 void reportNewOpticalFlow(Ice::Float,
298 Ice::Float,
299 Ice::Float,
300 Ice::Long,
301 const Ice::Current&) override;
302
303 // HeadIKUnitListener interface
304 public:
305 void reportHeadTargetChanged(const NameValueMap& targetJointAngles,
306 const FramedPositionBasePtr& targetPosition,
307 const Ice::Current& c = Ice::emptyCurrent) override;
308
309 // InertialMeasurementUnitListener interface
310 public:
311 void reportSensorValues(const std::string& device,
312 const std::string& name,
313 const IMUData& values,
314 const TimestampBasePtr& timestamp,
315 const Ice::Current& c = Ice::emptyCurrent) override;
316
317 // HeadIKUnitListener interface
318 public:
319 void
320 reportHeadTargetChanged(const Ice::Current&)
321 {
322 }
323
324 // TrackingErrorListener interface
325 public:
326 void reportNewTrackingError(Ice::Float pixelX,
327 Ice::Float pixelY,
328 Ice::Float angleX,
329 Ice::Float angleY,
330 const Ice::Current&) override;
331 };
332} // namespace armarx
std::string timestamp()
constexpr T c
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Brief description of class ReflexCombination.
void reportHeadTargetChanged(const NameValueMap &targetJointAngles, const FramedPositionBasePtr &targetPosition, const Ice::Current &c=Ice::emptyCurrent) override
void setReafferenceMethod(bool isReafference, const Ice::Current &c=Ice::emptyCurrent) override
void reportSensorValues(const std::string &device, const std::string &name, const IMUData &values, const TimestampBasePtr &timestamp, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void updateWeights(float vor, float okr, float jointIK, const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportControlModeChanged(const NameControlModeMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportHeadTargetChanged(const Ice::Current &)
void reportJointAccelerations(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointVelocities(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointTorques(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
void reportNewTrackingError(Ice::Float pixelX, Ice::Float pixelY, Ice::Float angleX, Ice::Float angleY, const Ice::Current &) override
void reportNewOpticalFlow(Ice::Float, Ice::Float, Ice::Float, Ice::Long, const Ice::Current &) override
void reportJointCurrents(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
void reportJointAngles(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
void reportJointStatuses(const NameStatusMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
#define q
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx