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 
52 namespace armarx
53 {
55  {
58  };
59 
60  /**
61  * @class ReflexCombinationPropertyDefinitions
62  * @brief
63  */
65  {
66  public:
69  {
70  defineOptionalProperty<bool>(
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");
80  defineOptionalProperty<float>(
81  "AdvancedVOR", 0, "Advanced Vestibulo-ocular reflex weight");
82 
83  defineOptionalProperty<std::string>("KinematicUnitName",
84  "Armar3KinematicUnit",
85  "Name of the KinematicUnit of the Robot");
86  defineOptionalProperty<std::string>(
87  "IMUObserverName",
88  "InertialMeasurementUnitObserver",
89  "Name of the InertialMeasurementUnitObserver of the Robot");
90  defineOptionalProperty<std::string>(
91  "RobotStateName", "RobotStateComponent", "Name of the RobotState of the Robot");
92  defineOptionalProperty<std::string>(
93  "HeadIKName", "IKVirtualGazeNoEyes", "Name of the HeadIK");
94  defineOptionalProperty<std::string>(
95  "RobotNodeSetName", "Robot", "Name of the RobotNodeSet");
96 
97  defineOptionalProperty<std::string>("ImageSourceSelectionName",
98  "ImageSourceSelection",
99  "Name of the ImageSourceSelection component");
100  defineOptionalProperty<Ice::StringSeq>(
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 
110  defineOptionalProperty<std::string>(
111  "CalibrationFile",
112  "ArmarXSimulation/camera_simulator_640x480.txt",
113  "Camera calibration file, will be made available in the SLICE interface");
114 
115  defineOptionalProperty<bool>(
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;
251  Ice::Float,
252  Ice::Float,
253  const Ice::Current&) override;
254 
255  // KinematicUnitListener interface
256  public:
257  void reportControlModeChanged(const NameControlModeMap&,
259  bool,
260  const Ice::Current& c = Ice::emptyCurrent) override;
263  bool valueChanged,
264  const Ice::Current& c = Ice::emptyCurrent) override;
267  bool valueChanged,
268  const Ice::Current& c = Ice::emptyCurrent) override;
269  void reportJointTorques(const NameValueMap&,
271  bool,
272  const Ice::Current& c = Ice::emptyCurrent) override;
275  bool,
276  const Ice::Current& c = Ice::emptyCurrent) override;
277  void reportJointCurrents(const NameValueMap&,
279  bool,
280  const Ice::Current& c = Ice::emptyCurrent) override;
283  bool,
284  const Ice::Current& c = Ice::emptyCurrent) override;
285  void reportJointStatuses(const NameStatusMap&,
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:
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:
327  Ice::Float pixelY,
328  Ice::Float angleX,
329  Ice::Float angleY,
330  const Ice::Current&) override;
331  };
332 } // namespace armarx
DerivationFilter.h
armarx::ReflexCombination::reportJointTorques
void reportJointTorques(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:617
armarx::COMBINATION_METHOD
COMBINATION_METHOD
Definition: ReflexCombination.h:54
armarx::ReflexCombination::reportHeadTargetChanged
void reportHeadTargetChanged(const NameValueMap &targetJointAngles, const FramedPositionBasePtr &targetPosition, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:696
RemoteRobot.h
armarx::ReflexCombination::onInitComponent
void onInitComponent() override
Definition: ReflexCombination.cpp:31
armarx::ReflexCombination::reportHeadTargetChanged
void reportHeadTargetChanged(const Ice::Current &)
Definition: ReflexCombination.h:320
DebugObserver.h
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:919
armarx::ReflexCombination::updateWeights
void updateWeights(float vor, float okr, float jointIK, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:218
armarx::ReflexCombination::reportJointMotorTemperatures
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:641
armarx::WeightedSum
@ WeightedSum
Definition: ReflexCombination.h:56
okr.h
armarx::OKR
Definition: okr.h:33
Pose.h
armarx::ReflexCombination::onExitComponent
void onExitComponent() override
Definition: ReflexCombination.cpp:203
armarx::ReflexCombination::getDefaultName
std::string getDefaultName() const override
Definition: ReflexCombination.h:153
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
vor.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
ButterworthFilter.h
armarx::ReflexCombination::reportJointAngles
void reportJointAngles(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:509
armarx::ReflexCombination::reportSensorValues
void reportSensorValues(const std::string &device, const std::string &name, const IMUData &values, const TimestampBasePtr &timestamp, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:725
feedforward.h
armarx::ReflexCombination::reportPlatformVelocity
void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:489
armarx::ReflexCombination::reportControlModeChanged
void reportControlModeChanged(const NameControlModeMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:501
armarx::VOR
Definition: vor.h:38
armarx::FeedforwardReflex
Definition: feedforward.h:48
armarx::ReflexCombination::reportJointAccelerations
void reportJointAccelerations(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:625
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::ReflexCombination::reportNewTrackingError
void reportNewTrackingError(Ice::Float pixelX, Ice::Float pixelY, Ice::Float angleX, Ice::Float angleY, const Ice::Current &) override
Definition: ReflexCombination.cpp:794
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::ReflexCombination::reportJointCurrents
void reportJointCurrents(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:633
armarx::ReflexCombination::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
Definition: ReflexCombination.cpp:804
Eigen::Quaternionf
Quaternion< float, 0 > Quaternionf
Definition: EigenForwardDeclarations.h:61
armarx::ReflexCombinationPropertyDefinitions
Definition: ReflexCombination.h:64
q
#define q
Component.h
armarx::Reafference
@ Reafference
Definition: ReflexCombination.h:57
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ReflexCombination::onConnectComponent
void onConnectComponent() override
Definition: ReflexCombination.cpp:160
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::ReflexCombination::reportJointStatuses
void reportJointStatuses(const NameStatusMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:649
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
reflex.h
IceUtil::Handle< class PropertyDefinitionContainer >
MedianFilter.h
armarx::ReflexCombination::setReafferenceMethod
void setReafferenceMethod(bool isReafference, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:258
jointik.h
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ReflexCombination::reportJointVelocities
void reportJointVelocities(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:578
armarx::ReflexCombinationPropertyDefinitions::ReflexCombinationPropertyDefinitions
ReflexCombinationPropertyDefinitions(std::string prefix)
Definition: ReflexCombination.h:67
armarx::ReflexCombination::reportNewOpticalFlow
void reportNewOpticalFlow(Ice::Float, Ice::Float, Ice::Float, Ice::Long, const Ice::Current &) override
Definition: ReflexCombination.cpp:657
armarx::ReflexCombination::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ReflexCombination.cpp:211
armarx::ReflexCombination
Brief description of class ReflexCombination.
Definition: ReflexCombination.h:144
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ReflexCombination::onDisconnectComponent
void onDisconnectComponent() override
Definition: ReflexCombination.cpp:197
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19