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