ReflexCombination.cpp
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 #include "ReflexCombination.h"
24 
26 
27 
28 using namespace armarx;
29 
30 
32 {
33  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
34  usingProxy(getProperty<std::string>("RobotStateName").getValue());
35  offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
36  usingProxy(getProperty<std::string>("ImageSourceSelectionName").getValue());
37 
38  offeringTopic("DebugDrawerUpdates");
39 
40 
41  usingTopic(getProperty<std::string>("RobotNodeSetName").getValue() + "State");
42  usingTopic("IMUValues");
43  usingTopic("PlatformState");
44  usingTopic("HeadIKUnitTopic");
45  usingTopic("OpticalFlowTopic");
46  usingTopic("OpticalFlowOKRTopic");
47  //usingTopic("TrackingErrorTopic");
48 
49  armar4 = !(getProperty<std::string>("KinematicUnitName").getValue().find("Armar3") == 0);
50 
51  headIKName = getProperty<std::string>("HeadIKName").getValue();
52 
53  if (armar4)
54  {
55  eye_pitch_left = "EyeL_1_joint";
56  eye_pitch_right = "EyeR_1_joint";
57  eye_yaw_left = "EyeL_2_joint";
58  eye_yaw_right = "EyeR_2_joint";
59  neck_roll = "Neck_2_joint";
60  }
61  else
62  {
63  eye_pitch_left = "Cameras";
64  eye_yaw_left = "Eye_Left";
65  eye_yaw_right = "Eye_Right";
66  neck_roll = "Neck_2_Roll";
67 
68  headJointNames =
69  {
70  "Neck_1_Pitch",
71  neck_roll,
72  "Neck_3_Yaw",
73  eye_pitch_left,
74  eye_yaw_right,
75  eye_yaw_left
76  };
77  }
78 
79  velocityBased = getProperty<bool>("VelocityBasedControl").getValue();
80  neckPerturbation = getProperty<bool>("NeckPerturbation").getValue();
81 
82  if (getProperty<bool>("reafferenceCombination").getValue())
83  {
84  combinationMethod = Reafference;
85  }
86  else
87  {
88  combinationMethod = WeightedSum;
89  }
90 
91  ARMARX_LOG << "Velocity based: " << velocityBased;
92 
93  vorWeight = getProperty<float>("VOR").getValue();
94  okrWeight = getProperty<float>("OKR").getValue();
95  jointIKWeight = getProperty<float>("JointIK").getValue();
96 
97 
98 
99  kp = getProperty<float>("kp").getValue();
100  ki = getProperty<float>("ki").getValue();
101  kd = getProperty<float>("kd").getValue();
102 
103  vor = new VOR(5);
104  vor->setJointNames(eye_pitch_left, eye_pitch_right, eye_yaw_left, eye_yaw_right, neck_roll);
105  vor->setBools(armar4, velocityBased);
106  vor->setPIDValues(kp, ki, kd);
107 
108  jointIK = new FeedforwardReflex(7);
109  jointIK->setBools(armar4, velocityBased);
110 
111  okr = new OKR(10);
112  okr->setJointNames(eye_pitch_left, eye_pitch_right, eye_yaw_left, eye_yaw_right, neck_roll);
113  okr->setBools(armar4, velocityBased);
114  okr->setPIDValues(kp, ki, kd);
115 
116 
117  execCombineReflexesTask = new PeriodicTask<ReflexCombination>(this, &ReflexCombination::combineReflexes, 5, false, "ReflexCombinationTask");
118  execCombineReflexesTask->setDelayWarningTolerance(2);
119 
120 
121  // Filters initialization
122 
123  int sampling_size = 20;
124  IMU_GyroFilters["X"] = new armarx::filters::MedianFilter(sampling_size);
125  IMU_GyroFilters["X"]->update(0, new Variant((float)0.0));
126  IMU_GyroFilters["Y"] = new armarx::filters::MedianFilter(sampling_size);
127  IMU_GyroFilters["Y"]->update(0, new Variant((float)0.0));
128  IMU_GyroFilters["Z"] = new armarx::filters::MedianFilter(sampling_size);
129  IMU_GyroFilters["Z"]->update(0, new Variant((float)0.0));
130 
131  double frequency = 10.; // cut off frequency
132  int sampleRate = 100;
133  double resonance = 1.0; // should be between 0.1 and sqrt(2)
134 
135  std::map<std::string, float> filterProperties {{"minSampleTimeDelta", 100 * 1000.0}};
136 
137  for (auto& joint_name : headJointNames)
138  {
139 
140  VelocityFilters[joint_name] = new armarx::filters::DerivationFilter();
141  VelocityFilters[joint_name]->setProperties(filterProperties);
142  VelocityFilters[joint_name]->update(0, new Variant((double)0.0));
143 
144  PreVelocityFilters[joint_name] = new armarx::filters::ButterworthFilter(frequency, sampleRate, Lowpass, resonance);
145  PreVelocityFilters[joint_name]->setInitialValue(0.);
146  PreVelocityFilters[joint_name]->update(0, new Variant((double)0.0));
147 
148  }
149 
150  frequency = 5.0;
151  sampleRate = 100;
152  resonance = 1.0;
153  FlowFilters["X"] = new armarx::filters::ButterworthFilter(frequency, sampleRate, Lowpass, resonance);
154  FlowFilters["X"]->setInitialValue(0.);
155  FlowFilters["X"]->update(0, new Variant((float)0.0));
156  FlowFilters["Y"] = new armarx::filters::ButterworthFilter(frequency, sampleRate, Lowpass, resonance);
157  FlowFilters["Y"]->setInitialValue(0.);
158  FlowFilters["Y"]->update(0, new Variant((float)0.0));
159 
160 
161 
162  t_init = armarx::TimeUtil::GetTime().toMilliSecondsDouble() / 1000.;
163 
164 }
165 
166 
168 {
169  kinUnitPrx = getProxy<KinematicUnitInterfacePrx>(getProperty<std::string>("KinematicUnitName").getValue());
170  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(getProperty<std::string>("RobotStateName").getValue());
171 
172  debugObserver = getTopic<DebugObserverInterfacePrx>(getProperty<std::string>("DebugObserverName").getValue());
173  imageSourceSelection = getProxy<ImageSourceSelectionInterfacePrx>(getProperty<std::string>("ImageSourceSelectionName").getValue());
174 
175  drawer = getTopic<DebugDrawerInterfacePrx>("DebugDrawerUpdates");
176 
177 
178  std::string nodeSetName = getProperty<std::string>("RobotNodeSetName").getValue();
179 
180  jointIK->setRobot(nodeSetName, headIKName, robotStateComponent);
181 
182 
183  FramedPosePtr dummy = new FramedPose();
184 
185  ARMARX_LOG << "Armar4: " << armar4;
186 
187  updateWeights(vorWeight, okrWeight, jointIKWeight);
188 
189  if ((combinationMethod == Reafference) && !jointIKEnabled)
190  {
191  ARMARX_WARNING << "Reafference combination cannot work without IK method enabled. Setting to weighted sum imnstead";
192  combinationMethod = WeightedSum;
193  }
194 
195  execCombineReflexesTask->start();
196 
197 }
198 
199 
201 {
202  execCombineReflexesTask->stop();
203 }
204 
205 
207 {
208  delete vor;
209  delete jointIK;
210  delete okr;
211 
212 }
213 
215 {
218 }
219 
220 void ReflexCombination::updateWeights(float vorWeight, float okrWeight, float jointIKWeight, const Ice::Current& c)
221 {
222 
223 
224  ARMARX_LOG << "new reflex weights vor:" << vorWeight << " okr:" << okrWeight << " jointik:" << jointIKWeight;
225 
226 
227  StringVariantBaseMap debugValues;
228  debugValues["reflexes_vor"] = new Variant(vorWeight);
229  debugValues["reflexes_okr"] = new Variant(okrWeight);
230  debugValues["reflexes_ik"] = new Variant(jointIKWeight);
231 
232  debugObserver->setDebugChannel("ReflexCombination", debugValues);
233 
234 
235  std::scoped_lock lock(mutex);
236 
237  this->vorWeight = vorWeight;
238  this->okrWeight = okrWeight;
239  this->jointIKWeight = jointIKWeight;
240 
241  vorEnabled = (vorWeight > 0);
242  jointIKEnabled = (jointIKWeight > 0);
243  okrEnabled = (okrWeight > 0);
244 
245  ARMARX_LOG << "enabled reflexes vor:" << vorEnabled << " okr:" << okrEnabled << " jointik:" << jointIKEnabled;
246 
247  vor->setEnabled(vorEnabled);
248  okr->setEnabled(okrEnabled);
249  jointIK->setEnabled(jointIKEnabled);
250 
251  ARMARX_LOG << "reflexes enabled.";
252 }
253 
254 void ReflexCombination::setReafferenceMethod(bool isReafference, const Ice::Current& c)
255 {
256  if (isReafference)
257  {
258  this->combinationMethod = Reafference;
259  }
260  else
261  {
262  this->combinationMethod = WeightedSum;
263  }
264 }
265 
266 void ReflexCombination::combineReflexes()
267 {
268  std::scoped_lock lock(mutex);
269 
270  if (!(vorEnabled || jointIKEnabled || okrEnabled))
271  {
272  ARMARX_LOG << deactivateSpam(1) << "at least one reflex must be enabled to stabilize the gaze!";
273  return;
274  }
275 
276  if (newHeadTarget)
277  {
278  ARMARX_LOG << deactivateSpam(1) << "waiting for new head position";
279  return;
280  }
281 
282  // lock.unlock();
283 
284  NameValueMap resultJointValues;
285  NameControlModeMap controlModes;
286 
287  std::map<std::string, float> weights;
288  std::map<std::string, float> jointValuesIK = jointIK->getJoints();
289  std::map<std::string, float> jointValuesVOR = vor->getJoints();
290  std::map<std::string, float> jointValuesOKR = okr->getJoints();
291 
292 
293  // logging to debug observed via single channel using the map
294  StringVariantBaseMap mapValues;
295  mapValues["optFlow_predX"] = new Variant(jointIK->optFlow_pred[0]);
296  mapValues["optFlow_predY"] = new Variant(jointIK->optFlow_pred[1]);
297  mapValues["meanOptFlow_pred"] = new Variant((float)jointIK->mean_optFl_pred);
298  mapValues["imu_gyro_predX"] = new Variant(jointIK->gyroscopeRotation_pred[0]);
299  mapValues["imu_gyro_predY"] = new Variant(jointIK->gyroscopeRotation_pred[1]);
300  mapValues["imu_gyro_predZ"] = new Variant(jointIK->gyroscopeRotation_pred[2]);
301  mapValues["vel_filtered"] = new Variant(VelocityFilters[eye_yaw_left]->getValue()->getDouble());
302  mapValues["flow_filteredX"] = new Variant(FlowFilters["X"]->getValue()->getDouble());
303  mapValues["flow_filteredY"] = new Variant(FlowFilters["Y"]->getValue()->getDouble());
304  mapValues["imu_filteredX"] = new Variant(IMU_GyroFilters["X"]->getValue()->getFloat());
305  mapValues["imu_filteredY"] = new Variant(IMU_GyroFilters["Y"]->getValue()->getFloat());
306  mapValues["imu_filteredZ"] = new Variant(IMU_GyroFilters["Z"]->getValue()->getFloat());
307  debugObserver->setDebugChannel("ForwardPredictor", mapValues);
308 
309  /*
310 
311  for (auto & r : reflexes)
312  {
313  float w = r.second->getWeight();
314 
315  for (auto & kv : r.second->getJoints())
316  {
317  if (!resultJointValues.count(kv.first))
318  {
319  resultJointValues[kv.first] = 0;
320  weights[kv.first] = 0;
321  }
322  resultJointValues[kv.first] += w * kv.second;
323  weights[kv.first] += w;
324  }
325  }
326 
327  */
328 
329 
330  // Add up references of each reflexes
331 
332  for (auto& kv : jointValuesIK)
333  {
334  if (!resultJointValues.count(kv.first))
335  {
336  resultJointValues[kv.first] = 0;
337  weights[kv.first] = 0;
338  }
339  resultJointValues[kv.first] += jointIKWeight * kv.second;
340  weights[kv.first] += jointIKWeight;
341  }
342 
343  for (auto& kv : jointValuesVOR)
344  {
345  if (!resultJointValues.count(kv.first))
346  {
347  resultJointValues[kv.first] = 0;
348  weights[kv.first] = 0;
349  }
350  resultJointValues[kv.first] += vorWeight * kv.second;
351  weights[kv.first] += vorWeight;
352  }
353 
354  for (auto& kv : jointValuesOKR)
355  {
356  if (!resultJointValues.count(kv.first))
357  {
358  resultJointValues[kv.first] = 0;
359  weights[kv.first] = 0;
360  }
361  resultJointValues[kv.first] += okrWeight * kv.second;
362  weights[kv.first] += okrWeight;
363  //ARMARX_LOG << "okr vel " << kv.first << "= " << kv.second;
364  }
365 
366 
367  if (combinationMethod == WeightedSum)
368  {
369  // normalize joint ref
370  for (auto& kv : weights)
371  {
372  resultJointValues[kv.first] = resultJointValues[kv.first] / kv.second;
373  }
374  }
375 
376  // send command to controller
377  if (resultJointValues.empty())
378  {
379  return;
380  }
381 
382 
383  // set the unset velocities to 0
384  if (velocityBased)
385  {
386  for (auto const& headJoint : headJointNames)
387  {
388  if (resultJointValues.find(headJoint) == resultJointValues.end())
389  {
390  resultJointValues[headJoint] = 0.;
391  }
392  }
393  }
394 
395  // position tracking to keep eyes parrallel (necessary for stereo calibration)
396  if (velocityBased)
397  {
398  try
399  {
400  double kp = 5.;
401  resultJointValues["Eye_Left"] = resultJointValues["Eye_Right"] + kp * (PreVelocityFilters["Eye_Right"]->getValue()->getDouble() - PreVelocityFilters["Eye_Left"]->getValue()->getDouble());
402 
403  }
404  catch (...)
405  {
406 
407  }
408  }
409 
410  for (auto& kv : resultJointValues)
411  {
412  if (velocityBased)
413  {
414  controlModes[kv.first] = eVelocityControl;
415  }
416  else
417  {
418  controlModes[kv.first] = ePositionControl;
419  }
420  }
421 
422  if (neckPerturbation && velocityBased)
423  {
424  controlModes["Neck_3_Yaw"] = eVelocityControl;
425  resultJointValues["Neck_3_Yaw"] = 4. * cos((armarx::TimeUtil::GetTime().toMilliSecondsDouble() / 1000. - t_init));
426  }
427 
428  try
429  {
430  // ARMARX_LOG << deactivateSpam(1) << resultJointValues;
431  //ARMARX_IMPORTANT_S << "joint vel reflex comb" << resultJointValues;
432 
433  StringVariantBaseMap debugValues;
434 
435  for (auto& kv : resultJointValues)
436  {
437  debugValues[kv.first] = new Variant(kv.second);
438  }
439 
440  debugObserver->setDebugChannel("ReflexCombination", debugValues);
441 
442 
443  StringVariantBaseMap debugValuesIK;
444  for (auto& kv : jointValuesIK)
445  {
446  debugValuesIK[kv.first] = new Variant(kv.second);
447  }
448  debugObserver->setDebugChannel("ReflexCombinationIK", debugValuesIK);
449 
450  StringVariantBaseMap debugValuesOKR;
451  for (auto& kv : jointValuesOKR)
452  {
453  debugValuesOKR[kv.first] = new Variant(kv.second);
454  }
455  debugObserver->setDebugChannel("ReflexCombinationOKR", debugValuesOKR);
456 
457  StringVariantBaseMap debugValuesVOR;
458  for (auto& kv : jointValuesVOR)
459  {
460  debugValuesVOR[kv.first] = new Variant(kv.second);
461  }
462  debugObserver->setDebugChannel("ReflexCombinationVOR", debugValuesVOR);
463 
464  kinUnitPrx->switchControlMode(controlModes);
465  if (velocityBased)
466  {
467  kinUnitPrx->setJointVelocities(resultJointValues);
468  }
469  else
470  {
471  kinUnitPrx->setJointAngles(resultJointValues);
472  }
473  }
474  catch (...)
475  {
476  ARMARX_IMPORTANT << "Setting joint values failed!";
477  }
478 
479 }
480 
481 
482 void ReflexCombination::reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current& c)
483 {
484  if (jointIKEnabled)
485  {
486  //jointIK->reportPlatformVelocity(currentPlatformVelocityX, currentPlatformVelocityY, currentPlatformVelocityRotation);
487  }
488 }
489 
490 void armarx::ReflexCombination::reportControlModeChanged(const NameControlModeMap&, Ice::Long timestamp, bool, const Ice::Current&)
491 {
492 }
493 
494 void armarx::ReflexCombination::reportJointAngles(const NameValueMap& values, Ice::Long timestamp, bool valueChanged, const Ice::Current& c)
495 {
496  std::scoped_lock lock(mutex);
497 
498  NameValueMap tmp = values;
499 
500  if (newHeadTarget)
501  {
502  float offset = 0.1f;
503  bool jointAnglesReached = true;
504  for (std::pair<std::string, Ice::Float> joint : targetJointAngles)
505  {
506  jointAnglesReached &= (tmp[joint.first] >= (joint.second - offset));
507  jointAnglesReached &= (tmp[joint.first] <= (joint.second + offset));
508  }
509 
510  if (jointAnglesReached)
511  {
512  newHeadTarget = false;
513 
514  ARMARX_LOG << deactivateSpam(1) << "new head target reached";
515 
516  if (vorEnabled)
517  {
518  vor->start();
519  }
520 
521 
522  if (jointIKEnabled)
523  {
524  jointIK->start();
525  }
526  if (okrEnabled)
527  {
528  okr->start();
529  }
530 
531  }
532  else
533  {
534  return;
535  }
536  }
537 
538  if (vorEnabled)
539  {
540  vor->reportJointAngles(values, valueChanged, c);
541  }
542  if (jointIKEnabled)
543  {
544  jointIK->reportJointAngles(values, valueChanged, c);
545  }
546  if (okrEnabled)
547  {
548  okr->reportJointAngles(values, valueChanged, c);
549  }
550 
551  // velocity estimation from position (velocity sensing not working in mca)
552  for (auto& joint_name : headJointNames)
553  {
554  PreVelocityFilters[joint_name]->update(timestamp, new Variant(tmp[joint_name]));
555  VelocityFilters[joint_name]->update(timestamp, new Variant(PreVelocityFilters[joint_name]->getValue()->getDouble()));
556  }
557 }
558 
559 void armarx::ReflexCombination::reportJointVelocities(const NameValueMap& velocities, Ice::Long timestamp, bool valueChanged, const Ice::Current& c)
560 {
561 
562  std::scoped_lock lock(mutex);
563  NameValueMap velocities_filtered(velocities);
564  for (auto& joint_name : headJointNames)
565  {
566  if (velocities_filtered.count(joint_name))
567  {
568  velocities_filtered[joint_name] = VelocityFilters[joint_name]->getValue()->getDouble();
569  }
570  }
571 
572 
573 
574  if (vorEnabled)
575  {
576  vor->reportJointVelocities(velocities_filtered, valueChanged, c);
577  }
578  if (jointIKEnabled)
579  {
580  jointIK->reportJointVelocities(velocities_filtered, valueChanged, c);
581  }
582  if (okrEnabled)
583  {
584  if (combinationMethod == Reafference && jointIKEnabled)
585  {
586  velocities_filtered[eye_yaw_left] = 0.; // no need of removing self induced velocities as already removed by the prediction
587  velocities_filtered[eye_yaw_right] = 0.;
588  velocities_filtered[eye_pitch_left] = 0.;
589  }
590  okr->reportJointVelocities(velocities_filtered, valueChanged, timestamp, c);
591  }
592 
593 }
594 
595 void armarx::ReflexCombination::reportJointTorques(const NameValueMap&, Ice::Long timestamp, bool, const Ice::Current&)
596 {
597 }
598 
599 void armarx::ReflexCombination::reportJointAccelerations(const NameValueMap&, Ice::Long timestamp, bool, const Ice::Current&)
600 {
601 }
602 
603 void armarx::ReflexCombination::reportJointCurrents(const NameValueMap&, Ice::Long timestamp, bool, const Ice::Current&)
604 {
605 }
606 
607 void armarx::ReflexCombination::reportJointMotorTemperatures(const NameValueMap&, Ice::Long timestamp, bool, const Ice::Current&)
608 {
609 
610 }
611 
612 void armarx::ReflexCombination::reportJointStatuses(const NameStatusMap&, Ice::Long timestamp, bool, const Ice::Current&)
613 {
614 }
615 
617 {
618 
619  std::scoped_lock lock(mutex);
620 
621  FlowFilters["X"]->update(timestamp, new Variant(x));
622  FlowFilters["Y"]->update(timestamp, new Variant(y));
623 
624  double x_flow, y_flow;
625 
626  x_flow = FlowFilters["X"]->getValue()->getDouble();
627  y_flow = FlowFilters["Y"]->getValue()->getDouble();
628 
629  // no filtering
630  //x_flow = x;
631  //y_flow = y;
632 
633  if (combinationMethod == Reafference && jointIKEnabled)
634  {
635  x_flow -= jointIK->optFlow_pred[0];
636  y_flow -= jointIK->optFlow_pred[1];
637 
638  if (fabs(x_flow) < 0.04)
639  {
640  x_flow = 0.;
641  }
642  }
643 
644  if (okrEnabled)
645  {
646  okr->reportNewOpticalFlow(x_flow, y_flow, deltaT, timestamp);
647  }
648 }
649 
650 
651 void armarx::ReflexCombination::reportHeadTargetChanged(const NameValueMap& targetJointAngles, const FramedPositionBasePtr& targetPosition, const Ice::Current&)
652 {
653 
654  std::scoped_lock lock(mutex);
655 
656  newHeadTarget = true;
657  this->targetJointAngles = targetJointAngles;
658 
659  ARMARX_INFO << " new head target " << targetPosition->output();
660 
661  if (jointIKEnabled)
662  {
663  jointIK->stop();
664  }
665  jointIK->reportHeadTargetChanged(targetJointAngles, targetPosition);
666 
667  if (vorEnabled)
668  {
669  vor->stop();
670  }
671  if (okrEnabled)
672  {
673  okr->stop();
674  }
675 
676 
677 }
678 
679 void armarx::ReflexCombination::reportSensorValues(const std::string& device, const std::string& name, const IMUData& values, const TimestampBasePtr& timestamp, const Ice::Current& c)
680 {
681 
682 
683  std::scoped_lock lock(mutex);
684 
685  /*
686  Eigen::Quaternionf qTemp = Eigen::Quaternionf(values.orientationQuaternion[0], values.orientationQuaternion[1], values.orientationQuaternion[2], values.orientationQuaternion[3]);
687  Eigen::Vector3f rpy = quaternionToRPY(qTemp);
688  ARMARX_LOG << deactivateSpam(1) << "RPY: " << rpy[0] << " " << rpy[1] << " " << rpy[2];
689  ARMARX_LOG << deactivateSpam(1) << "Quat: " << qTemp.w() << " " << qTemp.x() << " " << qTemp.y() << " " << qTemp.z();
690  */
691  if (IMU_GyroFilters["X"] && IMU_GyroFilters["Y"] && IMU_GyroFilters["Z"])
692  {
693  IMU_GyroFilters["X"]->update(timestamp->timestamp, new Variant((float) values.gyroscopeRotation[0]));
694  IMU_GyroFilters["Y"]->update(timestamp->timestamp, new Variant((float) values.gyroscopeRotation[1]));
695  IMU_GyroFilters["Z"]->update(timestamp->timestamp, new Variant((float) values.gyroscopeRotation[2]));
696  }
697 
698  IMUData values2 = values;
699 
700  if (IMU_GyroFilters["X"] && IMU_GyroFilters["Y"] && IMU_GyroFilters["Z"])
701  {
702  values2.gyroscopeRotation[0] = IMU_GyroFilters["X"]->getValue()->getFloat();
703  values2.gyroscopeRotation[1] = IMU_GyroFilters["Y"]->getValue()->getFloat();
704  values2.gyroscopeRotation[2] = IMU_GyroFilters["Z"]->getValue()->getFloat();
705  }
706 
707  if (combinationMethod == Reafference && jointIKEnabled)
708  {
709  values2.gyroscopeRotation[0] -= jointIK->gyroscopeRotation_pred[0];
710  values2.gyroscopeRotation[1] -= jointIK->gyroscopeRotation_pred[1];
711  values2.gyroscopeRotation[2] -= jointIK->gyroscopeRotation_pred[2];
712 
713  if (fabs(values2.gyroscopeRotation[2]) < 0.04)
714  {
715  values2.gyroscopeRotation[2] = 0.;
716  }
717  }
718 
719  if (vorEnabled)
720  {
721  vor->reportSensorValues(values2);
722  }
723 }
724 
725 
726 
727 void armarx::ReflexCombination::setImageQuality(float quality)
728 {
729  Ice::StringSeq imageSources = getProperty<Ice::StringSeq>("ImageProviders");
730  ARMARX_CHECK_GREATER_EQUAL(imageSources.size(), 2) << imageSources;
731  if (quality > 0.7)
732  {
733  imageSourceSelection->setImageSource(imageSources[1], 100000000);
734  }
735  else
736  {
737  imageSourceSelection->setImageSource(imageSources[0], 100000000);
738  }
739 }
740 
741 void armarx::ReflexCombination::reportNewTrackingError(Ice::Float pixelX, Ice::Float pixelY, Ice::Float angleX, Ice::Float angleY, const Ice::Current&)
742 {
743  okr->reportNewTrackingError(pixelX, pixelY, angleX, angleY);
744 }
745 
746 
748 {
749 }
armarx::ReflexCombination::reportJointTorques
void reportJointTorques(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:595
armarx::ReflexCombination::reportHeadTargetChanged
void reportHeadTargetChanged(const NameValueMap &targetJointAngles, const FramedPositionBasePtr &targetPosition, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:651
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::ReflexCombination::onInitComponent
void onInitComponent() override
Definition: ReflexCombination.cpp:31
ReflexCombination.h
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::ReflexCombination::updateWeights
void updateWeights(float vor, float okr, float jointIK, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:220
armarx::FeedforwardReflex::optFlow_pred
std::vector< float > optFlow_pred
Definition: feedforward.h:90
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::ReflexCombination::reportJointMotorTemperatures
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:607
armarx::OKR::setJointNames
void setJointNames(std::string eye_pitch_left, std::string eye_pitch_right, std::string eye_yaw_left, std::string eye_yaw_right, std::string neck_roll)
Definition: okr.cpp:156
armarx::WeightedSum
@ WeightedSum
Definition: ReflexCombination.h:57
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::OKR::setPIDValues
void setPIDValues(float kp, float ki, float kd)
Definition: okr.cpp:166
armarx::OKR
Definition: okr.h:33
armarx::ReflexCombination::onExitComponent
void onExitComponent() override
Definition: ReflexCombination.cpp:206
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::VOR::setJointNames
void setJointNames(std::string eye_pitch_left, std::string eye_pitch_right, std::string eye_yaw_left, std::string eye_yaw_right, std::string neck_roll)
Definition: vor.cpp:145
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ReflexCombination::reportJointAngles
void reportJointAngles(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:494
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:679
armarx::ReflexCombination::reportPlatformVelocity
void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:482
armarx::ReflexCombination::reportControlModeChanged
void reportControlModeChanged(const NameControlModeMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:490
armarx::FeedforwardReflex::setBools
void setBools(bool armar4, bool velocityBased)
Definition: feedforward.cpp:239
armarx::VOR
Definition: vor.h:36
IceInternal::Handle< FramedPose >
armarx::FeedforwardReflex
Definition: feedforward.h:46
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
ObserverObjectFactories.h
armarx::filters::MedianFilter
The MedianFilter class provides an implementation for a median for datafields of type float,...
Definition: MedianFilter.h:46
armarx::VOR::setPIDValues
void setPIDValues(float kp, float ki, float kd)
Definition: vor.cpp:156
armarx::filters::ButterworthFilter
Definition: ButterworthFilter.h:40
armarx::ReflexCombination::reportJointAccelerations
void reportJointAccelerations(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:599
armarx::VOR::setBools
void setBools(bool armar4, bool velocityBased)
Definition: vor.cpp:165
armarx::Reflex::getJoints
std::map< std::string, float > getJoints()
Definition: reflex.h:85
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::ReflexCombination::reportNewTrackingError
void reportNewTrackingError(Ice::Float pixelX, Ice::Float pixelY, Ice::Float angleX, Ice::Float angleY, const Ice::Current &) override
Definition: ReflexCombination.cpp:741
armarx::ReflexCombination::reportJointCurrents
void reportJointCurrents(const NameValueMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:603
armarx::ReflexCombination::reportPlatformOdometryPose
void reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current &) override
Definition: ReflexCombination.cpp:747
armarx::ReflexCombinationPropertyDefinitions
Definition: ReflexCombination.h:64
ARMARX_CHECK_GREATER_EQUAL
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
Definition: ExpressionException.h:123
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
armarx::Reafference
@ Reafference
Definition: ReflexCombination.h:57
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::control::common::getValue
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
Definition: utils.h:71
armarx::ReflexCombination::onConnectComponent
void onConnectComponent() override
Definition: ReflexCombination.cpp:167
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::ReflexCombination::reportJointStatuses
void reportJointStatuses(const NameStatusMap &, Ice::Long timestamp, bool, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:612
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::FeedforwardReflex::setRobot
void setRobot(std::string nodeSetName, std::string headIKName, RobotStateComponentInterfacePrx robotStateComponent)
Definition: feedforward.cpp:49
armarx::ReflexCombination::setReafferenceMethod
void setReafferenceMethod(bool isReafference, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:254
armarx::OKR::setBools
void setBools(bool armar4, bool velocityBased)
Definition: okr.cpp:175
armarx::FeedforwardReflex::gyroscopeRotation_pred
std::vector< float > gyroscopeRotation_pred
Definition: feedforward.h:92
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:92
armarx::ReflexCombination::reportJointVelocities
void reportJointVelocities(const NameValueMap &values, Ice::Long timestamp, bool valueChanged, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ReflexCombination.cpp:559
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::ReflexCombination::reportNewOpticalFlow
void reportNewOpticalFlow(Ice::Float, Ice::Float, Ice::Float, Ice::Long, const Ice::Current &) override
Definition: ReflexCombination.cpp:616
armarx::ReflexCombination::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ReflexCombination.cpp:214
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::FeedforwardReflex::mean_optFl_pred
double mean_optFl_pred
Definition: feedforward.h:91
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::filters::DerivationFilter
The DerivationFilter calculates the derivate of a datafield.
Definition: DerivationFilter.h:34
armarx::ReflexCombination::onDisconnectComponent
void onDisconnectComponent() override
Definition: ReflexCombination.cpp:200
armarx::Reflex::setEnabled
void setEnabled(bool enabled)
Definition: reflex.h:73