25 #include <VirtualRobot/MathTools.h>
37 #include <simox/control/geodesics/util.h>
38 #include <simox/control/robot/NodeInterface.h>
42 NJointControllerRegistration<NJointTaskspaceCollisionAvoidanceImpedanceController>
44 "NJointTaskspaceCollisionAvoidanceImpedanceController");
48 const RobotUnitPtr& robotUnit,
49 const NJointControllerConfigPtr& config,
53 ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
55 userCfgWithColl = CollisionCtrlCfg::FromAron(cfg->config);
57 coll = std::make_shared<core::CollisionAvoidanceBase>(rtGetRobot(), userCfgWithColl.coll);
58 collReady.store(
true);
59 ARMARX_INFO <<
"-- " << getClassName() <<
" initialized --";
65 return "NJointTaskspaceCollisionAvoidanceImpedanceController";
71 double time_measure = IceUtil::Time::now().toMicroSecondsDouble();
73 double time_update_status = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
75 arm->controller.run(arm->rtConfig, arm->rtStatus);
76 double time_run_rt = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
81 coll->rtLimbControllerRun(arm->kinematicChainName,
82 arm->rtStatus.jointPos,
83 arm->rtStatus.qvelFiltered,
84 arm->rtConfig.torqueLimit,
85 arm->rtStatus.desiredJointTorques);
87 double time_coll_run = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
92 coll->collLimb.at(arm->kinematicChainName)->rts.desiredJointTorques);
98 double time_set_target = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
100 time_measure = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
102 if (time_measure > 200)
105 "time_update_status: %.2f\n"
106 "run_rt_limb: %.2f\n"
107 "run_coll_rt_limb: %.2f\n"
108 "set_target_limb: %.2f\n"
111 time_run_rt - time_update_status,
112 time_coll_run - time_run_rt,
113 time_set_target - time_coll_run,
115 .deactivateSpam(1.0f);
124 double deltaT = timeSinceLastIteration.toSecondsDouble();
126 if (collReady.load())
129 coll->updateRtConfigFromUser();
130 coll->rtCollisionChecking();
132 for (
auto& pair :
limb)
134 this->
limbRT(pair.second, deltaT);
138 hands->updateRTStatus(deltaT);
146 const Ice::Current& iceCurrent)
149 auto cfg = common::control_law::arondto::CollisionAvoidanceConfigDict::FromAron(dto);
150 coll->setUserCfg(cfg);
155 const Ice::Current& iceCurrent)
157 if (not collReady.load())
161 return coll->userCfg.toAronDTO();
167 const Ice::Current& iceCurrent)
170 userCfgWithColl = CollisionCtrlCfg::FromAron(dto);
172 coll->setUserCfg(userCfgWithColl.coll);
181 return userCfgWithColl.toAronDTO();
192 auto rtStatus = arm->bufferRTtoPublish.getUpToDateReadBuffer();
194 datafields[
"trackingError"] =
new Variant(rtStatus.trackingError);
200 datafields,
"projectedImpedanceTorque", rtStatus.projImpedanceJointTorque);
206 Eigen::VectorXf selfCollNullspace = rtStatus.selfCollNullSpace.diagonal();
207 Eigen::VectorXf jointLimNullspace = rtStatus.jointLimNullSpace.diagonal();
242 for (
int i = 0; i < rtStatus.activeCollPairsNum; ++i)
261 .fromTo(rtStatus.selfCollDataVec[i].point * 1000.0,
262 rtStatus.selfCollDataVec[i].point * 1000.0 +
263 rtStatus.selfCollDataVec[i].direction * 50.0 *
264 rtStatus.selfCollDataVec[i].repulsiveForce)
265 .
color(simox::Color::blue()));
566 debugObs->setDebugChannel(
"CollAvoid_ImpCtrl_" + arm->nodeSetName, datafields);
578 for (
auto& pair : coll->collLimb)
589 "rt Preactivate controller NJointTaskspaceCollisionAvoidanceImpedanceController");
592 if (collReady.load())
595 coll->rtPreActivate();
603 if (collReady.load())
606 coll->rtPostDeactivate();
609 "post deactivate: NJointTaskspaceCollisionAvoidanceImpedanceController");
615 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
616 const std::map<std::string, ConstSensorDevicePtr>&)
622 ::armarx::WidgetDescription::WidgetSeq widgets;
625 LabelPtr label =
new Label;
626 label->text =
"select a controller config";
628 StringComboBoxPtr cfgBox =
new StringComboBox;
629 cfgBox->name =
"config_box";
630 cfgBox->defaultIndex = 0;
631 cfgBox->multiSelect =
false;
633 cfgBox->options = std::vector<std::string>{
634 "default",
"default_a7_right",
"default_a7_right_zero_torque"};
637 layout->children.emplace_back(label);
638 layout->children.emplace_back(cfgBox);
641 layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
650 auto cfgName =
values.at(
"config_box")->getString();
653 "controller_config/NJointTaskspaceCollisionAvoidanceImpedanceController/" + cfgName +
658 auto cfgDTO = armarx::readFromJson<CollisionCtrlCfg>(configPath.
toSystemPath());
661 return new ConfigurableNJointControllerConfig{cfgDTO.toAronDTO()};