MixedImpedanceVelocityController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ...
17  * @author Jianfeng Gao ( jianfeng dot gao at kit dot edu )
18  * @date 2024
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 #include <VirtualRobot/MathTools.h>
26 
28 #include <ArmarXCore/core/PackagePath.h> // for GUI
32 
33 #include <armarx/control/common/aron_conversions.h> // for GUI
36 
38 {
39  NJointControllerRegistration<NJointTaskspaceMixedImpedanceVelocityController>
41  "NJointTaskspaceMixedImpedanceVelocityController");
42 
43  void
45  ArmPtr& arm,
46  Config& cfg,
47  VirtualRobot::RobotPtr& nonRtRobotPtr)
48  {
49  arm->kinematicChainName = nodeSetName;
50  VirtualRobot::RobotNodeSetPtr rtRns =
51  rtGetRobot()->getRobotNodeSet(arm->kinematicChainName);
52  VirtualRobot::RobotNodeSetPtr nonRtRns =
53  nonRtRobotPtr->getRobotNodeSet(arm->kinematicChainName);
54  ARMARX_CHECK_EXPRESSION(rtRns) << arm->kinematicChainName;
55  ARMARX_CHECK_EXPRESSION(nonRtRns) << arm->kinematicChainName;
56  ARMARX_IMPORTANT << "Creating Taskspace Impedance controller with kinematic chain: "
57  << arm->kinematicChainName << " with num of joints: (RT robot) "
58  << rtRns->getSize() << ", and (non-RT robot) " << nonRtRns->getSize();
59 
60  std::vector<size_t> jointIDTorqueMode;
61  std::vector<size_t> jointIDVelocityMode;
62  arm->jointNames.clear();
63  for (size_t i = 0; i < rtRns->getSize(); ++i)
64  {
65  std::string jointName = rtRns->getNode(i)->getName();
66  arm->jointNames.push_back(jointName);
67 
68  bool foundControlDevice = false;
69  auto it = std::find(
70  cfg.jointNameListTorque.begin(), cfg.jointNameListTorque.end(), jointName);
71  if (it != cfg.jointNameListTorque.end())
72  {
73  ControlTargetBase* ct = useControlTarget(jointName, ControlModes::Torque1DoF);
75  auto* casted_ct = ct->asA<ControlTarget1DoFActuatorTorque>();
76  ARMARX_CHECK_EXPRESSION(casted_ct);
77  arm->targetsTorque.push_back(casted_ct);
78  jointIDTorqueMode.push_back(i);
79  foundControlDevice = true;
80  }
81 
82  it = std::find(
83  cfg.jointNameListVelocity.begin(), cfg.jointNameListVelocity.end(), jointName);
84  if (it != cfg.jointNameListVelocity.end())
85  {
86  ControlTargetBase* ct = useControlTarget(jointName, ControlModes::Velocity1DoF);
88  auto* casted_ct = ct->asA<ControlTarget1DoFActuatorVelocity>();
89  ARMARX_CHECK_EXPRESSION(casted_ct);
90  arm->targetsVel.push_back(casted_ct);
91  jointIDVelocityMode.push_back(i);
92  foundControlDevice = true;
93  }
94  if (not foundControlDevice)
95  {
96  auto namesTorque = armarx::control::common::sVecToString(cfg.jointNameListTorque);
97  auto namesVelocity =
98  armarx::control::common::sVecToString(cfg.jointNameListVelocity);
99  ARMARX_ERROR << "Does not found valid control device for joint name: " << jointName
100  << "Please check torque controlled joints: [" << namesTorque
101  << "] and velocity controlled joints: [" << namesVelocity << "].";
102  }
103 
104  const SensorValueBase* sv = useSensorValue(jointName);
106  arm->sensorDevices.append(sv, jointName);
107  };
108  ARMARX_DEBUG << "Number of torque controlled joints " << jointIDTorqueMode.size();
109  ARMARX_DEBUG << "Number of velocity controlled joints " << jointIDVelocityMode.size();
110  ARMARX_CHECK_EQUAL(rtRns->getNodeNames().size(),
111  jointIDTorqueMode.size() + jointIDVelocityMode.size());
112 
113  arm->controller.initialize(nonRtRns, rtRns, jointIDTorqueMode, jointIDVelocityMode);
114  arm->controller.ftsensor.initialize(rtRns, robotUnit, cfg.ftConfig);
115 
116  validateConfigData(cfg, arm);
117  arm->rtConfig = cfg;
118  arm->nonRtConfig = cfg;
119  arm->rtStatus.reset(rtRns->getSize(), jointIDTorqueMode.size(), jointIDVelocityMode.size());
120  }
121 
124  const NJointControllerConfigPtr& config,
125  const VirtualRobot::RobotPtr&) :
126  robotUnit(robotUnit)
127  {
129 
130  ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
132  userConfig.fromAron(cfg->config);
133 
135  nonRtRobot = robotUnit->cloneRobot();
136  robotUnit->updateVirtualRobot(nonRtRobot);
137 
138  for (auto& pair : userConfig.limbs)
139  {
140  limb.emplace(pair.first, std::make_unique<ArmData>());
141  limbInit(pair.first, limb.at(pair.first), pair.second, nonRtRobot);
142  controllableNodeSets.emplace(pair.first, nonRtRobot->getRobotNodeSet(pair.first));
143  }
144 
145  if (not userConfig.hands.empty())
146  {
147  hands = std::make_shared<core::HandControlBase>(nonRtRobot, userConfig.hands);
148  for (auto& pair : userConfig.hands)
149  {
150  for (auto& jointName : hands->hands.at(pair.first)->jointNames)
151  {
152  hands->appendDevice(pair.first,
153  useSensorValue(jointName),
154  useControlTarget(jointName, ControlModes::Position1DoF),
155  jointName);
156  }
157  ARMARX_INFO << "construction of hand "
158  << hands->hands.at(pair.first)->kinematicChainName;
159  controllableNodeSets.emplace(pair.first, nonRtRobot->getRobotNodeSet(pair.first));
160  }
161  }
162  }
163 
164  std::string
166  {
167  return "NJointTaskspaceMixedImpedanceVelocityController";
168  }
169 
170  void
172  {
173  std::string taskName = getClassName() + "AdditionalTask";
174  runTask(taskName,
175  [&]
176  {
178  4); // please don't set this to 0 as it is the rtRun/control thread
181 
182  CycleUtil c(1);
183  getObjectScheduler()->waitForObjectStateMinimum(eManagedIceObjectStarted);
184  ARMARX_IMPORTANT << "Create a new thread for " << getClassName();
185  while (getState() == eManagedIceObjectStarted)
186  {
187  if (isControllerActive())
188  {
189  additionalTask();
190  }
191  c.waitForCycleDuration();
192  }
193  });
194  }
195 
196  void
198  {
199  arm->bufferConfigNonRtToRt.getWriteBuffer() = arm->nonRtConfig;
200  arm->bufferConfigNonRtToRt.commitWrite();
201  }
202 
203  void
205  {
206  bool rtSafe = additionalTaskUpdateStatus();
208  if (not rtSafe)
209  {
211  }
212  }
213 
214  bool
216  {
217  robotUnit->updateVirtualRobot(nonRtRobot);
218  bool rtSafe = true;
219  for (auto& pair : limb)
220  {
221  auto& arm = pair.second;
222  arm->nonRtConfig = arm->bufferConfigUserToNonRt.getUpToDateReadBuffer();
223  arm->rtStatusInNonRT = arm->bufferRtStatusToNonRt.getUpToDateReadBuffer();
224  rtSafe = rtSafe and pair.second->rtStatusInNonRT.rtSafe;
225  }
226  if (hands)
227  {
228  hands->nonRTUpdateStatus();
229  }
230  return rtSafe;
231  }
232 
233  void
235  {
236  for (auto& pair : limb)
237  {
238  limbNonRT(pair.second);
239  }
240  if (hands)
241  {
242  hands->nonRTSetTarget();
243  }
244  }
245 
246  void
248  {
249  for (auto& pair : limb)
250  {
251  if (not pair.second->rtReady)
252  continue;
253 
254  if (not pair.second->rtStatusInNonRT.rtTargetSafe)
255  {
256  pair.second->rtStatusInNonRT =
257  pair.second->bufferRtStatusToNonRt.getUpToDateReadBuffer();
259  pair.second->rtStatusInNonRT.currentPose,
260  pair.second->nonRtConfig.desiredPose,
261  "current pose", "desired pose");
262  }
263  }
264  }
265 
266  /// -------------------------------- Real time cotnrol -----------------------------------------
267  void
269  const double deltaT)
270  {
271  arm->rtConfig = arm->bufferConfigNonRtToRt.getUpToDateReadBuffer();
272  arm->rtStatus.deltaT = deltaT;
273 
274  arm->controller.ftsensor.updateStatus(arm->rtConfig.ftConfig,
275  arm->rtStatus.currentForceTorque,
276  arm->rtStatus.deltaT,
277  arm->rtFirstRun.load());
278 
279  arm->sensorDevices.updateJointValues(
280  arm->rtStatus.jointPos, arm->rtStatus.jointVel, arm->rtStatus.jointTor);
281 
282 
283  arm->bufferRtStatusToNonRt.getWriteBuffer() = arm->rtStatus;
284  arm->bufferRtStatusToNonRt.commitWrite();
285  arm->bufferRtStatusToUser.getWriteBuffer() = arm->rtStatus;
286  arm->bufferRtStatusToUser.commitWrite();
287  }
288 
289  void
291  ArmPtr& arm,
292  const size_t nDoFTorque,
293  const size_t nDoFVelocity,
294  const Eigen::VectorXf& targetTorque,
295  const Eigen::VectorXf& targetVelocity)
296  {
297  for (size_t i = 0; i < nDoFTorque; i++)
298  {
299  auto jointIdx = arm->controller.jointIDTorqueMode[i];
300  arm->targetsTorque.at(i)->torque = targetTorque(jointIdx);
301  if (!arm->targetsTorque.at(i)->isValid())
302  {
303  arm->targetsTorque.at(i)->torque = 0;
304  }
305  }
306  for (size_t i = 0; i < nDoFVelocity; i++)
307  {
308  auto jointIdx = arm->controller.jointIDVelocityMode[i];
309  arm->targetsVel.at(i)->velocity = targetVelocity(jointIdx);
310  // if (!targets.at(i)->isValid() || fabs(targets.at(i)->velocity) > cfg->maxJointVelocity)
311  if (!arm->targetsVel.at(i)->isValid())
312  {
313  arm->targetsVel.at(i)->velocity = 0;
314  }
315  }
316  arm->bufferRtStatusToOnPublish.getWriteBuffer() = arm->rtStatus;
317  arm->bufferRtStatusToOnPublish.commitWrite();
318 
319  arm->bufferConfigRtToOnPublish.getWriteBuffer() = arm->rtConfig;
320  arm->bufferConfigRtToOnPublish.commitWrite();
321 
322  arm->bufferConfigRtToUser.getWriteBuffer() = arm->rtConfig;
323  arm->bufferConfigRtToUser.commitWrite();
324 
325  if (arm->rtFirstRun.load())
326  {
327  arm->rtFirstRun.store(false);
328  arm->rtReady.store(true);
329  }
330  }
331 
332  void
334  {
335  double time_measure = IceUtil::Time::now().toMicroSecondsDouble();
336  limbRTUpdateStatus(arm, deltaT);
337  double time_update_status = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
338 
339  arm->controller.run(arm->rtConfig, arm->rtStatus);
340  double time_run_rt = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
341 
342  limbRTSetTarget(arm,
343  arm->rtStatus.nDoFTorque,
344  arm->rtStatus.nDoFVelocity,
345  arm->rtStatus.desiredJointTorques,
346  arm->rtStatus.desiredJointVelocity);
347 
348  double time_set_target = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
349  time_measure = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
350 
351  if (time_measure > 200)
352  {
353  ARMARX_RT_LOGF_WARN("---- rt too slow: "
354  "time_update_status: %.2f\n"
355  "run_rt_limb: %.2f\n"
356  "set_target_limb: %.2f\n"
357  "time all: %.2f\n",
358  time_update_status, // 0-1 us
359  time_run_rt - time_update_status, //
360  time_set_target - time_run_rt, //
361  time_measure)
362  .deactivateSpam(1.0f); // 0-1 us
363  }
364  }
365 
366  void
368  const IceUtil::Time& /*sensorValuesTimestamp*/,
369  const IceUtil::Time& timeSinceLastIteration)
370  {
371  double deltaT = timeSinceLastIteration.toSecondsDouble();
372  for (auto& pair : limb)
373  {
374  limbRT(pair.second, deltaT);
375  }
376  if (hands)
377  {
378  hands->updateRTStatus(deltaT);
379  hands->setTargets();
380  }
381  }
382 
383  /// ------------------------------ update/get config -------------------------------------------
384  void
387  const Ice::Current& iceCurrent)
388  {
389  auto prevCfg = userConfig;
390  userConfig.fromAron(dto);
391 
392  for (auto& pair : userConfig.limbs)
393  {
394  validateConfigData(pair.second, limb.at(pair.first));
395  if (common::detectAndReportPoseDeviationWarning(pair.second.desiredPose,
396  prevCfg.limbs.at(pair.first).desiredPose,
397  "new desired pose", "previous desired pose",
398  pair.second.safeDistanceMMToGoal,
399  pair.second.safeRotAngleDegreeToGoal,
400  "updateConfig_" + pair.first))
401  {
402  ARMARX_INFO << "use the existing target pose";
403  pair.second.desiredPose = prevCfg.limbs.at(pair.first).desiredPose;
404  }
405  limb.at(pair.first)->bufferConfigUserToNonRt.getWriteBuffer() = pair.second;
406  limb.at(pair.first)->bufferConfigUserToNonRt.commitWrite();
407  }
408  if (hands)
409  {
410  hands->updateConfig(userConfig.hands);
411  }
412  }
413 
416  {
417  for (auto& pair : limb)
418  {
419  userConfig.limbs.at(pair.first) =
420  pair.second->bufferConfigRtToUser.getUpToDateReadBuffer();
421  }
422  if (hands)
423  {
424  hands->getConfig(userConfig.hands);
425  }
426  return userConfig.toAronDTO();
427  }
428 
429  void
431  const std::string& nodeSetName,
432  const bool forceGuard,
433  const bool torqueGuard,
434  const Ice::Current& iceCurrent)
435  {
436  auto it = userConfig.limbs.find(nodeSetName);
437  if (it != userConfig.limbs.end())
438  {
439  it->second.ftConfig.enableSafeGuardForce = forceGuard;
440  it->second.ftConfig.enableSafeGuardTorque = torqueGuard;
441  limb.at(nodeSetName)->controller.ftsensor.enableSafeGuard(forceGuard, torqueGuard);
443  << "reset safe guard with force torque sensors: safe? "
444  << limb.at(nodeSetName)->controller.ftsensor.isSafe(it->second.ftConfig);
445  limb.at(nodeSetName)->bufferConfigUserToNonRt.getWriteBuffer() = it->second;
446  limb.at(nodeSetName)->bufferConfigUserToNonRt.commitWrite();
447  }
448  else
449  {
450  ARMARX_WARNING << "no robot node set with name " << nodeSetName
451  << " found in the controllers.";
452  }
453  }
454 
455  /// -------------------------------- Other interaces -------------------------------------------
456  bool
458  const std::string& nodeSetName,
459  const Ice::Current& iceCurrent)
460  {
461  auto it = userConfig.limbs.find(nodeSetName);
462  if (it != userConfig.limbs.end())
463  {
464  return limb.at(nodeSetName)->controller.ftsensor.ftSafe.load();
465  }
466  else
467  {
468  ARMARX_WARNING << "no robot node set with name " << nodeSetName
469  << " found in the controllers.";
470  }
471  return false;
472  }
473 
474  Ice::FloatSeq
476  const Ice::Current& iceCurrent)
477  {
478  std::vector<float> tcpVel;
479  auto& arm = limb.at(rns);
480  auto s = arm->bufferRtStatusToUser.getUpToDateReadBuffer();
481  for (int i = 0; i < s.currentTwist.size(); i++)
482  {
483  tcpVel.push_back(s.currentTwist[i]);
484  }
485  return tcpVel;
486  }
487 
488  bool
490  const TargetPoseMap& targetPoseMap,
491  const TargetNullspaceMap& targetNullspaceMap,
492  const Ice::Current& iceCurrent)
493  {
494  for (auto& pair : userConfig.limbs)
495  {
496  for (size_t i = 0; i < 4; ++i)
497  {
498  for (int j = 0; j < 4; ++j)
499  {
500  pair.second.desiredPose(i, j) = targetPoseMap.at(pair.first)[i][j];
501  }
502  }
503  if (targetNullspaceMap.at(pair.first).size() > 0)
504  {
505  const size_t nDoF = pair.second.desiredNullspaceJointAngles.value().size();
506  ARMARX_CHECK_EQUAL(targetNullspaceMap.at(pair.first).size(), nDoF)
507  << "the joint numbers does not match";
508  for (size_t i = 0; i < nDoF; ++i)
509  {
510  pair.second.desiredNullspaceJointAngles.value()(i) =
511  targetNullspaceMap.at(pair.first)[i];
512  }
513  }
514  limb.at(pair.first)->bufferConfigUserToNonRt.getWriteBuffer() = pair.second;
515  limb.at(pair.first)->bufferConfigUserToNonRt.commitWrite();
516  }
517  return true;
518  }
519 
520  void
522  ArmPtr& arm)
523  {
524  const auto nDoF = arm->controller.numOfJoints;
525 
526  const auto checkSize = [nDoF](const auto& v) { ARMARX_CHECK_EQUAL(v.rows(), nDoF); };
527  const auto checkNonNegative = [](const auto& v) { ARMARX_CHECK((v.array() >= 0).all()); };
528 
529  if (!configData.desiredNullspaceJointAngles.has_value())
530  {
531  if (!isControllerActive())
532  {
533  ARMARX_INFO << "No user defined nullspace target, reset to zero with "
534  << VAROUT(nDoF);
535  configData.desiredNullspaceJointAngles = Eigen::VectorXf::Zero(nDoF);
536  arm->reInitPreActivate.store(true);
537  }
538  else
539  {
540  auto currentValue =
541  arm->bufferConfigRtToUser.getUpToDateReadBuffer().desiredNullspaceJointAngles;
543  << "Controller is active, but no user defined nullspace target. \n"
544  "You should first get up-to-date config of this controller and then update "
545  "it:\n"
546  " auto cfg = ctrl->getConfig(); \n"
547  " cfg.desiredPose = xxx;\n"
548  " ctrl->updateConfig(cfg);\n"
549  "Now, I decide by myself to use the existing values of nullspace target\n"
550  << currentValue.value();
551  configData.desiredNullspaceJointAngles = currentValue;
552  }
553  }
554  ARMARX_CHECK_GREATER(configData.safeDistanceMMToGoal, 100.0f);
555  checkSize(configData.desiredNullspaceJointAngles.value());
556  checkSize(configData.kdNullspaceTorque);
557  checkSize(configData.kpNullspaceTorque);
558  checkSize(configData.kdNullspaceVel);
559  checkSize(configData.kpNullspaceVel);
560 
561  checkNonNegative(configData.kdNullspaceTorque);
562  checkNonNegative(configData.kpNullspaceTorque);
563  checkNonNegative(configData.kpNullspaceVel);
564  checkNonNegative(configData.kdNullspaceVel);
565  checkNonNegative(configData.kdImpedance);
566  checkNonNegative(configData.kpImpedance);
567  }
568 
569  void
571  ArmPtr& arm,
572  const DebugObserverInterfacePrx& debugObs)
573  {
574  StringVariantBaseMap datafields;
575  auto rtData = arm->bufferConfigRtToOnPublish.getUpToDateReadBuffer();
576  auto rtStatus = arm->bufferRtStatusToOnPublish.getUpToDateReadBuffer();
577 
578 
579  common::debugEigenPose(datafields, "current_pose", rtStatus.currentPose);
580  common::debugEigenPose(datafields, "desired_pose", rtStatus.desiredPose);
581  common::debugEigenVec(datafields, "kpImpedance", rtData.kpImpedance);
582  common::debugEigenVec(datafields, "kdImpedance", rtData.kdImpedance);
583 
584  common::debugEigenVec(datafields, "currentForceTorque", rtStatus.currentForceTorque);
585 
586  common::debugEigenVec(datafields, "forceImpedance", rtStatus.forceImpedance);
587  common::debugEigenVec(datafields, "cartesianVelTarget", rtStatus.cartesianVelTarget);
588  common::debugEigenVec(datafields, "nullspaceTorque", rtStatus.nullspaceTorque);
589  common::debugEigenVec(datafields, "desiredJointTorques", rtStatus.desiredJointTorques);
590  debugObs->setDebugChannel(getClassName() + "_" + arm->kinematicChainName, datafields);
591  }
592 
593  void
595  const SensorAndControl&,
597  const DebugObserverInterfacePrx& debugObs)
598  {
599  for (auto& pair : limb)
600  {
601  if (not pair.second->rtReady.load())
602  continue;
603  limbPublish(pair.second, debugObs);
604  }
605  }
606 
607  void
609  {
610  for (auto& pair : limb)
611  {
612  pair.second->rtReady.store(false);
613  }
614  }
615 
616  void
618  {
619  VirtualRobot::RobotNodeSetPtr rns = rtGetRobot()->getRobotNodeSet(arm->kinematicChainName);
620  Eigen::Matrix4f currentPose = rns->getTCP()->getPoseInRootFrame();
621  auto quat = VirtualRobot::MathTools::eigen4f2quat(currentPose);
622  ARMARX_RT_LOGF_INFO("rt preactivate controller with target pose\n\n "
623  "[ %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f ].",
624  currentPose(0, 3),
625  currentPose(1, 3),
626  currentPose(2, 3),
627  quat.w,
628  quat.x,
629  quat.y,
630  quat.z);
631 
632  if (arm->reInitPreActivate.load())
633  {
634  arm->rtConfig.desiredNullspaceJointAngles.value() = rns->getJointValuesEigen();
635  arm->rtConfig.desiredPose = currentPose;
636 
637  arm->bufferConfigUserToNonRt.reinitAllBuffers(arm->rtConfig);
638  arm->reInitPreActivate.store(false);
639  }
640  {
641  arm->nonRtConfig = arm->rtConfig;
642  arm->bufferConfigNonRtToRt.reinitAllBuffers(arm->rtConfig);
643  arm->bufferConfigRtToOnPublish.reinitAllBuffers(arm->rtConfig);
644  arm->bufferConfigRtToUser.reinitAllBuffers(arm->rtConfig);
645  }
646  {
647  arm->sensorDevices.updateJointValues(
648  arm->rtStatus.jointPos, arm->rtStatus.jointVel, arm->rtStatus.jointTor);
649  arm->rtStatus.rtPreActivate(currentPose);
650 
651  arm->rtStatusInNonRT = arm->rtStatus;
652  arm->bufferRtStatusToOnPublish.reinitAllBuffers(arm->rtStatus);
653  arm->bufferRtStatusToNonRt.reinitAllBuffers(arm->rtStatus);
654  arm->bufferRtStatusToUser.reinitAllBuffers(arm->rtStatus);
655  }
656 
657  arm->controller.preactivateInit(rns);
658  }
659 
660  void
662  {
663  for (auto& pair : limb)
664  {
665  ARMARX_RT_LOGF_INFO("rtPreActivateController for %s", pair.first.c_str());
666  limbReInit(pair.second);
667  userConfig.limbs.at(pair.first) = pair.second->rtConfig;
668  }
669  if (hands)
670  {
671  hands->rtPreActivate();
672  }
673  }
674 
675  void
677  {
678  // for (auto& pair : limb)
679  // {
680  // pair.second->controller.isInitialized.store(false);
681  // }
682  }
683 
684  /// ----------------------------------- GUI Widget ---------------------------------------------
687  const VirtualRobot::RobotPtr& robot,
688  const std::map<std::string, ConstControlDevicePtr>& controlDevices,
689  const std::map<std::string, ConstSensorDevicePtr>&)
690  {
691  using namespace armarx::WidgetDescription;
692  HBoxLayoutPtr layout = new HBoxLayout;
693 
694 
695  ::armarx::WidgetDescription::WidgetSeq widgets;
696 
697  /// select default config
698  LabelPtr label = new Label;
699  label->text = "select a controller config";
700 
701  StringComboBoxPtr cfgBox = new StringComboBox;
702  cfgBox->name = "config_box";
703  cfgBox->defaultIndex = 0;
704  cfgBox->multiSelect = false;
705 
706  cfgBox->options = std::vector<std::string>{"default", "default_right", "default_right_a7"};
707  ARMARX_TRACE;
708 
709  layout->children.emplace_back(label);
710  layout->children.emplace_back(cfgBox);
711  ARMARX_TRACE;
712 
713  layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
714  ARMARX_INFO_S << "Layout done";
715  return layout;
716  }
717 
721  {
722  auto cfgName = values.at("config_box")->getString();
723  const armarx::PackagePath configPath(
724  "armarx_control",
725  "controller_config/NJointTaskspaceMixedImpedanceVelocityController/" + cfgName +
726  ".json");
727  ARMARX_INFO_S << "Loading config from " << configPath.toSystemPath();
728  ARMARX_CHECK(std::filesystem::exists(configPath.toSystemPath()));
729 
730  auto cfgDTO = armarx::readFromJson<ConfigDict>(configPath.toSystemPath());
731 
732  ARMARX_TRACE;
733  return new ConfigurableNJointControllerConfig{cfgDTO.toAronDTO()};
734  }
735 
736 } // namespace armarx::control::njoint_controller::task_space
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::userConfig
ConfigDict userConfig
Definition: MixedImpedanceVelocityController.h:171
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: MixedImpedanceVelocityController.cpp:661
armarx::control::njoint_controller::task_space::registrationControllerNJointTaskspaceMixedImpedanceVelocityController
NJointControllerRegistration< NJointTaskspaceMixedImpedanceVelocityController > registrationControllerNJointTaskspaceMixedImpedanceVelocityController("NJointTaskspaceMixedImpedanceVelocityController")
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
ARMARX_RT_LOGF_INFO
#define ARMARX_RT_LOGF_INFO(...)
Definition: ControlThreadOutputBuffer.h:339
SingleTypeVariantList.h
armarx::control::common::debugEigenPose
void debugEigenPose(StringVariantBaseMap &datafields, const std::string &name, Eigen::Matrix4f pose)
Definition: utils.cpp:113
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MixedImpedanceVelocityController.cpp:165
armarx::control::ethercat::RTUtility::RT_THREAD_PRIORITY
static constexpr int RT_THREAD_PRIORITY
The thread priority for rt-threads.
Definition: RTUtility.h:24
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::rtRun
void rtRun(const IceUtil::Time &sensorValuesTimestamp, const IceUtil::Time &timeSinceLastIteration) override
TODO make protected and use attorneys.
Definition: MixedImpedanceVelocityController.cpp:367
armarx::NJointControllerBase::useSynchronizedRtRobot
const VirtualRobot::RobotPtr & useSynchronizedRtRobot(bool updateCollisionModel=false)
Requests a VirtualRobot for use in rtRun *.
Definition: NJointController.cpp:293
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::onPublish
void onPublish(const SensorAndControl &, const DebugDrawerInterfacePrx &, const DebugObserverInterfacePrx &) override
Definition: MixedImpedanceVelocityController.cpp:594
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limb
std::map< std::string, ArmPtr > limb
Definition: MixedImpedanceVelocityController.h:168
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::ConfigPtrT
ConfigurableNJointControllerConfigPtr ConfigPtrT
Definition: MixedImpedanceVelocityController.h:56
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::handleRTNotSafeInNonRT
void handleRTNotSafeInNonRT()
Definition: MixedImpedanceVelocityController.cpp:247
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::controllableNodeSets
std::map< std::string, VirtualRobot::RobotNodeSetPtr > controllableNodeSets
Definition: MixedImpedanceVelocityController.h:173
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::common::detectAndReportPoseDeviationWarning
bool detectAndReportPoseDeviationWarning(const Eigen::Matrix4f &pose1, const Eigen::Matrix4f &pose2, const std::string &namePose1, const std::string &namePose2, float positionThrMM, float angleThrDeg, const std::string &who)
Definition: utils.cpp:600
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::updateTargetPose
bool updateTargetPose(const TargetPoseMap &targetPoseMap, const TargetNullspaceMap &targetNullspaceMap, const Ice::Current &=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:489
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:37
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::additionalTask
virtual void additionalTask()
Definition: MixedImpedanceVelocityController.cpp:204
armarx::control::ethercat::RTUtility::pinThreadToCPU
static bool pinThreadToCPU(unsigned int cpu)
Pins the calling thread to the CPU with the given id.
Definition: RTUtility.cpp:52
ARMARX_CHECK_GREATER
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
Definition: ExpressionException.h:116
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
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
aron_conversions.h
MixedImpedanceVelocityController.h
armarx::control::common::reportPoseDeviationWarning
void reportPoseDeviationWarning(const std::string &who, const Eigen::Matrix4f &pose1, const Eigen::Matrix4f &pose2, const std::string &namePose1, const std::string &namePose2)
Definition: utils.cpp:581
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config &cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
Definition: MixedImpedanceVelocityController.cpp:44
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:521
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::getConfig
::armarx::aron::data::dto::DictPtr getConfig(const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:415
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::NJointControllerBase::rtGetRobot
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
Definition: NJointControllerBase.h:845
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
visionx::voxelgrid::Label
uint32_t Label
Type of an object label.
Definition: types.h:7
armarx::control::TargetNullspaceMap
dictionary< string, Ice::FloatSeq > TargetNullspaceMap
Definition: ControllerInterface.ice:40
armarx::WidgetDescription
Definition: DefaultWidgetDescriptions.cpp:27
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbNonRT
void limbNonRT(ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:197
armarx::PackagePath::toSystemPath
static std::filesystem::path toSystemPath(const data::PackagePath &pp)
Definition: PackagePath.cpp:54
armarx::NJointControllerBase::isControllerActive
bool isControllerActive(const Ice::Current &=Ice::emptyCurrent) const final override
Definition: NJointControllerBase.h:777
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::enableSafeGuardForceTorque
void enableSafeGuardForceTorque(const std::string &nodeSetName, const bool forceGuard, const bool torqueGuard, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:430
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_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::NJointTaskspaceMixedImpedanceVelocityController
NJointTaskspaceMixedImpedanceVelocityController(const RobotUnitPtr &robotUnit, const NJointControllerConfigPtr &config, const VirtualRobot::RobotPtr &)
Definition: MixedImpedanceVelocityController.cpp:123
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbRTUpdateStatus
void limbRTUpdateStatus(ArmPtr &arm, const double deltaT)
-----------------------------— Real time cotnrol --------------------------------------—
Definition: MixedImpedanceVelocityController.cpp:268
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::isSafeForceTorque
bool isSafeForceTorque(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
-----------------------------— Other interaces ----------------------------------------—
Definition: MixedImpedanceVelocityController.cpp:457
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:617
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::getTCPVel
Ice::FloatSeq getTCPVel(const std::string &rns, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:475
ArmarXObjectScheduler.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::additionalTaskUpdateStatus
bool additionalTaskUpdateStatus()
Definition: MixedImpedanceVelocityController.cpp:215
armarx::control::ethercat::RTUtility::elevateThreadPriority
static bool elevateThreadPriority(int priority)
Elevate the thread priority of the calling thread to the given priority.
Definition: RTUtility.cpp:17
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::nonRtRobot
VirtualRobot::RobotPtr nonRtRobot
Definition: MixedImpedanceVelocityController.h:169
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbRT
void limbRT(ArmPtr &arm, const double deltaT)
Definition: MixedImpedanceVelocityController.cpp:333
armarx::control::common::debugEigenVec
void debugEigenVec(StringVariantBaseMap &datafields, const std::string &name, Eigen::VectorXf vec)
Definition: utils.cpp:125
utils.h
CycleUtil.h
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
armarx::control::NJointTaskspaceMixedImpedanceVelocityControllerInterface::calibrateFTSensor
void calibrateFTSensor()
ft sensor
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: MixedImpedanceVelocityController.cpp:171
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::rtPostDeactivateController
void rtPostDeactivateController() override
This function is called after the controller is deactivated.
Definition: MixedImpedanceVelocityController.cpp:676
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbRTSetTarget
void limbRTSetTarget(ArmPtr &arm, const size_t nDoFTorque, const size_t nDoFVelocity, const Eigen::VectorXf &targetTorque, const Eigen::VectorXf &targetVelocity)
Definition: MixedImpedanceVelocityController.cpp:290
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::updateConfig
void updateConfig(const ::armarx::aron::data::dto::DictPtr &dto, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
NJointController interface.
Definition: MixedImpedanceVelocityController.cpp:385
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
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
TimeUtil.h
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::GenerateConfigDescription
static WidgetDescription::WidgetPtr GenerateConfigDescription(const VirtualRobot::RobotPtr &, const std::map< std::string, ConstControlDevicePtr > &, const std::map< std::string, ConstSensorDevicePtr > &)
--------------------------------— GUI Widget ------------------------------------------—
Definition: MixedImpedanceVelocityController.cpp:686
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::hands
core::HandControlPtr hands
Definition: MixedImpedanceVelocityController.h:172
armarx::control::TargetPoseMap
dictionary< string, FloatSeqSeq > TargetPoseMap
Definition: ControllerInterface.ice:39
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::GenerateConfigFromVariants
static ConfigPtrT GenerateConfigFromVariants(const StringVariantBaseMap &values)
Definition: MixedImpedanceVelocityController.cpp:719
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::Config
law::TaskspaceMixedImpedanceVelocityController::Config Config
Definition: MixedImpedanceVelocityController.h:57
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: MixedImpedanceVelocityController.cpp:570
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: MixedImpedanceVelocityController.h:101
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::additionalTaskSetTarget
void additionalTaskSetTarget()
Definition: MixedImpedanceVelocityController.cpp:234
armarx::control::common::sVecToString
std::string sVecToString(const std::vector< std::string > &vec, const std::string &delimiter)
Definition: utils.cpp:306
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_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
ARMARX_RT_LOGF_WARN
#define ARMARX_RT_LOGF_WARN(...)
Definition: ControlThreadOutputBuffer.h:345
armarx::PackagePath
Definition: PackagePath.h:55
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::robotUnit
RobotUnitPtr robotUnit
Definition: MixedImpedanceVelocityController.h:170
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
RTUtility.h
armarx::ManagedIceObject::getObjectScheduler
ArmarXObjectSchedulerPtr getObjectScheduler() const
Definition: ManagedIceObject.cpp:731
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
PackagePath.h