NJointTSDMPController.cpp
Go to the documentation of this file.
2 
3 #include <boost/archive/text_iarchive.hpp>
4 #include <boost/archive/text_oarchive.hpp>
5 
7 
9 {
10  NJointControllerRegistration<NJointTSDMPController>
11  registrationControllerNJointTSDMPController("NJointTSDMPController");
12 
14  const armarx::NJointControllerConfigPtr& config,
16  {
18  cfg = NJointTaskSpaceDMPControllerConfigPtr::dynamicCast(config);
19  ARMARX_CHECK_EXPRESSION(!cfg->nodeSetName.empty());
20  VirtualRobot::RobotNodeSetPtr rns = rtGetRobot()->getRobotNodeSet(cfg->nodeSetName);
21  jointNames = rns->getNodeNames();
22  ARMARX_CHECK_EXPRESSION(rns) << cfg->nodeSetName;
23  for (size_t i = 0; i < rns->getSize(); ++i)
24  {
25  std::string jointName = rns->getNode(i)->getName();
26  ControlTargetBase* ct = useControlTarget(jointName, ControlModes::Velocity1DoF);
27  const SensorValueBase* sv = useSensorValue(jointName);
28  targets.push_back(ct->asA<ControlTarget1DoFActuatorVelocity>());
29 
30  const SensorValue1DoFActuatorTorque* torqueSensor =
31  sv->asA<SensorValue1DoFActuatorTorque>();
32  const SensorValue1DoFActuatorVelocity* velocitySensor =
33  sv->asA<SensorValue1DoFActuatorVelocity>();
34  const SensorValue1DoFGravityTorque* gravityTorqueSensor =
35  sv->asA<SensorValue1DoFGravityTorque>();
36  const SensorValue1DoFActuatorPosition* positionSensor =
37  sv->asA<SensorValue1DoFActuatorPosition>();
38  if (!torqueSensor)
39  {
40  ARMARX_WARNING << "No Torque sensor available for " << jointName;
41  }
42  if (!gravityTorqueSensor)
43  {
44  ARMARX_WARNING << "No Gravity Torque sensor available for " << jointName;
45  }
46 
47  torqueSensors.push_back(torqueSensor);
48  gravityTorqueSensors.push_back(gravityTorqueSensor);
49  velocitySensors.push_back(velocitySensor);
50  positionSensors.push_back(positionSensor);
51  };
52 
53  tcp = (cfg->tcpName.empty()) ? rns->getTCP() : rtGetRobot()->getRobotNode(cfg->tcpName);
54  refFrame = (cfg->frameName.empty()) ? rns->getRobot()->getRootNode()
55  : rtGetRobot()->getRobotNode(cfg->frameName);
56  ARMARX_CHECK_EXPRESSION(tcp) << cfg->tcpName;
57 
58  // set tcp controller
59  tcpController.reset(new CartesianVelocityController(rns, tcp));
60  nodeSetName = cfg->nodeSetName;
61  torquePIDs.resize(tcpController->rns->getSize(), pidController());
62 
63  ik.reset(new VirtualRobot::DifferentialIK(
64  rns, refFrame, VirtualRobot::JacobiProvider::eSVDDamped));
65 
66 
67  finished = false;
68  tsvmp::TaskSpaceDMPControllerConfig taskSpaceDMPConfig;
69  taskSpaceDMPConfig.motionTimeDuration = cfg->timeDuration;
70  taskSpaceDMPConfig.DMPKernelSize = cfg->kernelSize;
71  taskSpaceDMPConfig.DMPMode = cfg->dmpMode;
72  taskSpaceDMPConfig.DMPStyle = cfg->dmpStyle;
73  taskSpaceDMPConfig.DMPAmplitude = cfg->dmpAmplitude;
74  taskSpaceDMPConfig.phaseStopParas.goDist = cfg->phaseDist0;
75  taskSpaceDMPConfig.phaseStopParas.backDist = cfg->phaseDist1;
76  taskSpaceDMPConfig.phaseStopParas.Kpos = cfg->phaseKpPos;
77  taskSpaceDMPConfig.phaseStopParas.Dpos = 0;
78  taskSpaceDMPConfig.phaseStopParas.Kori = cfg->phaseKpOri;
79  taskSpaceDMPConfig.phaseStopParas.Dori = 0;
80  taskSpaceDMPConfig.phaseStopParas.mm2radi = cfg->posToOriRatio;
81  taskSpaceDMPConfig.phaseStopParas.maxValue = cfg->phaseL;
82  taskSpaceDMPConfig.phaseStopParas.slop = cfg->phaseK;
83 
84  dmpCtrl.reset(new tsvmp::TaskSpaceDMPController("default", taskSpaceDMPConfig, false));
85 
86  // initialize tcp position and orientation
87 
88 
89  RTToControllerData initSensorData;
90  initSensorData.deltaT = 0;
91  initSensorData.currentTime = 0;
92  initSensorData.currentPose.setZero();
93  initSensorData.currentTwist.setZero();
94  rt2CtrlData.reinitAllBuffers(initSensorData);
95 
96  targetVels.setZero(6);
98  initData.targetTSVel.setZero(6);
99  initData.targetPose = refFrame->toLocalCoordinateSystem(tcp->getGlobalPose());
100  initData.nullspaceJointVelocities.resize(tcpController->rns->getSize(), 0);
101  initData.torqueKp.resize(tcpController->rns->getSize(), 0);
102  initData.torqueKd.resize(tcpController->rns->getSize(), 0);
103  initData.mode = ModeFromIce(cfg->mode);
104  reinitTripleBuffer(initData);
105 
106  debugName = cfg->debugName;
107 
108  KpF = cfg->Kp_LinearVel;
109  KoF = cfg->Kp_AngularVel;
110  DpF = cfg->Kd_LinearVel;
111  DoF = cfg->Kd_AngularVel;
112 
113  filtered_qvel.setZero(targets.size());
114  vel_filter_factor = cfg->vel_filter;
115 
116  filtered_position.setZero(3);
117  pos_filter_factor = cfg->pos_filter;
118 
119  // jlhigh = rns->getNode("..")->getJointLimitHi();
120  // jllow = rns->getNode("")->getJointLimitLo();
121  firstRun = true;
122 
123  jointLowLimits.setZero(targets.size());
124  jointHighLimits.setZero(targets.size());
125  for (size_t i = 0; i < rns->getSize(); i++)
126  {
127  VirtualRobot::RobotNodePtr rn = rns->getAllRobotNodes().at(i);
128 
129  jointLowLimits(i) = rn->getJointLimitLo();
130  jointHighLimits(i) = rn->getJointLimitHi();
131  }
132 
133  started = false;
134 
135  RTToUserData initInterfaceData;
136  initInterfaceData.currentTcpPose = Eigen::Matrix4f::Identity();
137  rt2UserData.reinitAllBuffers(initInterfaceData);
138  }
139 
140  std::string
141  NJointTSDMPController::getClassName(const Ice::Current&) const
142  {
143  return "NJointTSDMPController";
144  }
145 
146  void
148  {
149  if (!started)
150  {
151  return;
152  }
153 
154  if (!rt2CtrlData.updateReadBuffer() || !dmpCtrl)
155  {
156  return;
157  }
158 
159  double deltaT = rt2CtrlData.getReadBuffer().deltaT;
160  Eigen::Matrix4f currentPose = rt2CtrlData.getReadBuffer().currentPose;
161  Eigen::VectorXf currentTwist = rt2CtrlData.getReadBuffer().currentTwist;
162 
163  LockGuardType guard{controllerMutex};
164  dmpCtrl->flow(deltaT, currentPose, currentTwist);
165 
166  if (dmpCtrl->canVal < 1e-8)
167  {
168  finished = true;
169  }
170  targetVels = dmpCtrl->getTargetVelocity();
171  targetPose = dmpCtrl->getTargetPoseMat();
172  std::vector<double> targetState = dmpCtrl->getTargetPose();
173 
174  debugOutputData.getWriteBuffer().latestTargetVelocities["x_vel"] = targetVels(0);
175  debugOutputData.getWriteBuffer().latestTargetVelocities["y_vel"] = targetVels(1);
176  debugOutputData.getWriteBuffer().latestTargetVelocities["z_vel"] = targetVels(2);
177  debugOutputData.getWriteBuffer().latestTargetVelocities["roll_vel"] = targetVels(3);
178  debugOutputData.getWriteBuffer().latestTargetVelocities["pitch_vel"] = targetVels(4);
179  debugOutputData.getWriteBuffer().latestTargetVelocities["yaw_vel"] = targetVels(5);
180  debugOutputData.getWriteBuffer().dmpTargets["dmp_x"] = targetState[0];
181  debugOutputData.getWriteBuffer().dmpTargets["dmp_y"] = targetState[1];
182  debugOutputData.getWriteBuffer().dmpTargets["dmp_z"] = targetState[2];
183  debugOutputData.getWriteBuffer().dmpTargets["dmp_qw"] = targetState[3];
184  debugOutputData.getWriteBuffer().dmpTargets["dmp_qx"] = targetState[4];
185  debugOutputData.getWriteBuffer().dmpTargets["dmp_qy"] = targetState[5];
186  debugOutputData.getWriteBuffer().dmpTargets["dmp_qz"] = targetState[6];
187  debugOutputData.getWriteBuffer().currentPose["currentPose_x"] = currentPose(0, 3);
188  debugOutputData.getWriteBuffer().currentPose["currentPose_y"] = currentPose(1, 3);
189  debugOutputData.getWriteBuffer().currentPose["currentPose_z"] = currentPose(2, 3);
190 
192  VirtualRobot::MathTools::eigen4f2quat(currentPose);
193  debugOutputData.getWriteBuffer().currentPose["currentPose_qw"] = currentQ.w;
194  debugOutputData.getWriteBuffer().currentPose["currentPose_qx"] = currentQ.x;
195  debugOutputData.getWriteBuffer().currentPose["currentPose_qy"] = currentQ.y;
196  debugOutputData.getWriteBuffer().currentPose["currentPose_qz"] = currentQ.z;
197  debugOutputData.getWriteBuffer().currentCanVal = dmpCtrl->debugData.canVal;
198  debugOutputData.getWriteBuffer().mpcFactor = dmpCtrl->debugData.mpcFactor;
199  debugOutputData.getWriteBuffer().error = dmpCtrl->debugData.poseError;
200  debugOutputData.getWriteBuffer().posError = dmpCtrl->debugData.posiError;
201  debugOutputData.getWriteBuffer().oriError = dmpCtrl->debugData.oriError;
202  debugOutputData.getWriteBuffer().deltaT = deltaT;
203 
204  debugOutputData.commitWrite();
205 
206  getWriterControlStruct().targetTSVel = targetVels;
207  getWriterControlStruct().targetPose = targetPose;
209  }
210 
211  Eigen::VectorXf
212  NJointTSDMPController::calcIK(const Eigen::VectorXf& cartesianVel,
213  const Eigen::VectorXf& nullspaceVel,
215  {
216  Eigen::MatrixXf jacobi = ik->getJacobianMatrix(tcp, mode);
217 
218  Eigen::FullPivLU<Eigen::MatrixXf> lu_decomp(jacobi);
219 
220  Eigen::MatrixXf nullspace = lu_decomp.kernel();
221  Eigen::VectorXf nsv = Eigen::VectorXf::Zero(nullspace.rows());
222  for (int i = 0; i < nullspace.cols(); i++)
223  {
224  float squaredNorm = nullspace.col(i).squaredNorm();
225  // Prevent division by zero
226  if (squaredNorm > 1.0e-32f)
227  {
228  nsv += nullspace.col(i) * nullspace.col(i).dot(nullspaceVel) /
229  nullspace.col(i).squaredNorm();
230  }
231  }
232 
233  Eigen::MatrixXf inv =
234  ik->computePseudoInverseJacobianMatrix(jacobi, ik->getJacobiRegularization(mode));
235  // ARMARX_INFO << "inv: " << inv;
236  Eigen::VectorXf jointVel = inv * cartesianVel;
237  // jointVel += nsv;
238  return jointVel;
239  }
240 
241  void
242  NJointTSDMPController::rtRun(const IceUtil::Time& sensorValuesTimestamp,
243  const IceUtil::Time& timeSinceLastIteration)
244  {
245  Eigen::Matrix4f currentPose = refFrame->toLocalCoordinateSystem(tcp->getGlobalPose());
246  rt2UserData.getWriteBuffer().currentTcpPose = currentPose;
247  rt2UserData.commitWrite();
248 
249  if (firstRun)
250  {
251  filtered_position = currentPose.block<3, 1>(0, 3);
252 
253  firstRun = false;
254  for (size_t i = 0; i < targets.size(); ++i)
255  {
256  targets.at(i)->velocity = 0;
257  }
258  return;
259  }
260  else
261  {
262  filtered_position = (1 - pos_filter_factor) * filtered_position +
263  pos_filter_factor * currentPose.block<3, 1>(0, 3);
264  }
265 
266  double deltaT = timeSinceLastIteration.toSecondsDouble();
267 
268  Eigen::MatrixXf jacobi =
269  ik->getJacobianMatrix(tcp, VirtualRobot::IKSolver::CartesianSelection::All);
270 
271  Eigen::VectorXf qvel(velocitySensors.size());
272  for (size_t i = 0; i < velocitySensors.size(); ++i)
273  {
274  qvel(i) = velocitySensors[i]->velocity;
275  }
276 
277  filtered_qvel = (1 - vel_filter_factor) * filtered_qvel + vel_filter_factor * qvel;
278  Eigen::VectorXf tcptwist = jacobi * filtered_qvel;
279 
280  rt2CtrlData.getWriteBuffer().currentPose = currentPose;
281  rt2CtrlData.getWriteBuffer().currentTwist = tcptwist;
282  rt2CtrlData.getWriteBuffer().deltaT = deltaT;
283  rt2CtrlData.getWriteBuffer().currentTime += deltaT;
284  rt2CtrlData.commitWrite();
285 
286  rt2UserData.getWriteBuffer().currentTcpPose = currentPose;
287  rt2UserData.commitWrite();
288 
289  Eigen::VectorXf targetVel = rtGetControlStruct().targetTSVel;
290  Eigen::Matrix4f targetPose = rtGetControlStruct().targetPose;
291 
292  Eigen::VectorXf jointTargetVelocities = Eigen::VectorXf::Zero(targets.size());
293  if (started)
294  {
295  // targetVel = rtGetControlStruct().targetTSVel;
296  // targetPose = rtGetControlStruct().targetPose;
297 
298  Eigen::Matrix3f diffMat =
299  targetPose.block<3, 3>(0, 0) * currentPose.block<3, 3>(0, 0).inverse();
300  Eigen::Vector3f errorRPY = VirtualRobot::MathTools::eigen3f2rpy(diffMat);
301 
302  Eigen::Vector6f rtTargetVel;
303  rtTargetVel.block<3, 1>(0, 0) =
304  KpF * (targetPose.block<3, 1>(0, 3) - currentPose.block<3, 1>(0, 3)) +
305  DpF * (-tcptwist.block<3, 1>(0, 0));
306  // rtTargetVel.block<3, 1>(0, 0) = KpF * (targetPose.block<3, 1>(0, 3) - currentPose.block<3, 1>(0, 3)) + DpF * (targetVel.block<3, 1>(0, 0) - tcptwist.block<3, 1>(0, 0));
307  rtTargetVel.block<3, 1>(3, 0) =
308  KoF * errorRPY + DoF * (targetVel.block<3, 1>(3, 0) - tcptwist.block<3, 1>(3, 0));
309  // rtTargetVel = targetVel;
310 
311 
312  float normLinearVelocity = rtTargetVel.block<3, 1>(0, 0).norm();
313  if (normLinearVelocity > cfg->maxLinearVel)
314  {
315  rtTargetVel.block<3, 1>(0, 0) =
316  cfg->maxLinearVel * rtTargetVel.block<3, 1>(0, 0) / normLinearVelocity;
317  }
318 
319  float normAngularVelocity = rtTargetVel.block<3, 1>(3, 0).norm();
320  if (normAngularVelocity > cfg->maxAngularVel)
321  {
322  rtTargetVel.block<3, 1>(3, 0) =
323  cfg->maxAngularVel * rtTargetVel.block<3, 1>(3, 0) / normAngularVelocity;
324  }
325 
326 
327  // cartesian vel controller
328  // Eigen::Vector6f x;
329  // for (size_t i = 0; i < 6; i++)
330  // {
331  // x(i) = rtTargetVel(i);
332  // }
333 
334  Eigen::VectorXf jnv = Eigen::VectorXf::Zero(tcpController->rns->getSize());
335  float jointLimitAvoidanceKp = rtGetControlStruct().avoidJointLimitsKp;
336  if (jointLimitAvoidanceKp > 0)
337  {
338  jnv += jointLimitAvoidanceKp * tcpController->calculateJointLimitAvoidance();
339  }
340  for (size_t i = 0; i < tcpController->rns->getSize(); i++)
341  {
342  jnv(i) += rtGetControlStruct().nullspaceJointVelocities.at(i);
343  }
344 
345  // jointTargetVelocities = tcpController->calculate(x, jnv, VirtualRobot::IKSolver::CartesianSelection::All);
346  jointTargetVelocities =
347  calcIK(rtTargetVel, jnv, VirtualRobot::IKSolver::CartesianSelection::All);
348  // Eigen::VectorXf jointTargetVelocities = tcpController->calculate(x, jnv, VirtualRobot::IKSolver::CartesianSelection::All);
349  ARMARX_CHECK_EXPRESSION(!targets.empty());
350  ARMARX_CHECK_LESS(targets.size(), 1000);
351  }
352 
353  for (size_t i = 0; i < targets.size(); ++i)
354  {
355  targets.at(i)->velocity = jointTargetVelocities(i);
356 
357  if (!targets.at(i)->isValid() || fabs(targets.at(i)->velocity) > cfg->maxJointVelocity)
358  {
359  targets.at(i)->velocity = 0.0f;
360  }
361  }
362  rtDebugData.getWriteBuffer().targetJointVels = jointTargetVelocities;
363  rtDebugData.commitWrite();
364  }
365 
366 
367  void
368  NJointTSDMPController::learnDMPFromFiles(const Ice::StringSeq& fileNames, const Ice::Current&)
369  {
370  ARMARX_INFO << "Learning DMP ... ";
371 
372  LockGuardType guard{controllerMutex};
373  dmpCtrl->learnDMPFromFiles(fileNames);
374  }
375 
376  void
377  NJointTSDMPController::setSpeed(Ice::Double times, const Ice::Current&)
378  {
379  LockGuardType guard{controllerMutex};
380  dmpCtrl->setSpeed(times);
381  }
382 
383  void
385  const Ice::DoubleSeq& viapoint,
386  const Ice::Current&)
387  {
388  LockGuardType guard{controllerMutex};
389  dmpCtrl->setViaPose(u, viapoint);
390  }
391 
392  void
393  NJointTSDMPController::setTorqueKp(const StringFloatDictionary& torqueKp, const Ice::Current&)
394  {
396  for (size_t i = 0; i < tcpController->rns->getSize(); i++)
397  {
398  getWriterControlStruct().torqueKp.at(i) =
399  torqueKp.at(tcpController->rns->getNode(i)->getName());
400  }
402  }
403 
404  void
406  const StringFloatDictionary& nullspaceJointVelocities,
407  const Ice::Current&)
408  {
410  for (size_t i = 0; i < tcpController->rns->getSize(); i++)
411  {
412  getWriterControlStruct().nullspaceJointVelocities.at(i) =
413  nullspaceJointVelocities.at(tcpController->rns->getNode(i)->getName());
414  }
416  }
417 
418  void
420  Ice::Float avoidJointLimitsKp,
422  const Ice::Current&)
423  {
425  getWriterControlStruct().avoidJointLimitsKp = avoidJointLimitsKp;
426  getWriterControlStruct().mode = ModeFromIce(mode);
428  }
429 
430 
431  void
433  {
434  LockGuardType guard{controllerMutex};
435  ARMARX_INFO << "setting via points ";
436  dmpCtrl->removeAllViaPoints();
437  }
438 
439 
440  void
441  NJointTSDMPController::setGoals(const Ice::DoubleSeq& goals, const Ice::Current& ice)
442  {
443  LockGuardType guard{controllerMutex};
444  dmpCtrl->setGoalPoseVec(goals);
445  }
446 
447  void
448  NJointTSDMPController::pauseDMP(const Ice::Current&)
449  {
450  dmpCtrl->pauseController();
451  }
452 
453  void
454  NJointTSDMPController::resumeDMP(const Ice::Current&)
455  {
456  dmpCtrl->resumeController();
457  }
458 
459  void
460  NJointTSDMPController::resetDMP(const Ice::Current&)
461  {
462  if (started)
463  {
464  ARMARX_INFO << "Cannot reset running DMP";
465  }
466  firstRun = true;
467  }
468 
469  void
470  NJointTSDMPController::stopDMP(const Ice::Current&)
471  {
472  started = false;
473  }
474 
475  std::string
477  {
478 
479  return dmpCtrl->saveDMPToString();
480  }
481 
482  std::vector<double>
483  NJointTSDMPController::createDMPFromString(const std::string& dmpString, const Ice::Current&)
484  {
485  dmpCtrl->loadDMPFromString(dmpString);
486  return dmpCtrl->dmpPtr->defaultGoal;
487  }
488 
492  {
494  {
496  }
498  {
500  }
502  {
503  return VirtualRobot::IKSolver::CartesianSelection::All;
504  }
505  ARMARX_ERROR_S << "invalid mode " << mode;
507  }
508 
509 
510  void
511  NJointTSDMPController::runDMP(const Ice::DoubleSeq& goals, double tau, const Ice::Current&)
512  {
513  ARMARX_INFO << "------dmp controller: " << VAROUT(goals);
514  firstRun = true;
515  while (firstRun)
516  {
517  usleep(100);
518  }
519  while (!rt2UserData.updateReadBuffer())
520  {
521  usleep(100);
522  }
523 
524  Eigen::Matrix4f pose = rt2UserData.getReadBuffer().currentTcpPose;
525 
526  LockGuardType guard{controllerMutex};
527  // Eigen::Matrix4f pose = tcp->getPoseInRootFrame();
528  dmpCtrl->prepareExecution(dmpCtrl->eigen4f2vec(pose), goals);
529  finished = false;
530 
531  ARMARX_INFO << "run DMP";
532  started = true;
533  }
534 
535  void
536  NJointTSDMPController::runDMPWithTime(const Ice::DoubleSeq& goals,
537  Ice::Double timeDuration,
538  const Ice::Current&)
539  {
540  firstRun = true;
541  while (firstRun)
542  {
543  usleep(100);
544  }
545  while (!rt2UserData.updateReadBuffer())
546  {
547  usleep(100);
548  }
549 
550  Eigen::Matrix4f pose = rt2UserData.getReadBuffer().currentTcpPose;
551 
552  LockGuardType guard{controllerMutex};
553  dmpCtrl->config.motionTimeDuration = timeDuration;
554  dmpCtrl->prepareExecution(dmpCtrl->eigen4f2vec(pose), goals);
555 
556  finished = false;
557  started = true;
558  }
559 
560 
561  void
563  {
564  }
565 
566  void
568  {
569  }
570 
571  void
574  const DebugObserverInterfacePrx& debugObs)
575  {
576  std::string datafieldName = debugName;
577  StringVariantBaseMap datafields;
578  auto values = debugOutputData.getUpToDateReadBuffer().latestTargetVelocities;
579  for (auto& pair : values)
580  {
581  datafieldName = pair.first + "_" + debugName;
582  datafields[datafieldName] = new Variant(pair.second);
583  }
584 
585  auto dmpTargets = debugOutputData.getUpToDateReadBuffer().dmpTargets;
586  for (auto& pair : dmpTargets)
587  {
588  datafieldName = pair.first + "_" + debugName;
589  datafields[datafieldName] = new Variant(pair.second);
590  }
591 
592  auto currentPose = debugOutputData.getUpToDateReadBuffer().currentPose;
593  for (auto& pair : currentPose)
594  {
595  datafieldName = pair.first + "_" + debugName;
596  datafields[datafieldName] = new Variant(pair.second);
597  }
598 
599  datafieldName = "canVal_" + debugName;
600  datafields[datafieldName] =
601  new Variant(debugOutputData.getUpToDateReadBuffer().currentCanVal);
602  datafieldName = "mpcFactor_" + debugName;
603  datafields[datafieldName] = new Variant(debugOutputData.getUpToDateReadBuffer().mpcFactor);
604  datafieldName = "error_" + debugName;
605  datafields[datafieldName] = new Variant(debugOutputData.getUpToDateReadBuffer().error);
606  datafieldName = "posError_" + debugName;
607  datafields[datafieldName] = new Variant(debugOutputData.getUpToDateReadBuffer().posError);
608  datafieldName = "oriError_" + debugName;
609  datafields[datafieldName] = new Variant(debugOutputData.getUpToDateReadBuffer().oriError);
610  datafieldName = "deltaT_" + debugName;
611  datafields[datafieldName] = new Variant(debugOutputData.getUpToDateReadBuffer().deltaT);
612 
613 
614  Eigen::VectorXf targetJoints = rtDebugData.getUpToDateReadBuffer().targetJointVels;
615  for (int i = 0; i < targetJoints.size(); ++i)
616  {
617  datafieldName = jointNames[i] + "_velocity";
618  datafields[datafieldName] = new Variant(targetJoints[i]);
619  }
620 
621  datafieldName = "DMPController_" + debugName;
622  debugObs->setDebugChannel(datafieldName, datafields);
623  }
624 
625  void
627  {
628  ARMARX_INFO << "init ...";
629  started = false;
630  runTask("NJointTSDMPController",
631  [&]
632  {
633  CycleUtil c(1);
634  getObjectScheduler()->waitForObjectStateMinimum(eManagedIceObjectStarted);
635  while (getState() == eManagedIceObjectStarted)
636  {
637  if (isControllerActive())
638  {
639  controllerRun();
640  }
641  c.waitForCycleDuration();
642  }
643  });
644  }
645 
646  void
648  {
649  ARMARX_INFO << "stopped ...";
650  }
651 
652  void
653  NJointTSDMPController::setMPWeights(const DoubleSeqSeq& weights, const Ice::Current&)
654  {
655  dmpCtrl->setWeights(weights);
656  }
657 
658  DoubleSeqSeq
660  {
661  DMP::DVec2d res = dmpCtrl->getWeights();
662  DoubleSeqSeq resvec;
663  for (size_t i = 0; i < res.size(); ++i)
664  {
665  std::vector<double> cvec;
666  for (size_t j = 0; j < res[i].size(); ++j)
667  {
668  cvec.push_back(res[i][j]);
669  }
670  resvec.push_back(cvec);
671  }
672 
673  return resvec;
674  }
675 
676  void
678  {
679  DpF = kd;
680  }
681 
682  void
684  {
685  KpF = kp;
686  }
687 
688  void
690  {
691  DoF = kd;
692  }
693 
694  void
696  {
697  KoF = kp;
698  }
699 
700 } // namespace armarx::ctrl::njoint_ctrl::dmp
armarx::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::reinitTripleBuffer
void reinitTripleBuffer(const NJointTSDMPControllerControlData &initial)
Definition: NJointControllerWithTripleBuffer.h:68
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Kori
float Kori
Definition: TaskSpaceVMP.h:47
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::onPublish
virtual void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: NJointTSDMPController.cpp:572
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::onInitNJointController
void onInitNJointController() override
Definition: NJointTSDMPController.cpp:626
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: NJointTSDMPController.cpp:242
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::torqueKp
std::vector< float > torqueKp
Definition: NJointTSDMPController.h:41
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Dpos
float Dpos
Definition: TaskSpaceVMP.h:46
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::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::rtGetControlStruct
const NJointTSDMPControllerControlData & rtGetControlStruct() const
Definition: NJointControllerWithTripleBuffer.h:32
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::runDMPWithTime
void runDMPWithTime(const Ice::DoubleSeq &goals, Ice::Double timeDuration, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:536
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPKernelSize
int DMPKernelSize
Definition: TaskSpaceVMP.h:54
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setLinearVelocityKd
void setLinearVelocityKd(Ice::Float kd, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointTSDMPController.cpp:677
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setAngularVelocityKp
void setAngularVelocityKp(Ice::Float kp, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointTSDMPController.cpp:695
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setTorqueKp
void setTorqueKp(const StringFloatDictionary &torqueKp, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:393
armarx::TripleBuffer::commitWrite
void commitWrite()
Definition: TripleBuffer.h:146
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setViaPoints
void setViaPoints(Ice::Double u, const Ice::DoubleSeq &viapoint, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:384
armarx::NJointControllerBase::useControlTarget
ControlTargetBase * useControlTarget(const std::string &deviceName, const std::string &controlMode)
Declares to calculate the ControlTarget for the given ControlDevice in the given ControlMode when rtR...
Definition: NJointController.cpp:410
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::getClassName
std::string getClassName(const Ice::Current &) const override
Definition: NJointTSDMPController.cpp:141
armarx::control::deprecated_njoint_mp_controller::task_space
Definition: DeprecatedNJointPeriodicTSDMPCompliantController.cpp:6
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::onDisconnectNJointController
void onDisconnectNJointController() override
Definition: NJointTSDMPController.cpp:647
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::calcIK
Eigen::VectorXf calcIK(const Eigen::VectorXf &cartesianVel, const Eigen::VectorXf &nullspace, VirtualRobot::IKSolver::CartesianSelection mode)
Definition: NJointTSDMPController.cpp:212
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::targetTSVel
Eigen::Vector6f targetTSVel
Definition: NJointTSDMPController.h:36
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::ManagedIceObject::getState
int getState() const
Retrieve current state of the ManagedIceObject.
Definition: ManagedIceObject.cpp:725
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::NJointTaskSpaceDMPControllerInterface::getMPWeights
DoubleSeqSeq getMPWeights()
armarx::NJointTaskSpaceDMPControllerMode::ePosition
@ ePosition
Definition: ControllerInterface.ice:36
ARMARX_CHECK_LESS
#define ARMARX_CHECK_LESS(lhs, rhs)
This macro evaluates whether lhs is less (<) than rhs and if it turns out to be false it will throw a...
Definition: ExpressionException.h:102
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig
Definition: TaskSpaceVMP.h:52
armarx::CartesianVelocityController
Definition: CartesianVelocityController.h:36
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::phaseStopParas
PhaseStopParams phaseStopParas
Definition: TaskSpaceVMP.h:60
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: NJointTSDMPController.cpp:567
armarx::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::getWriterControlStruct
NJointTSDMPControllerControlData & getWriterControlStruct()
Definition: NJointControllerWithTripleBuffer.h:54
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::nullspaceJointVelocities
std::vector< float > nullspaceJointVelocities
Definition: NJointTSDMPController.h:39
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::goDist
float goDist
Definition: TaskSpaceVMP.h:41
armarx::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::LockGuardType
std::lock_guard< std::recursive_mutex > LockGuardType
Definition: NJointControllerWithTripleBuffer.h:14
armarx::NJointTaskSpaceDMPControllerInterface::resumeDMP
void resumeDMP()
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::motionTimeDuration
float motionTimeDuration
Definition: TaskSpaceVMP.h:59
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::controllerRun
void controllerRun()
Definition: NJointTSDMPController.cpp:147
armarx::NJointControllerBase::rtGetRobot
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
Definition: NJointControllerBase.h:845
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::backDist
float backDist
Definition: TaskSpaceVMP.h:42
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::maxValue
float maxValue
Definition: TaskSpaceVMP.h:43
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::learnDMPFromFiles
void learnDMPFromFiles(const Ice::StringSeq &fileNames, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:368
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: NJointTSDMPController.cpp:562
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setLinearVelocityKp
void setLinearVelocityKp(Ice::Float kp, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointTSDMPController.cpp:683
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Dori
float Dori
Definition: TaskSpaceVMP.h:48
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::ModeFromIce
VirtualRobot::IKSolver::CartesianSelection ModeFromIce(const NJointTaskSpaceDMPControllerMode::CartesianSelection mode)
Definition: NJointTSDMPController.cpp:490
armarx::control::deprecated_njoint_mp_controller::task_space::registrationControllerNJointTSDMPController
NJointControllerRegistration< NJointTSDMPController > registrationControllerNJointTSDMPController("NJointTSDMPController")
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setMPWeights
void setMPWeights(const DoubleSeqSeq &weights, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:653
armarx::NJointControllerBase::isControllerActive
bool isControllerActive(const Ice::Current &=Ice::emptyCurrent) const final override
Definition: NJointControllerBase.h:777
armarx::NJointControllerBase::runTask
void runTask(const std::string &taskName, Task &&task)
Executes a given task in a separate thread from the Application ThreadPool.
Definition: NJointControllerBase.h:753
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::NJointTaskSpaceDMPControllerMode::CartesianSelection
CartesianSelection
Definition: ControllerInterface.ice:34
armarx::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::writeControlStruct
void writeControlStruct()
Definition: NJointControllerWithTripleBuffer.h:44
armarx::TripleBuffer::getReadBuffer
const T & getReadBuffer() const
Definition: TripleBuffer.h:102
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::createDMPFromString
std::vector< double > createDMPFromString(const std::string &dmpString, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:483
ArmarXObjectScheduler.h
armarx::NJointControllerWithTripleBuffer< NJointTSDMPControllerControlData >::controlDataMutex
MutexType controlDataMutex
Definition: NJointControllerWithTripleBuffer.h:73
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPAmplitude
float DMPAmplitude
Definition: TaskSpaceVMP.h:57
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::slop
float slop
Definition: TaskSpaceVMP.h:44
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setAngularVelocityKd
void setAngularVelocityKd(Ice::Float kd, const Ice::Current &=Ice::emptyCurrent) override
Definition: NJointTSDMPController.cpp:689
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::Kpos
float Kpos
Definition: TaskSpaceVMP.h:45
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::NJointTSDMPController
NJointTSDMPController(const RobotUnitPtr &, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: NJointTSDMPController.cpp:13
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setSpeed
void setSpeed(Ice::Double times, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:377
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::torqueKd
std::vector< float > torqueKd
Definition: NJointTSDMPController.h:42
armarx::NJointTaskSpaceDMPControllerInterface::getDMPAsString
string getDMPAsString()
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
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::NJointTaskSpaceDMPControllerMode::eAll
@ eAll
Definition: ControllerInterface.ice:38
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::targetPose
Eigen::Matrix4f targetPose
Definition: NJointTSDMPController.h:37
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::NJointTaskSpaceDMPControllerMode::eOrientation
@ eOrientation
Definition: ControllerInterface.ice:37
armarx::NJointTaskSpaceDMPControllerInterface::pauseDMP
void pauseDMP()
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPStyle
std::string DMPStyle
Definition: TaskSpaceVMP.h:56
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPControllerConfig::DMPMode
std::string DMPMode
Definition: TaskSpaceVMP.h:55
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData::mode
VirtualRobot::IKSolver::CartesianSelection mode
Definition: NJointTSDMPController.h:43
Eigen::Matrix< float, 6, 1 >
armarx::control::deprecated_njoint_mp_controller::tsvmp::PhaseStopParams::mm2radi
float mm2radi
Definition: TaskSpaceVMP.h:49
NJointTSDMPController.h
armarx::NJointTaskSpaceDMPControllerInterface::resetDMP
void resetDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setControllerTarget
void setControllerTarget(Ice::Float avoidJointLimitsKp, NJointTaskSpaceDMPControllerMode::CartesianSelection mode, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:419
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
armarx::TripleBuffer::getUpToDateReadBuffer
const T & getUpToDateReadBuffer() const
Definition: TripleBuffer.h:108
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setNullspaceJointVelocities
void setNullspaceJointVelocities(const StringFloatDictionary &nullspaceJointVelocities, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:405
armarx::TripleBuffer::reinitAllBuffers
std::enable_if< std::is_copy_constructible< U >::value >::type reinitAllBuffers(const T &init)
Definition: TripleBuffer.h:153
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPControllerControlData
Definition: NJointTSDMPController.h:33
armarx::control::deprecated_njoint_mp_controller::tsvmp::TaskSpaceDMPController
Brief description of class TaskSpaceDMPController.
Definition: TaskSpaceVMP.h:83
armarx::ManagedIceObject::getObjectScheduler
ArmarXObjectSchedulerPtr getObjectScheduler() const
Definition: ManagedIceObject.cpp:731
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::setGoals
void setGoals(const Ice::DoubleSeq &goals, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:441
armarx::NJointTaskSpaceDMPControllerInterface::stopDMP
void stopDMP()
armarx::control::deprecated_njoint_mp_controller::task_space::NJointTSDMPController::runDMP
void runDMP(const Ice::DoubleSeq &goals, Ice::Double tau, const Ice::Current &) override
Definition: NJointTSDMPController.cpp:511
armarx::NJointControllerBase::useSensorValue
const SensorValueBase * useSensorValue(const std::string &sensorDeviceName) const
Get a const ptr to the given SensorDevice's SensorValue.
Definition: NJointController.cpp:383
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::NJointTaskSpaceDMPControllerInterface::removeAllViaPoints
void removeAllViaPoints()
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