NJointCartesianNaturalPositionController.cpp
Go to the documentation of this file.
2 
3 #include <iomanip>
4 
5 #include <VirtualRobot/math/Helpers.h>
6 
8 
14 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
15 
16 namespace armarx
17 {
18  std::string
19  vec2str(const std::vector<float>& vec)
20  {
21  std::stringstream ss;
22  for (size_t i = 0; i < vec.size(); i++)
23  {
24  if (i > 0)
25  {
26  ss << ", ";
27  }
28  ss << vec.at(i);
29  }
30  return ss.str();
31  }
32 
33  std::ostream&
34  operator<<(std::ostream& out, const CartesianNaturalPositionControllerConfig& cfg)
35  {
36  out << "maxPositionAcceleration " << cfg.maxPositionAcceleration << '\n'
37  << "maxOrientationAcceleration " << cfg.maxOrientationAcceleration << '\n'
38  << "maxNullspaceAcceleration " << cfg.maxNullspaceAcceleration << '\n'
39 
40  << "KpPos " << cfg.KpPos << '\n'
41  << "KpOri " << cfg.KpOri << '\n'
42  << "maxTcpPosVel " << cfg.maxTcpPosVel << '\n'
43  << "maxTcpOriVel " << cfg.maxTcpOriVel << '\n'
44  << "maxElpPosVel " << cfg.maxElbPosVel << '\n'
45 
46  << "maxJointVelocity " << vec2str(cfg.maxJointVelocity) << '\n'
47  << "maxNullspaceVelocity " << vec2str(cfg.maxNullspaceVelocity) << '\n'
48  << "jointCosts " << vec2str(cfg.jointCosts) << '\n'
49 
50  << "jointLimitAvoidanceKp " << cfg.jointLimitAvoidanceKp << '\n'
51  << "elbowKp " << cfg.elbowKp << '\n'
52  << "nullspaceTargetKp " << cfg.nullspaceTargetKp << '\n'
53 
54  ;
55  return out;
56  }
57 
58  NJointControllerRegistration<NJointCartesianNaturalPositionController>
60  "NJointCartesianNaturalPositionController");
61 
62  std::string
64  {
65  return "NJointCartesianNaturalPositionController";
66  }
67 
69  RobotUnit*,
70  const NJointCartesianNaturalPositionControllerConfigPtr& config,
72  {
73  ARMARX_CHECK_NOT_NULL(config);
74 
75  //ARMARX_IMPORTANT << VAROUT(config->rns);
76  //ARMARX_IMPORTANT << config->runCfg;
77 
78  //robot
79  {
80  _rtRobot = useSynchronizedRtRobot();
81  ARMARX_CHECK_NOT_NULL(_rtRobot);
82 
83  _rtRns = _rtRobot->getRobotNodeSet(config->rns);
84  ARMARX_CHECK_NOT_NULL(_rtRns) << "No rns " << config->rns;
85  _rtTcp = _rtRns->getTCP();
86  ARMARX_CHECK_NOT_NULL(_rtTcp) << "No tcp in rns " << config->rns;
87  _rtElbow = _rtRobot->getRobotNode(config->elbowNode);
88  ARMARX_CHECK_NOT_NULL(_rtElbow) << "No elbow node " << config->elbowNode;
89 
90  _rtRobotRoot = _rtRobot->getRootNode();
91  }
92  //ARMARX_IMPORTANT << "got robot";
93 
94  //sensor
95  {
96  if (!config->ftName.empty())
97  {
98  const auto svalFT = useSensorValue<SensorValueForceTorque>(config->ftName);
99  ARMARX_CHECK_NOT_NULL(svalFT) << "No sensor value of name " << config->ftName;
100  _rtForceSensor = &(svalFT->force);
101  _rtTorqueSensor = &(svalFT->force);
102 
103  const auto sdev = peekSensorDevice(config->ftName);
104  ARMARX_CHECK_NOT_NULL(sdev);
105 
106  const auto reportFrameName = sdev->getReportingFrame();
107  ARMARX_CHECK_EXPRESSION(!reportFrameName.empty())
108  << VAROUT(sdev->getReportingFrame());
109 
110  _rtFT = _rtRobot->getRobotNode(reportFrameName);
111  ARMARX_CHECK_NOT_NULL(_rtFT)
112  << "No sensor report frame '" << reportFrameName << "' in robot";
113  }
114  }
115  //ARMARX_IMPORTANT << "got sensor";
116  //ctrl
117  {
118  _rtJointVelocityFeedbackBuffer =
119  Eigen::VectorXf::Zero(static_cast<int>(_rtRns->getSize()));
120 
121  _rtPosController = std::make_unique<CartesianNaturalPositionController>(
122  _rtRns,
123  _rtElbow,
124  config->runCfg.maxPositionAcceleration,
125  config->runCfg.maxOrientationAcceleration,
126  config->runCfg.maxNullspaceAcceleration);
127 
128  _rtPosController->setConfig(config->runCfg);
129  ARMARX_IMPORTANT << "controller config: " << config->runCfg;
130 
131  for (size_t i = 0; i < _rtRns->getSize(); ++i)
132  {
133  std::string jointName = _rtRns->getNode(i)->getName();
134  auto ct = useControlTarget<ControlTarget1DoFActuatorVelocity>(
135  jointName, ControlModes::Velocity1DoF);
136  auto sv = useSensorValue<SensorValue1DoFActuatorVelocity>(jointName);
139 
140  _rtVelTargets.emplace_back(&(ct->velocity));
141  _rtVelSensors.emplace_back(&(sv->velocity));
142  }
143  }
144 
145  _rtFFvelMaxAgeMS = config->feedforwardVelocityTTLms;
146 
147  _rtFTHistory.resize(config->ftHistorySize, FTval());
148 
149  //ARMARX_IMPORTANT << "got control";
150  //visu
151  {
152  _tripFakeRobotGP.getWriteBuffer()(0, 0) = std::nanf("");
153  _tripFakeRobotGP.commitWrite();
154  }
155  //ARMARX_IMPORTANT << "got visu";
156  }
157 
158  void
160  {
161  //_publishIsAtTarget = false;
162  //_rtForceOffset = Eigen::Vector3f::Zero();
163 
164  _publish.errorPos = 0;
165  _publish.errorOri = 0;
166  _publish.errorPosMax = 0;
167  _publish.errorOriMax = 0;
168  _publish.tcpPosVel = 0;
169  _publish.tcpOriVel = 0;
170  _publish.elbPosVel = 0;
171  //_publish.targetReached = false;
172  //_publishForceThreshold = _rtForceThreshold;
173  _rtPosController->setTarget(_rtTcp->getPoseInRootFrame(),
174  _rtElbow->getPositionInRootFrame());
175  }
176 
177  void
179  const IceUtil::Time& timeSinceLastIteration)
180  {
181  auto& rt2nonrtBuf = _tripRt2NonRt.getWriteBuffer();
182 
183  if (_tripBufCfg.updateReadBuffer())
184  {
185  ARMARX_RT_LOGF_IMPORTANT("updates in tripple buffer cfg");
186  auto& r = _tripBufCfg._getNonConstReadBuffer();
187  if (r.updated)
188  {
189  r.updated = false;
190  _rtPosController->setConfig(r.cfg);
191  ARMARX_RT_LOGF_IMPORTANT("updated the controller config");
192  }
193  }
194  if (_tripBufTarget.updateReadBuffer())
195  {
196  ARMARX_RT_LOGF_IMPORTANT("updates in tripple buffer target");
197  auto& r = _tripBufTarget._getNonConstReadBuffer();
198  if (r.updated)
199  {
200  r.updated = false;
201  _rtSetOrientation = r.setOrientation;
202  _rtPosController->setTarget(r.tcpTarget, r.elbowTarget);
203  _rtStopConditionReached = false;
204  _publishIsAtForceLimit = false;
205  }
206  }
207  if (_tripBufNullspaceTarget.updateReadBuffer())
208  {
209  ARMARX_RT_LOGF_IMPORTANT("updates in tripple buffer NullspaceTarget");
210  auto& r = _tripBufNullspaceTarget._getNonConstReadBuffer();
211  if (r.updated)
212  {
213  r.updated = false;
214  if (r.clearRequested)
215  {
216  _rtPosController->clearNullspaceTarget();
217  }
218  else
219  {
220  ARMARX_RT_LOGF_IMPORTANT("_rtPosController->setNullspaceTarget");
221  _rtPosController->setNullspaceTarget(r.nullspaceTarget);
222  }
223  r.clearRequested = false;
224  }
225  }
226  if (_tripBufFFvel.updateReadBuffer())
227  {
228  _rtFFvel = _tripBufFFvel.getReadBuffer();
229  _rtFFvelLastUpdateMS = sensorValuesTimestamp.toMilliSeconds();
230  }
231  if (_tripBufFToffset.updateReadBuffer())
232  {
233  _rtFTOffset = _tripBufFToffset.getReadBuffer();
234  }
235  if (_tripBufFTlimit.updateReadBuffer())
236  {
237  _rtFTlimit = _tripBufFTlimit.getReadBuffer();
238  if (_rtFTlimit.force < 0 && _rtFTlimit.torque < 0)
239  {
240  _publishIsAtForceLimit = false;
241  }
242  }
243  if (_tripBufFTfake.updateReadBuffer())
244  {
245  _rtFTfake = _tripBufFTfake.getReadBuffer();
246  }
247 
248  //run
249  //bool reachedTarget = false;
250  //bool reachedFtLimit = false;
251 
252  if (_rtForceSensor)
253  {
254  /*const Eigen::Vector3f ftInRoot =
255  _rtFT->getTransformationTo(_rtRobotRoot)
256  .topLeftCorner<3, 3>()
257  .transpose() *
258  (*_rtForceSensor);*/
259  //rt2nonrtBuf.ft.force = ftInRoot;
260  //rt2nonrtBuf.ft.torque = *_rtTorqueSensor;
261  //rt2nonrtBuf.ft.timestampInUs = sensorValuesTimestamp.toMicroSeconds();
262  //rt2nonrtBuf.ftInRoot = _rtFT->getPoseInRootFrame();
263 
264  FTval ft;
265  ft.force = *_rtForceSensor;
266  ft.torque = *_rtTorqueSensor;
267 
268  if (_rtFTfake.use)
269  {
270  ft.force = _rtFTfake.force;
271  ft.torque = _rtFTfake.torque;
272  ARMARX_RT_LOGF_VERBOSE("Using fake ft values");
273  }
274 
275  _rtFTHistory.at(_rtFTHistoryIndex) = ft;
276  _rtFTHistoryIndex = (_rtFTHistoryIndex + 1) % _rtFTHistory.size();
277 
278  FTval ftAvg;
279  for (size_t i = 0; i < _rtFTHistory.size(); i++)
280  {
281  ftAvg.force += _rtFTHistory.at(i).force;
282  ftAvg.torque += _rtFTHistory.at(i).torque;
283  }
284  ftAvg.force = ftAvg.force / _rtFTHistory.size();
285  ftAvg.torque = ftAvg.torque / _rtFTHistory.size();
286 
287 
288  rt2nonrtBuf.currentFT = ft;
289  rt2nonrtBuf.averageFT = ftAvg;
290 
291  if ((_rtFTlimit.force > 0 && ft.force.norm() > _rtFTlimit.force) ||
292  (_rtFTlimit.torque > 0 && ft.torque.norm() > _rtFTlimit.torque))
293  {
294  _rtStopConditionReached = true;
295  _publishIsAtForceLimit = true;
296  }
297 
298  //Eigen::Vector3f ftVal = ftInRoot;
299  //if (_rtForceThresholdInRobotRootZ)
300  //{
301  // ftVal(0) = 0;
302  // ftVal(1) = 0;
303  //}
304  //if (_setFTOffset)
305  //{
306  // _rtForceOffset = ftVal;
307  // _setFTOffset = false;
308  // _publishIsAtForceLimit = false;
309  //}
310  //rt2nonrtBuf.ftUsed = ftVal;
311 
312  //const float currentForce = std::abs(ftVal.norm() - _rtForceOffset.norm());
313 
314  //reachedFtLimit = (_rtForceThreshold >= 0) && currentForce > _rtForceThreshold;
315  //_publishForceCurrent = currentForce;
316  //_publishIsAtForceLimit = _publishIsAtForceLimit || reachedFtLimit;
317  }
318 
319  //_publishWpsCur = _rtHasWps ? _rtPosController->currentWaypointIndex : 0;
320 
321  rt2nonrtBuf.rootPose = _rtRobot->getGlobalPose();
322  rt2nonrtBuf.tcp = _rtTcp->getPoseInRootFrame();
323  rt2nonrtBuf.elb = _rtElbow->getPoseInRootFrame();
324  rt2nonrtBuf.tcpTarg = _rtPosController->getCurrentTarget();
325  rt2nonrtBuf.elbTarg = ::math::Helpers::CreatePose(_rtPosController->getCurrentElbowTarget(),
327 
328 
329  if (_rtStopConditionReached)
330  {
331  setNullVelocity();
332  }
333  else
334  {
336  _rtSetOrientation ? VirtualRobot::IKSolver::All : VirtualRobot::IKSolver::Position;
337  _rtPosController->setNullSpaceControl(_nullspaceControlEnabled);
338 
339  if (_rtFFvel.use)
340  {
341  if (_rtFFvelLastUpdateMS + _rtFFvelMaxAgeMS >
342  sensorValuesTimestamp.toMilliSeconds())
343  {
344  _rtPosController->setFeedForwardVelocity(_rtFFvel.feedForwardVelocity);
345  }
346  else
347  {
348  ARMARX_RT_LOGF_WARN("Feed forward velocity cleared due to timeout");
349  _rtFFvel.use = false;
350  }
351  }
352 
353  const Eigen::VectorXf& goal =
354  _rtPosController->calculate(timeSinceLastIteration.toSecondsDouble(), mode);
355 
356  const Eigen::VectorXf actualTcpVel = _rtPosController->actualTcpVel(goal);
357  const Eigen::VectorXf actualElbVel = _rtPosController->actualElbVel(goal);
358  //ARMARX_IMPORTANT << VAROUT(actualTcpVel) << VAROUT(actualElbVel);
359  _publish.tcpPosVel = actualTcpVel.block<3, 1>(0, 0).norm();
360  _publish.tcpOriVel = actualTcpVel.block<3, 1>(3, 0).norm();
361  _publish.elbPosVel = actualElbVel.block<3, 1>(0, 0).norm();
362 
363  //write targets
364  ARMARX_CHECK_EQUAL(static_cast<std::size_t>(goal.size()), _rtVelTargets.size());
365  for (std::size_t idx = 0; idx < _rtVelTargets.size(); ++idx)
366  {
367  float* ptr = _rtVelTargets[idx];
368  *ptr = goal(idx);
369  }
370  }
371  _tripRt2NonRt.commitWrite();
372  }
373 
374  void
376  {
377  }
378 
379  void
381  const CartesianNaturalPositionControllerConfig& cfg,
382  const Ice::Current&)
383  {
384  std::lock_guard g{_mutexSetTripBuf};
385  auto& w = _tripBufCfg.getWriteBuffer();
386  w.cfg = cfg;
387  w.updated = true;
388  _tripBufCfg.commitWrite();
389  ARMARX_IMPORTANT << "set new config\n" << cfg;
390  }
391 
392  void
394  const Eigen::Vector3f& elbowTarget,
395  bool setOrientation,
396  const Ice::Current&)
397  {
398  std::lock_guard g{_mutexSetTripBuf};
399  auto& w = _tripBufTarget.getWriteBuffer();
400  w.tcpTarget = tcpTarget;
401  w.elbowTarget = elbowTarget;
402  w.setOrientation = setOrientation;
403  w.updated = true;
404  _tripBufTarget.commitWrite();
405  ARMARX_IMPORTANT << "set new target\n"
406  << tcpTarget << "\nelbow: " << elbowTarget.transpose();
407  }
408 
409  void
411  const Eigen::Matrix4f& tcpTarget,
412  const Eigen::Vector3f& elbowTarget,
413  bool setOrientation,
414  const Eigen::Vector6f& ffVel,
415  const Ice::Current&)
416  {
417  std::lock_guard g{_mutexSetTripBuf};
418  {
419  auto& w = _tripBufTarget.getWriteBuffer();
420  w.tcpTarget = tcpTarget;
421  w.elbowTarget = elbowTarget;
422  w.setOrientation = setOrientation;
423  w.updated = true;
424  }
425  {
426  auto& w = _tripBufFFvel.getWriteBuffer();
427  w.feedForwardVelocity = ffVel;
428  w.updated = true;
429  }
430  _tripBufFFvel.commitWrite();
431  _tripBufTarget.commitWrite();
432  }
433 
434  void
436  const Ice::Current&)
437  {
438  std::lock_guard g{_mutexSetTripBuf};
439  auto& w = _tripBufFFvel.getWriteBuffer();
440  w.feedForwardVelocity = vel;
441  w.use = true;
442  w.updated = true;
443  _tripBufFFvel.commitWrite();
444  ARMARX_IMPORTANT << "set new FeedForwardVelocity\n" << vel.transpose();
445  }
446 
447  void
449  {
450  std::lock_guard g{_mutexSetTripBuf};
451  auto& w = _tripBufFFvel.getWriteBuffer();
452  w.feedForwardVelocity = Eigen::Vector6f::Zero();
453  w.use = false;
454  w.updated = true;
455  _tripBufFFvel.commitWrite();
456  ARMARX_IMPORTANT << "cleared FeedForwardVelocity";
457  }
458 
459  void
460  NJointCartesianNaturalPositionController::setNullVelocity()
461  {
462  for (auto ptr : _rtVelTargets)
463  {
464  *ptr = 0;
465  }
466  }
467 
468  //bool NJointCartesianNaturalPositionController::hasReachedForceLimit(const Ice::Current&)
469  //{
470  // ARMARX_CHECK_NOT_NULL(_rtForceSensor);
471  // return _publishIsAtForceLimit;
472  //}
473 
474  void
476  const Eigen::Matrix4f& p,
477  const Ice::Current&)
478  {
479  std::lock_guard g{_tripFakeRobotGPWriteMutex};
480  _tripFakeRobotGP.getWriteBuffer() = p;
481  _tripFakeRobotGP.commitWrite();
482  }
483 
484  void
486  {
487  std::lock_guard g{_tripFakeRobotGPWriteMutex};
488  _tripFakeRobotGP.getWriteBuffer()(0, 0) = std::nanf("");
489  _tripFakeRobotGP.commitWrite();
490  }
491 
492  void
494  {
495  _stopNowRequested = true;
496  }
497 
498  void
500  const Ice::FloatSeq& nullspaceTarget,
501  const Ice::Current&)
502  {
503  std::lock_guard g{_mutexSetTripBuf};
504  auto& w = _tripBufNullspaceTarget.getWriteBuffer();
505  w.nullspaceTarget = nullspaceTarget;
506  w.clearRequested = false;
507  w.updated = true;
508  _tripBufNullspaceTarget.commitWrite();
509  ARMARX_IMPORTANT << "set new nullspaceTarget\n" << nullspaceTarget;
510  }
511 
512  void
514  {
515  std::lock_guard g{_mutexSetTripBuf};
516  auto& w = _tripBufNullspaceTarget.getWriteBuffer();
517  w.clearRequested = true;
518  w.updated = true;
519  _tripBufNullspaceTarget.commitWrite();
520  ARMARX_IMPORTANT << "reset nullspaceTarget";
521  }
522 
523  void
525  const Ice::Current&)
526  {
527  _nullspaceControlEnabled = enabled;
528  }
529 
530  FTSensorValue
531  NJointCartesianNaturalPositionController::frost(const FTval& ft)
532  {
533  FTSensorValue r;
534  r.force = ft.force;
535  r.torque = ft.torque;
536  return r;
537  }
538 
539  FTSensorValue
541  {
542  std::lock_guard g{_tripRt2NonRtMutex};
543  return frost(_tripRt2NonRt.getUpToDateReadBuffer().currentFT);
544  }
545 
546  FTSensorValue
548  {
549  std::lock_guard g{_tripRt2NonRtMutex};
550  return frost(_tripRt2NonRt.getUpToDateReadBuffer().averageFT);
551  }
552 
553  void
555  const Ice::Current&)
556  {
557  std::lock_guard g{_mutexSetTripBuf};
558  auto& w = _tripBufFToffset.getWriteBuffer();
559  w.force = offset.force;
560  w.torque = offset.torque;
561  w.updated = true;
562  _tripBufFToffset.commitWrite();
563  ARMARX_IMPORTANT << "set FT offset:\n"
564  << offset.force.transpose() << "\n"
565  << offset.torque.transpose();
566  }
567 
568  void
570  {
571  std::lock_guard g{_mutexSetTripBuf};
572  auto& w = _tripBufFToffset.getWriteBuffer();
573  w.force = Eigen::Vector3f::Zero();
574  w.torque = Eigen::Vector3f::Zero();
575  w.updated = true;
576  _tripBufFToffset.commitWrite();
577  ARMARX_IMPORTANT << "reset FT offset";
578  }
579 
580  void
582  float torque,
583  const Ice::Current&)
584  {
585  std::lock_guard g{_mutexSetTripBuf};
586  auto& w = _tripBufFTlimit.getWriteBuffer();
587  w.force = force;
588  w.torque = torque;
589  w.updated = true;
590  _tripBufFTlimit.commitWrite();
591  ARMARX_IMPORTANT << "set FT limit:" << force << " " << torque;
592  }
593 
594  void
596  {
597  std::lock_guard g{_mutexSetTripBuf};
598  auto& w = _tripBufFTlimit.getWriteBuffer();
599  w.force = -1;
600  w.torque = -1;
601  w.updated = true;
602  _tripBufFTlimit.commitWrite();
603  ARMARX_IMPORTANT << "reset FT limit";
604  }
605 
606  void
608  const Ice::Current&)
609  {
610  std::lock_guard g{_mutexSetTripBuf};
611  auto& w = _tripBufFTfake.getWriteBuffer();
612  w.force = ftValue.force;
613  w.torque = ftValue.torque;
614  w.use = true;
615  w.updated = true;
616  _tripBufFTfake.commitWrite();
617  ARMARX_IMPORTANT << "set fake FT value:\n"
618  << ftValue.force.transpose() << "\n"
619  << ftValue.torque.transpose();
620  }
621 
622  void
624  {
625  std::lock_guard g{_mutexSetTripBuf};
626  auto& w = _tripBufFTfake.getWriteBuffer();
627  w.force = Eigen::Vector3f::Zero();
628  w.torque = Eigen::Vector3f::Zero();
629  w.use = false;
630  w.updated = true;
631  _tripBufFTfake.commitWrite();
632  ARMARX_IMPORTANT << "cleared fake FT value";
633  }
634 
635  bool
637  {
638  ARMARX_CHECK_NOT_NULL(_rtForceSensor);
639  return _publishIsAtForceLimit;
640  }
641 
642  void
644  const DebugDrawerInterfacePrx& drawer,
645  const DebugObserverInterfacePrx& obs)
646  {
647  const float errorPos = _publish.errorPos;
648  const float errorOri = _publish.errorOri;
649  const float errorPosMax = _publish.errorPosMax;
650  const float errorOriMax = _publish.errorOriMax;
651  //const float forceThreshold = _publishForceThreshold;
652  //const float forceCurrent = _publishForceCurrent;
653  const float tcpPosVel = _publish.tcpPosVel;
654  const float tcpOriVel = _publish.tcpOriVel;
655  const float elbPosVel = _publish.elbPosVel;
656 
657  {
658  StringVariantBaseMap datafields;
659 
660  datafields["errorPos"] = new Variant(errorPos);
661  datafields["errorOri"] = new Variant(errorOri);
662  datafields["errorPosMax"] = new Variant(errorPosMax);
663  datafields["errorOriMax"] = new Variant(errorOriMax);
664 
665  datafields["tcpPosVel"] = new Variant(tcpPosVel);
666  datafields["tcpOriVel"] = new Variant(tcpOriVel);
667  datafields["elbPosVel"] = new Variant(elbPosVel);
668 
669  //datafields["forceThreshold"] = new Variant(forceThreshold);
670  //datafields["forceCurrent"] = new Variant(forceCurrent);
671 
672  obs->setDebugChannel(getInstanceName(), datafields);
673  }
674 
675  ARMARX_INFO << deactivateSpam(1) << std::setprecision(4) << "perror " << errorPos << " / "
676  << errorPosMax << ", oerror " << errorOri << " / " << errorOriMax << ')';
677 
678  {
679  std::lock_guard g{_tripRt2NonRtMutex};
680  const auto& buf = _tripRt2NonRt.getUpToDateReadBuffer();
681 
682  const Eigen::Matrix4f fakeGP = _tripFakeRobotGP.getUpToDateReadBuffer();
683  const Eigen::Matrix4f gp = std::isfinite(fakeGP(0, 0)) ? fakeGP : buf.rootPose;
684 
685  if (buf.tcp != buf.tcpTarg)
686  {
687  const Eigen::Matrix4f gtcp = gp * buf.tcp;
688  const Eigen::Matrix4f gtcptarg = gp * buf.tcpTarg;
689  const Eigen::Matrix4f gelb = gp * buf.elb;
690  const Eigen::Matrix4f gelbtarg = gp * buf.elbTarg;
691  drawer->setPoseVisu(getName(), "tcp", new Pose(gtcp));
692  drawer->setPoseVisu(getName(), "tcptarg", new Pose(gtcptarg));
693  drawer->setLineVisu(getName(),
694  "tcp2targ",
695  new Vector3(Eigen::Vector3f{gtcp.topRightCorner<3, 1>()}),
696  new Vector3(Eigen::Vector3f{gtcptarg.topRightCorner<3, 1>()}),
697  3,
698  {0, 0, 1, 1});
699  drawer->setLineVisu(getName(),
700  "elb2targ",
701  new Vector3(Eigen::Vector3f{gelb.topRightCorner<3, 1>()}),
702  new Vector3(Eigen::Vector3f{gelbtarg.topRightCorner<3, 1>()}),
703  3,
704  {0, 0, 1, 1});
705  }
706  else
707  {
708  drawer->removePoseVisu(getName(), "tcp");
709  drawer->removePoseVisu(getName(), "tcptarg");
710  drawer->removeLineVisu(getName(), "tcp2targ");
711  }
712  //if (_rtForceSensor)
713  //{
714  // const Eigen::Matrix4f gft = gp * buf.ftInRoot;
715  // const Vector3Ptr pos = new Vector3{Eigen::Vector3f{gft.topRightCorner<3, 1>()}};
716  // drawer->setArrowVisu(
717  // getName(), "force", pos,
718  // new Vector3{buf.ft.force.normalized()},
719  // {1, 1, 0, 1}, buf.ft.force.norm(), 2.5);
720  // drawer->setArrowVisu(
721  // getName(), "forceUsed", pos,
722  // new Vector3{buf.ftUsed.normalized()},
723  // {1, 0.5, 0, 1}, buf.ftUsed.norm(), 2.5);
724  //}
725  }
726  }
727 } // namespace armarx
armarx::NJointCartesianNaturalPositionController::setNullspaceControlEnabled
void setNullspaceControlEnabled(bool enabled, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:524
armarx::NJointCartesianNaturalPositionController::NJointCartesianNaturalPositionController
NJointCartesianNaturalPositionController(RobotUnit *robotUnit, const NJointCartesianNaturalPositionControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointCartesianNaturalPositionController.cpp:68
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::NJointControllerBase::peekSensorDevice
ConstSensorDevicePtr peekSensorDevice(const std::string &deviceName) const
Get a const ptr to the given SensorDevice.
Definition: NJointController.cpp:275
armarx::NJointCartesianNaturalPositionController::resetFTOffset
void resetFTOffset(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:569
armarx::NJointControllerBase::getInstanceName
std::string getInstanceName(const Ice::Current &=Ice::emptyCurrent) const final override
Definition: NJointControllerBase.h:803
armarx::TripleBuffer::getWriteBuffer
T & getWriteBuffer()
Definition: TripleBuffer.h:90
armarx::NJointControllerBase::useSynchronizedRtRobot
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
Definition: NJointController.cpp:293
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::NJointCartesianNaturalPositionController::stopMovement
void stopMovement(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:493
armarx::NJointCartesianNaturalPositionController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointCartesianNaturalPositionController.cpp:643
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::NJointCartesianNaturalPositionController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointCartesianNaturalPositionController.cpp:178
armarx::TripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:146
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::NJointCartesianNaturalPositionController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: NJointCartesianNaturalPositionController.cpp:63
trace.h
SensorValueForceTorque.h
armarx::NJointCartesianNaturalPositionController::clearFakeFTValue
void clearFakeFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:623
armarx::NJointCartesianNaturalPositionController::setTarget
void setTarget(const Eigen::Matrix4f &tcpTarget, const Eigen::Vector3f &elbowTarget, bool setOrientation, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:393
NJointCartesianNaturalPositionController.h
std::isfinite
bool isfinite(const std::vector< T, Ts... > &v)
Definition: algorithm.h:327
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::NJointCartesianNaturalPositionController::clearFeedForwardVelocity
void clearFeedForwardVelocity(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:448
armarx::NJointCartesianNaturalPositionController::setFakeFTValue
void setFakeFTValue(const FTSensorValue &ftValue, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:607
armarx::NJointCartesianNaturalPositionController::setFTLimit
void setFTLimit(float force, float torque, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:581
armarx::NJointCartesianNaturalPositionController::setConfig
void setConfig(const CartesianNaturalPositionControllerConfig &cfg, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:380
armarx::registrationControllerNJointCartesianNaturalPositionController
NJointControllerRegistration< NJointCartesianNaturalPositionController > registrationControllerNJointCartesianNaturalPositionController("NJointCartesianNaturalPositionController")
armarx::NJointCartesianNaturalPositionController::setVisualizationRobotGlobalPose
void setVisualizationRobotGlobalPose(const Eigen::Matrix4f &p, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:475
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
armarx::TripleBuffer::getReadBuffer
const T & getReadBuffer() const
Definition: TripleBuffer.h:102
armarx::NJointCartesianNaturalPositionController::clearNullspaceTarget
void clearNullspaceTarget(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:513
ControlTarget1DoFActuator.h
armarx::NJointCartesianNaturalPositionController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointCartesianNaturalPositionController.cpp:375
ARMARX_RT_LOGF_VERBOSE
#define ARMARX_RT_LOGF_VERBOSE(...)
Definition: ControlThreadOutputBuffer.h:337
armarx::NJointCartesianNaturalPositionController::isAtForceLimit
bool isAtForceLimit(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:636
armarx::vec2str
std::string vec2str(const std::vector< float > &vec)
Definition: NJointCartesianNaturalPositionController.cpp:19
ARMARX_RT_LOGF_IMPORTANT
#define ARMARX_RT_LOGF_IMPORTANT(...)
Definition: ControlThreadOutputBuffer.h:341
armarx::NJointCartesianNaturalPositionController::resetVisualizationRobotGlobalPose
void resetVisualizationRobotGlobalPose(const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointCartesianNaturalPositionController.cpp:485
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::NJointCartesianNaturalPositionController::setFeedForwardVelocity
void setFeedForwardVelocity(const Eigen::Vector6f &vel, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:435
armarx::NJointCartesianNaturalPositionController::clearFTLimit
void clearFTLimit(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:595
armarx::NJointCartesianNaturalPositionController::getCurrentFTValue
FTSensorValue getCurrentFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:540
armarx::NJointCartesianNaturalPositionController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointCartesianNaturalPositionController.cpp:159
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::NJointCartesianNaturalPositionController::setNullspaceTarget
void setNullspaceTarget(const Ice::FloatSeq &nullspaceTarget, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:499
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::NJointCartesianNaturalPositionController::setFTOffset
void setFTOffset(const FTSensorValue &offset, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:554
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::NJointCartesianNaturalPositionController::getAverageFTValue
FTSensorValue getAverageFTValue(const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:547
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:221
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
Eigen::Matrix< float, 6, 1 >
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
ControlThreadOutputBuffer.h
armarx::TripleBuffer::_getNonConstReadBuffer
T & _getNonConstReadBuffer()
Definition: TripleBuffer.h:115
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
armarx::TripleBuffer::getUpToDateReadBuffer
const T & getUpToDateReadBuffer() const
Definition: TripleBuffer.h:108
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
ARMARX_RT_LOGF_WARN
#define ARMARX_RT_LOGF_WARN(...)
Definition: ControlThreadOutputBuffer.h:345
NJointControllerRegistry.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
SensorValue1DoFActuator.h
armarx::NJointCartesianNaturalPositionController::setTargetFeedForward
void setTargetFeedForward(const Eigen::Matrix4f &tcpTarget, const Eigen::Vector3f &elbowTarget, bool setOrientation, const Eigen::Vector6f &ffVel, const Ice::Current &) override
Definition: NJointCartesianNaturalPositionController.cpp:410
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::TripleBuffer::updateReadBuffer
bool updateReadBuffer() const
Swaps in the hidden buffer if it contains new data.
Definition: TripleBuffer.h:131
norm
double norm(const Point &a)
Definition: point.hpp:94