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 
30 
33 
35 {
36  NJointControllerRegistration<NJointTaskspaceMixedImpedanceVelocityController>
38  "NJointTaskspaceMixedImpedanceVelocityController");
39 
40  void
42  ArmPtr& arm,
43  Config& cfg,
44  VirtualRobot::RobotPtr& nonRtRobotPtr)
45  {
46  arm->kinematicChainName = nodeSetName;
47  VirtualRobot::RobotNodeSetPtr rtRns =
48  rtGetRobot()->getRobotNodeSet(arm->kinematicChainName);
49  VirtualRobot::RobotNodeSetPtr nonRtRns =
50  nonRtRobotPtr->getRobotNodeSet(arm->kinematicChainName);
51  ARMARX_CHECK_EXPRESSION(rtRns) << arm->kinematicChainName;
52  ARMARX_CHECK_EXPRESSION(nonRtRns) << arm->kinematicChainName;
53  ARMARX_IMPORTANT << "Creating Taskspace Impedance controller with kinematic chain: "
54  << arm->kinematicChainName << " with num of joints: (RT robot) "
55  << rtRns->getSize() << ", and (non-RT robot) " << nonRtRns->getSize();
56 
57  std::vector<size_t> jointIDTorqueMode;
58  std::vector<size_t> jointIDVelocityMode;
59  arm->jointNames.clear();
60  for (size_t i = 0; i < rtRns->getSize(); ++i)
61  {
62  std::string jointName = rtRns->getNode(i)->getName();
63  arm->jointNames.push_back(jointName);
64 
65  bool foundControlDevice = false;
66  auto it = std::find(
67  cfg.jointNameListTorque.begin(), cfg.jointNameListTorque.end(), jointName);
68  if (it != cfg.jointNameListTorque.end())
69  {
70  ControlTargetBase* ct = useControlTarget(jointName, ControlModes::Torque1DoF);
72  auto* casted_ct = ct->asA<ControlTarget1DoFActuatorTorque>();
73  ARMARX_CHECK_EXPRESSION(casted_ct);
74  arm->targetsTorque.push_back(casted_ct);
75  jointIDTorqueMode.push_back(i);
76  foundControlDevice = true;
77  }
78 
79  it = std::find(
80  cfg.jointNameListVelocity.begin(), cfg.jointNameListVelocity.end(), jointName);
81  if (it != cfg.jointNameListVelocity.end())
82  {
83  ControlTargetBase* ct = useControlTarget(jointName, ControlModes::Velocity1DoF);
85  auto* casted_ct = ct->asA<ControlTarget1DoFActuatorVelocity>();
86  ARMARX_CHECK_EXPRESSION(casted_ct);
87  arm->targetsVel.push_back(casted_ct);
88  jointIDVelocityMode.push_back(i);
89  foundControlDevice = true;
90  }
91  if (not foundControlDevice)
92  {
93  auto namesTorque = armarx::control::common::sVecToString(cfg.jointNameListTorque);
94  auto namesVelocity =
95  armarx::control::common::sVecToString(cfg.jointNameListVelocity);
96  ARMARX_ERROR << "Does not found valid control device for joint name: " << jointName
97  << "Please check torque controlled joints: [" << namesTorque
98  << "] and velocity controlled joints: [" << namesVelocity << "].";
99  }
100 
101  const SensorValueBase* sv = useSensorValue(jointName);
103  const auto* torqueSensor = sv->asA<SensorValue1DoFActuatorTorque>();
104  const auto* velocitySensor = sv->asA<SensorValue1DoFActuatorVelocity>();
105  const auto* positionSensor = sv->asA<SensorValue1DoFActuatorPosition>();
106 
107  if (torqueSensor == nullptr)
108  {
109  ARMARX_WARNING << "No Torque sensor available for " << jointName;
110  }
111  if (velocitySensor == nullptr)
112  {
113  ARMARX_WARNING << "No velocity sensor available for " << jointName;
114  }
115  if (positionSensor == nullptr)
116  {
117  ARMARX_WARNING << "No position sensor available for " << jointName;
118  }
119 
120  arm->sensorDevices.torqueSensors.push_back(torqueSensor);
121  arm->sensorDevices.velocitySensors.push_back(velocitySensor);
122  arm->sensorDevices.positionSensors.push_back(positionSensor);
123  };
124  ARMARX_DEBUG << "Number of torque controlled joints " << jointIDTorqueMode.size();
125  ARMARX_DEBUG << "Number of velocity controlled joints " << jointIDVelocityMode.size();
126  ARMARX_CHECK_EQUAL(rtRns->getNodeNames().size(),
127  jointIDTorqueMode.size() + jointIDVelocityMode.size());
128 
129  arm->controller.initialize(nonRtRns, rtRns, jointIDTorqueMode, jointIDVelocityMode);
130  arm->controller.ftsensor.initialize(rtRns, robotUnit, cfg.ftConfig);
131 
132  validateConfigData(cfg, arm);
133  arm->rtConfig = cfg;
134  arm->nonRtConfig = cfg;
135  }
136 
139  const NJointControllerConfigPtr& config,
140  const VirtualRobot::RobotPtr&) :
141  robotUnit(robotUnit)
142  {
144 
145  ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
147  userConfig.fromAron(cfg->config);
148 
150  nonRtRobot = robotUnit->cloneRobot();
151  robotUnit->updateVirtualRobot(nonRtRobot);
152 
153  for (auto& pair : userConfig.cfg)
154  {
155  limb.emplace(pair.first, std::make_unique<ArmData>());
156  limbInit(pair.first, limb.at(pair.first), pair.second, nonRtRobot);
157  }
158  }
159 
160  std::string
162  {
163  return "NJointTaskspaceMixedImpedanceVelocityController";
164  }
165 
166  void
168  {
169  std::string taskName = getClassName() + "AdditionalTask";
170  runTask(taskName,
171  [&]
172  {
174  4); // please don't set this to 0 as it is the rtRun/control thread
177 
178  CycleUtil c(1);
179  getObjectScheduler()->waitForObjectStateMinimum(eManagedIceObjectStarted);
180  ARMARX_IMPORTANT << "Create a new thread for " << getClassName();
181  while (getState() == eManagedIceObjectStarted)
182  {
183  if (isControllerActive())
184  {
185  additionalTask();
186  }
187  c.waitForCycleDuration();
188  }
189  });
190  }
191 
192  void
194  {
195  arm->nonRtConfig = arm->bufferConfigUserToNonRt.getUpToDateReadBuffer();
196  arm->bufferConfigNonRtToRt.getWriteBuffer() = arm->nonRtConfig;
197  arm->bufferConfigNonRtToRt.commitWrite();
198  }
199 
200  void
202  {
203  robotUnit->updateVirtualRobot(nonRtRobot);
204  bool rtSafe = true;
205  for (auto& pair : limb)
206  {
207  limbNonRT(pair.second);
208  pair.second->rtStatusInNonRT =
209  pair.second->bufferRtStatusToNonRt.getUpToDateReadBuffer();
210  rtSafe = rtSafe and pair.second->rtStatusInNonRT.rtSafe;
211  }
212  if (not rtSafe)
213  {
214  for (auto& pair : limb)
215  {
217  "new target \n\n [%.2f, %.2f, %.2f]\n\nis too far away from the "
218  "current pose\n\n [%.2f, %.2f, %.2f]",
219  pair.second->rtStatusInNonRT.desiredPose(0, 3),
220  pair.second->rtStatusInNonRT.desiredPose(1, 3),
221  pair.second->rtStatusInNonRT.desiredPose(2, 3),
222  pair.second->rtStatusInNonRT.currentPose(0, 3),
223  pair.second->rtStatusInNonRT.currentPose(1, 3),
224  pair.second->rtStatusInNonRT.currentPose(2, 3))
225  .deactivateSpam(1.0);
226  }
227  }
228  }
229 
230  void
232  {
233  double timeMeasure = IceUtil::Time::now().toMicroSecondsDouble();
234  arm->rtConfig = arm->bufferConfigNonRtToRt.getUpToDateReadBuffer();
235  double time_update_non_rt_buffer =
236  IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
237 
238  if (arm->rtFirstRun.load())
239  {
240  arm->controller.ftsensor.reset();
241  }
242  else
243  {
244  arm->controller.updateFT(arm->rtConfig.ftConfig, arm->rtStatus);
245  }
246  double time_update_ft = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
247 
248  size_t nDoF = arm->sensorDevices.positionSensors.size();
249  double time_update_size = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
250  for (size_t i = 0; i < nDoF; ++i)
251  {
252  arm->rtStatus.jointPosition[i] = arm->sensorDevices.positionSensors[i]->position;
253  arm->rtStatus.jointVelocity[i] = arm->sensorDevices.velocitySensors[i]->velocity;
254  arm->rtStatus.jointTorque[i] = arm->sensorDevices.torqueSensors[i]->torque;
255  }
256 
257  double time_update_js = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
258  arm->rtStatus.deltaT = deltaT;
259  double time_update_rt_status = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
260 
261  arm->bufferRtStatusToNonRt.getWriteBuffer() = arm->rtStatus;
262  arm->bufferRtStatusToNonRt.commitWrite();
263  arm->bufferRtStatusToUser.getWriteBuffer() = arm->rtStatus;
264  arm->bufferRtStatusToUser.commitWrite();
265  double time_write_rt_buffer = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
266 
267  arm->controller.run(arm->rtConfig, arm->rtStatus);
268  double time_run_rt = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
269 
270  for (unsigned int i = 0; i < arm->rtStatus.nDoFTorque; i++)
271  {
272  auto jointIdx = arm->controller.jointIDTorqueMode[i];
273  arm->targetsTorque.at(i)->torque = arm->rtStatus.desiredJointTorques(jointIdx);
274  if (!arm->targetsTorque.at(i)->isValid())
275  {
276  arm->targetsTorque.at(i)->torque = 0;
277  }
278  }
279  for (unsigned int i = 0; i < arm->rtStatus.nDoFVelocity; i++)
280  {
281  auto jointIdx = arm->controller.jointIDVelocityMode[i];
282  arm->targetsVel.at(i)->velocity = arm->rtStatus.desiredJointVelocity(jointIdx);
283  // if (!targets.at(i)->isValid() || fabs(targets.at(i)->velocity) > cfg->maxJointVelocity)
284  if (!arm->targetsVel.at(i)->isValid())
285  {
286  arm->targetsVel.at(i)->velocity = 0;
287  }
288  }
289  arm->bufferRtStatusToOnPublish.getWriteBuffer() = arm->rtStatus;
290  arm->bufferRtStatusToOnPublish.commitWrite();
291 
292  arm->bufferConfigRtToOnPublish.getWriteBuffer() = arm->rtConfig;
293  arm->bufferConfigRtToOnPublish.commitWrite();
294 
295  arm->bufferConfigRtToUser.getWriteBuffer() = arm->rtConfig;
296  arm->bufferConfigRtToUser.commitWrite();
297  double time_rt_status_buffer = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
298  timeMeasure = IceUtil::Time::now().toMicroSecondsDouble() - timeMeasure;
299 
300  if (timeMeasure > 100)
301  {
302  ARMARX_RT_LOGF_WARN("---- rt too slow: unit in (us)"
303  "update_non_rt_buffer: %.2f\n"
304  "update_ft: %.2f\n"
305  "update_size: %.2f\n"
306  "update_js: %.2f\n"
307  "update_rt_status: %.2f\n"
308  "write_rt_buffer: %.2f\n"
309  "run_rt: %.2f\n"
310  "rt_status_buffer: %.2f\n"
311  "time all: %.2f\n",
312  time_update_non_rt_buffer, // 0-1 us
313  time_update_ft - time_update_non_rt_buffer, //
314  time_update_size - time_update_ft, //
315  time_update_js - time_update_size, //
316  time_update_rt_status - time_update_non_rt_buffer, // 1-2 us
317  time_write_rt_buffer - time_update_rt_status, // 0-1 us
318  time_run_rt - time_write_rt_buffer, // 26-33 us
319  time_rt_status_buffer - time_run_rt,
320  timeMeasure); // 0-1 us
321  }
322 
323  if (arm->rtFirstRun.load())
324  {
325  arm->rtFirstRun.store(false);
326  arm->rtReady.store(true);
327  }
328  }
329 
330  void
332  const IceUtil::Time& /*sensorValuesTimestamp*/,
333  const IceUtil::Time& timeSinceLastIteration)
334  {
335  double deltaT = timeSinceLastIteration.toSecondsDouble();
336  for (auto& pair : limb)
337  {
338  limbRT(pair.second, deltaT);
339  }
340  }
341 
342  Ice::FloatSeq
344  const Ice::Current& iceCurrent)
345  {
346  std::vector<float> tcpVel;
347  auto& arm = limb.at(rns);
348  auto s = arm->bufferRtStatusToUser.getUpToDateReadBuffer();
349  for (int i = 0; i < s.currentTwist.size(); i++)
350  {
351  tcpVel.push_back(s.currentTwist[i]);
352  }
353  return tcpVel;
354  }
355 
356  void
359  const Ice::Current& iceCurrent)
360  {
361  userConfig.fromAron(dto);
362  for (auto& pair : userConfig.cfg)
363  {
364  validateConfigData(pair.second, limb.at(pair.first));
365  limb.at(pair.first)->bufferConfigUserToNonRt.getWriteBuffer() = pair.second;
366  limb.at(pair.first)->bufferConfigUserToNonRt.commitWrite();
367  }
368  }
369 
370  void
372  const std::string& nodeSetName,
373  const bool forceGuard,
374  const bool torqueGuard,
375  const Ice::Current& iceCurrent)
376  {
377  auto it = userConfig.cfg.find(nodeSetName);
378  if (it != userConfig.cfg.end())
379  {
380  it->second.ftConfig.enableSafeGuardForce = forceGuard;
381  it->second.ftConfig.enableSafeGuardTorque = torqueGuard;
382  limb.at(nodeSetName)->controller.ftsensor.resetSafeGuardOffset();
384  << "reset safe guard with force torque sensors: safe? "
385  << limb.at(nodeSetName)->controller.ftsensor.isSafe(it->second.ftConfig);
386  limb.at(nodeSetName)->bufferConfigUserToNonRt.getWriteBuffer() = it->second;
387  limb.at(nodeSetName)->bufferConfigUserToNonRt.commitWrite();
388  }
389  else
390  {
391  ARMARX_WARNING << "no robot node set with name " << nodeSetName
392  << " found in the controllers.";
393  }
394  }
395 
396  bool
398  const std::string& nodeSetName,
399  const Ice::Current& iceCurrent)
400  {
401  auto it = userConfig.cfg.find(nodeSetName);
402  if (it != userConfig.cfg.end())
403  {
404  return limb.at(nodeSetName)->controller.ftsensor.ftSafe.load();
405  }
406  else
407  {
408  ARMARX_WARNING << "no robot node set with name " << nodeSetName
409  << " found in the controllers.";
410  }
411  return false;
412  }
413 
414  bool
416  const TargetPoseMap& targetPoseMap,
417  const TargetNullspaceMap& targetNullspaceMap,
418  const Ice::Current& iceCurrent)
419  {
420  for (auto& pair : userConfig.cfg)
421  {
422  for (size_t i = 0; i < 4; ++i)
423  {
424  for (int j = 0; j < 4; ++j)
425  {
426  pair.second.desiredPose(i, j) = targetPoseMap.at(pair.first)[i][j];
427  }
428  }
429  if (targetNullspaceMap.at(pair.first).size() > 0)
430  {
431  const size_t nDoF = pair.second.desiredNullspaceJointAngles.value().size();
432  ARMARX_CHECK_EQUAL(targetNullspaceMap.at(pair.first).size(), nDoF)
433  << "the joint numbers does not match";
434  for (size_t i = 0; i < nDoF; ++i)
435  {
436  pair.second.desiredNullspaceJointAngles.value()(i) =
437  targetNullspaceMap.at(pair.first)[i];
438  }
439  }
440  limb.at(pair.first)->bufferConfigUserToNonRt.getWriteBuffer() = pair.second;
441  limb.at(pair.first)->bufferConfigUserToNonRt.commitWrite();
442  }
443  return true;
444  }
445 
448  {
449  for (auto& pair : limb)
450  {
451  userConfig.cfg.at(pair.first) =
452  pair.second->bufferConfigRtToUser.getUpToDateReadBuffer();
453  }
454  return userConfig.toAronDTO();
455  }
456 
457  void
459  ArmPtr& arm)
460  {
461  const auto nDoF = arm->controller.numOfJoints;
462 
463  const auto checkSize = [nDoF](const auto& v) { ARMARX_CHECK_EQUAL(v.rows(), nDoF); };
464  const auto checkNonNegative = [](const auto& v) { ARMARX_CHECK((v.array() >= 0).all()); };
465 
466  if (!configData.desiredNullspaceJointAngles.has_value())
467  {
468  if (!isControllerActive())
469  {
470  ARMARX_INFO << "No user defined nullspace target, reset to zero with "
471  << VAROUT(nDoF);
472  configData.desiredNullspaceJointAngles = Eigen::VectorXf::Zero(nDoF);
473  arm->reInitPreActivate.store(true);
474  }
475  else
476  {
477  auto currentValue =
478  arm->bufferConfigRtToUser.getUpToDateReadBuffer().desiredNullspaceJointAngles;
480  << "Controller is active, but no user defined nullspace target. \n"
481  "You should first get up-to-date config of this controller and then update "
482  "it:\n"
483  " auto cfg = ctrl->getConfig(); \n"
484  " cfg.desiredPose = xxx;\n"
485  " ctrl->updateConfig(cfg);\n"
486  "Now, I decide by myself to use the existing values of nullspace target\n"
487  << currentValue.value();
488  configData.desiredNullspaceJointAngles = currentValue;
489  }
490  }
491  ARMARX_CHECK_GREATER(configData.safeDistanceToGoal, 100.0f);
492  checkSize(configData.desiredNullspaceJointAngles.value());
493  checkSize(configData.kdNullspaceTorque);
494  checkSize(configData.kpNullspaceTorque);
495  checkSize(configData.kdNullspaceVel);
496  checkSize(configData.kpNullspaceVel);
497 
498  checkNonNegative(configData.kdNullspaceTorque);
499  checkNonNegative(configData.kpNullspaceTorque);
500  checkNonNegative(configData.kpNullspaceVel);
501  checkNonNegative(configData.kdNullspaceVel);
502  checkNonNegative(configData.kdImpedance);
503  checkNonNegative(configData.kpImpedance);
504  }
505 
506  void
508  ArmPtr& arm,
509  const DebugObserverInterfacePrx& debugObs)
510  {
511  StringVariantBaseMap datafields;
512  auto rtData = arm->bufferConfigRtToOnPublish.getUpToDateReadBuffer();
513  auto rtStatus = arm->bufferRtStatusToOnPublish.getUpToDateReadBuffer();
514 
515 
516  common::debugEigenPose(datafields, "current_pose", rtStatus.currentPose);
517  common::debugEigenPose(datafields, "desired_pose", rtStatus.desiredPose);
518  common::debugEigenVec(datafields, "kpImpedance", rtData.kpImpedance);
519  common::debugEigenVec(datafields, "kdImpedance", rtData.kdImpedance);
520 
521  common::debugEigenVec(datafields, "currentForceTorque", rtStatus.currentForceTorque);
522 
523  common::debugEigenVec(datafields, "forceImpedance", rtStatus.forceImpedance);
524  common::debugEigenVec(datafields, "cartesianVelTarget", rtStatus.cartesianVelTarget);
525  common::debugEigenVec(datafields, "nullspaceTorque", rtStatus.nullspaceTorque);
526  common::debugEigenVec(datafields, "desiredJointTorques", rtStatus.desiredJointTorques);
527  debugObs->setDebugChannel(getClassName() + "_" + arm->kinematicChainName, datafields);
528  }
529 
530  void
532  const SensorAndControl&,
534  const DebugObserverInterfacePrx& debugObs)
535  {
536  for (auto& pair : limb)
537  {
538  limbPublish(pair.second, debugObs);
539  }
540  }
541 
542  void
544  {
545  for (auto& pair : limb)
546  {
547  pair.second->rtReady.store(false);
548  }
549  }
550 
551  void
553  {
554  VirtualRobot::RobotNodeSetPtr rns = rtGetRobot()->getRobotNodeSet(arm->kinematicChainName);
555  Eigen::Matrix4f currentPose = rns->getTCP()->getPoseInRootFrame();
556  ARMARX_IMPORTANT << "rt preactivate controller with target pose\n\n" << currentPose;
557 
558  if (arm->reInitPreActivate.load())
559  {
560  arm->rtConfig.desiredNullspaceJointAngles.value() = rns->getJointValuesEigen();
561  arm->rtConfig.desiredPose = currentPose;
562 
563  arm->bufferConfigUserToNonRt.reinitAllBuffers(arm->rtConfig);
564  arm->reInitPreActivate.store(false);
565  }
566  {
567  arm->nonRtConfig = arm->rtConfig;
568  arm->bufferConfigNonRtToRt.reinitAllBuffers(arm->rtConfig);
569  arm->bufferConfigRtToOnPublish.reinitAllBuffers(arm->rtConfig);
570  arm->bufferConfigRtToUser.reinitAllBuffers(arm->rtConfig);
571  }
572 
573  const auto nDoF = rns->getSize();
574  const auto nDoFTorque = arm->controller.jointIDTorqueMode.size();
575  const auto nDoFVelocity = arm->controller.jointIDVelocityMode.size();
576  {
577  arm->rtStatus.nDoFTorque = nDoFTorque;
578  arm->rtStatus.nDoFVelocity = nDoFVelocity;
579  arm->rtStatus.numJoints = nDoF;
580  arm->rtStatus.desiredJointTorques.setZero(nDoF);
581  arm->rtStatus.desiredJointVelocity.setZero(nDoF);
582  arm->rtStatus.forceImpedance.setZero();
583  arm->rtStatus.cartesianVelTarget.setZero();
584  arm->rtStatus.nullspaceTorque.setZero(nDoF);
585  arm->rtStatus.nullspaceVelocity.setZero(nDoF);
586 
587  arm->rtStatus.jointPosition.resize(nDoF, 0.);
588  arm->rtStatus.jointVelocity.resize(nDoF, 0.);
589  arm->rtStatus.jointTorque.resize(nDoF, 0.);
590  for (size_t i = 0; i < nDoF; ++i)
591  {
592  arm->rtStatus.jointPosition[i] = arm->sensorDevices.positionSensors[i]->position;
593  arm->rtStatus.jointVelocity[i] = arm->sensorDevices.velocitySensors[i]->velocity;
594  arm->rtStatus.jointTorque[i] = arm->sensorDevices.torqueSensors[i]->torque;
595  }
596 
597  arm->rtStatus.qpos = rns->getJointValuesEigen();
598  arm->rtStatus.qvel.setZero(nDoF);
599  arm->rtStatus.qvelFiltered.setZero(nDoF);
600 
601  arm->rtStatus.currentPose = currentPose;
602  arm->rtStatus.desiredPose = currentPose;
603  arm->rtStatus.currentTwist.setZero();
604  arm->rtStatus.poseDiffMatImp.setZero();
605  arm->rtStatus.poseErrorImp.setZero();
606  arm->rtStatus.jacobi.setZero(6, nDoF);
607  arm->rtStatus.jtpinv.setZero(6, nDoF);
608 
609  arm->rtStatus.deltaT = 0.0;
610  arm->rtStatus.rtSafe = false;
611 
612  arm->rtStatus.currentForceTorque.setZero();
613 
614  arm->rtStatusInNonRT = arm->rtStatus;
615  arm->bufferRtStatusToOnPublish.reinitAllBuffers(arm->rtStatus);
616  arm->bufferRtStatusToNonRt.reinitAllBuffers(arm->rtStatus);
617  arm->bufferRtStatusToUser.reinitAllBuffers(arm->rtStatus);
618  }
619 
620  arm->controller.preactivateInit(rns);
621  }
622 
623  void
625  {
626  for (auto& pair : limb)
627  {
628  ARMARX_INFO << "rtPreActivateController for " << pair.first;
629  limbReInit(pair.second);
630  userConfig.cfg.at(pair.first) = pair.second->rtConfig;
631  }
632  }
633 
634  void
636  {
637  // for (auto& pair : limb)
638  // {
639  // pair.second->controller.isInitialized.store(false);
640  // }
641  }
642 } // namespace armarx::control::njoint_controller::task_space
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::userConfig
ConfigDict userConfig
Definition: MixedImpedanceVelocityController.h:154
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::rtPreActivateController
void rtPreActivateController() override
This function is called before the controller is activated.
Definition: MixedImpedanceVelocityController.cpp:624
armarx::control::njoint_controller::task_space::registrationControllerNJointTaskspaceMixedImpedanceVelocityController
NJointControllerRegistration< NJointTaskspaceMixedImpedanceVelocityController > registrationControllerNJointTaskspaceMixedImpedanceVelocityController("NJointTaskspaceMixedImpedanceVelocityController")
armarx::ControlTargetBase::asA
const T * asA() const
Definition: ControlTargetBase.h:76
armarx::control::common::debugEigenPose
void debugEigenPose(StringVariantBaseMap &datafields, const std::string &name, Eigen::Matrix4f pose)
Definition: utils.cpp:110
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::getClassName
std::string getClassName(const Ice::Current &=Ice::emptyCurrent) const override
Definition: MixedImpedanceVelocityController.cpp:161
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:331
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:531
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:150
armarx::SensorValueBase::asA
const T * asA() const
Definition: SensorValueBase.h:82
armarx::SensorValueBase
The SensorValueBase class.
Definition: SensorValueBase.h:40
armarx::ControlTargetBase
Brief description of class JointControlTargetBase.
Definition: ControlTargetBase.h:47
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::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::updateTargetPose
bool updateTargetPose(const TargetPoseMap &targetPoseMap, const TargetNullspaceMap &targetNullspaceMap, const Ice::Current &=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:415
armarx::control::njoint_controller::task_space
Definition: AdmittanceController.cpp:33
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::additionalTask
virtual void additionalTask()
Definition: MixedImpedanceVelocityController.cpp:201
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
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::NJointControllerBase::ConfigPtrT
NJointControllerConfigPtr ConfigPtrT
Definition: NJointControllerBase.h:586
MixedImpedanceVelocityController.h
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbInit
void limbInit(const std::string nodeSetName, ArmPtr &arm, Config &cfg, VirtualRobot::RobotPtr &nonRtRobotPtr)
Definition: MixedImpedanceVelocityController.cpp:41
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::validateConfigData
void validateConfigData(Config &config, ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:458
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:447
armarx::NJointControllerBase::rtGetRobot
const VirtualRobot::RobotPtr & rtGetRobot()
TODO make protected and use attorneys.
Definition: NJointControllerBase.h:845
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::control::TargetNullspaceMap
dictionary< string, Ice::FloatSeq > TargetNullspaceMap
Definition: ControllerInterface.ice:40
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbNonRT
void limbNonRT(ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:193
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:371
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:138
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::isSafeForceTorque
bool isSafeForceTorque(const std::string &nodeSetName, const Ice::Current &iceCurrent=Ice::emptyCurrent) override
Definition: MixedImpedanceVelocityController.cpp:397
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbReInit
void limbReInit(ArmPtr &arm)
Definition: MixedImpedanceVelocityController.cpp:552
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:343
ArmarXObjectScheduler.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
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:152
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:231
armarx::control::common::debugEigenVec
void debugEigenVec(StringVariantBaseMap &datafields, const std::string &name, Eigen::VectorXf vec)
Definition: utils.cpp:122
utils.h
CycleUtil.h
armarx::control::NJointTaskspaceMixedImpedanceVelocityControllerInterface::calibrateFTSensor
void calibrateFTSensor()
ft sensor
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::onInitNJointController
void onInitNJointController() override
NJointControllerBase interface.
Definition: MixedImpedanceVelocityController.cpp:167
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:635
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:357
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_INFO
#define ARMARX_INFO
Definition: Logging.h:174
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::control::TargetPoseMap
dictionary< string, FloatSeqSeq > TargetPoseMap
Definition: ControllerInterface.ice:39
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::Config
law::TaskspaceMixedImpedanceVelocityController::Config Config
Definition: MixedImpedanceVelocityController.h:56
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::limbPublish
void limbPublish(ArmPtr &arm, const DebugObserverInterfacePrx &debugObs)
Definition: MixedImpedanceVelocityController.cpp:507
armarx::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::ArmPtr
std::unique_ptr< ArmData > ArmPtr
Definition: MixedImpedanceVelocityController.h:100
armarx::control::common::sVecToString
std::string sVecToString(const std::vector< std::string > &vec, const std::string &delimiter)
Definition: utils.cpp:291
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::control::njoint_controller::task_space::NJointTaskspaceMixedImpedanceVelocityController::robotUnit
RobotUnitPtr robotUnit
Definition: MixedImpedanceVelocityController.h:153
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