25 #include <VirtualRobot/MathTools.h>
37 #include <simox/control/geodesics/util.h>
38 #include <simox/control/robot/NodeInterface.h>
42 NJointControllerRegistration<NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController>
44 "NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController");
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() <<
" initized --";
64 const Ice::Current&)
const
66 return "NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController";
73 double time_easure = IceUtil::Time::now().toMicroSecondsDouble();
75 double time_update_status = IceUtil::Time::now().toMicroSecondsDouble() - time_easure;
77 arm->controller.run(arm->rtConfig, arm->rtStatus);
78 double time_run_rt = IceUtil::Time::now().toMicroSecondsDouble() - time_easure;
83 coll->rtLimbControllerRun(arm->kinematicChainName,
84 arm->rtStatus.jointPos,
85 arm->rtStatus.qvelFiltered,
86 arm->rtConfig.torqueLimit,
87 arm->rtStatus.desiredJointTorques);
89 double time_coll_run = IceUtil::Time::now().toMicroSecondsDouble() - time_easure;
94 arm->rtStatus.nDoFTorque,
95 arm->rtStatus.nDoFVelocity,
96 coll->collLimb.at(arm->kinematicChainName)->rts.desiredJointTorques,
97 arm->rtStatus.desiredJointVelocity);
102 arm->rtStatus.nDoFTorque,
103 arm->rtStatus.nDoFVelocity,
104 arm->rtStatus.desiredJointTorques,
105 arm->rtStatus.desiredJointVelocity);
107 double time_set_target = IceUtil::Time::now().toMicroSecondsDouble() - time_easure;
109 time_easure = IceUtil::Time::now().toMicroSecondsDouble() - time_easure;
111 if (time_easure > 200)
114 "time_update_status: %.2f\n"
115 "run_rt_limb: %.2f\n"
116 "run_coll_rt_limb: %.2f\n"
117 "set_target_limb: %.2f\n"
120 time_run_rt - time_update_status,
121 time_coll_run - time_run_rt,
122 time_set_target - time_coll_run,
124 .deactivateSpam(1.0f);
133 double deltaT = timeSinceLastIteration.toSecondsDouble();
135 if (collReady.load())
138 coll->updateRtConfigFromUser();
139 coll->rtCollisionChecking();
141 for (
auto& pair :
limb)
143 this->
limbRT(pair.second, deltaT);
147 hands->updateRTStatus(deltaT);
155 const Ice::Current& iceCurrent)
158 auto cfg = common::control_law::arondto::CollisionAvoidanceConfigDict::FromAron(dto);
159 coll->setUserCfg(cfg);
164 const Ice::Current& iceCurrent)
166 if (not collReady.load())
170 return coll->userCfg.toAronDTO();
176 const Ice::Current& iceCurrent)
179 userCfgWithColl = CollisionCtrlCfg::FromAron(dto);
181 coll->setUserCfg(userCfgWithColl.coll);
186 const Ice::Current& iceCurrent)
188 for (
auto& pair :
limb)
191 pair.second->bufferConfigRtToUser.getUpToDateReadBuffer();
194 return userCfgWithColl.toAronDTO();
205 auto rtStatus = arm->bufferRTtoPublish.getUpToDateReadBuffer();
207 datafields[
"trackingError"] =
new Variant(rtStatus.trackingError);
213 datafields,
"projectedImpedanceTorque", rtStatus.projImpedanceJointTorque);
219 Eigen::VectorXf selfCollNullspace = rtStatus.selfCollNullSpace.diagonal();
220 Eigen::VectorXf jointLimNullspace = rtStatus.jointLimNullSpace.diagonal();
243 datafields[
"activeCollPairsNum"] =
new Variant(rtStatus.activeCollPairsNum);
244 datafields[
"collisionPairsNum"] =
new Variant(rtStatus.collisionPairsNum);
245 datafields[
"jointLimitNullspaceTime"] =
new Variant(rtStatus.jointLimitNullspaceTime);
246 datafields[
"jointLimitTorqueTime"] =
new Variant(rtStatus.jointLimitTorqueTime);
247 datafields[
"collisionTorqueTime"] =
new Variant(rtStatus.collisionTorqueTime);
248 datafields[
"selfCollNullspaceTime"] =
new Variant(rtStatus.selfCollNullspaceTime);
249 datafields[
"collisionPairTime"] =
new Variant(rtStatus.collisionPairTime);
250 datafields[
"impForceRatio"] =
new Variant(rtStatus.impForceRatio);
251 datafields[
"impTorqueRatio"] =
new Variant(rtStatus.impTorqueRatio);
255 for (
int i = 0; i < rtStatus.activeCollPairsNum; ++i)
274 .fromTo(rtStatus.selfCollDataVec[i].point * 1000.0,
275 rtStatus.selfCollDataVec[i].point * 1000.0 +
276 rtStatus.selfCollDataVec[i].direction * 50.0 *
277 rtStatus.selfCollDataVec[i].repulsiveForce)
278 .
color(simox::Color::blue()));
284 new Variant(rtStatus.selfCollDataVec[i].minDistance);
286 new Variant(rtStatus.selfCollDataVec[i].repulsiveForce);
288 new Variant(-1.0f * rtStatus.selfCollDataVec[i].damping *
289 rtStatus.selfCollDataVec[i].distanceVelocity);
291 new Variant(rtStatus.selfCollDataVec[i].desiredNSColl);
293 datafields,
std::to_string(i) +
"_point", rtStatus.selfCollDataVec[i].point);
295 datafields,
std::to_string(i) +
"_dir", rtStatus.selfCollDataVec[i].direction);
579 debugObs->setDebugChannel(
"CollAvoid_ImpCtrl_" + arm->nodeSetName, datafields);
591 for (
auto& pair : coll->collLimb)
602 "NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController");
605 if (collReady.load())
608 coll->rtPreActivate();
616 if (collReady.load())
619 coll->rtPostDeactivate();
622 "NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController");
628 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
629 const std::map<std::string, ConstSensorDevicePtr>&)
635 ::armarx::WidgetDescription::WidgetSeq widgets;
638 LabelPtr label =
new Label;
639 label->text =
"select a controller config";
641 StringComboBoxPtr cfgBox =
new StringComboBox;
642 cfgBox->name =
"config_box";
643 cfgBox->defaultIndex = 0;
644 cfgBox->multiSelect =
false;
646 cfgBox->options = std::vector<std::string>{
647 "default",
"default_a7_right",
"default_a7_right_zero_torque"};
650 layout->children.emplace_back(label);
651 layout->children.emplace_back(cfgBox);
654 layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
663 auto cfgName =
values.at(
"config_box")->getString();
666 "controller_config/NJointTaskspaceCollisionAvoidanceMixedImpedanceVelocityController/" +
671 auto cfgDTO = armarx::readFromJson<CollisionCtrlCfg>(configPath.
toSystemPath());
674 return new ConfigurableNJointControllerConfig{cfgDTO.toAronDTO()};