25 #include <VirtualRobot/MathTools.h>
26 #include <VirtualRobot/RobotNodeSet.h>
43 #include <simox/control/geodesics/util.h>
44 #include <simox/control/robot/NodeInterface.h>
48 NJointControllerRegistration<NJointTaskspaceCollisionAvoidanceImpedanceController>
50 "NJointTaskspaceCollisionAvoidanceImpedanceController");
55 const NJointControllerConfigPtr& config,
59 ConfigPtrT cfg = ConfigPtrT::dynamicCast(config);
61 userCfgWithColl = CollisionCtrlCfg::FromAron(cfg->config);
63 coll = std::make_shared<core::CollisionAvoidanceBase>(rtGetRobot(), userCfgWithColl.coll);
64 collReady.store(
true);
65 ARMARX_INFO <<
"-- " << getClassName() <<
" initialized --";
71 return "NJointTaskspaceCollisionAvoidanceImpedanceController";
77 double time_measure = IceUtil::Time::now().toMicroSecondsDouble();
79 double time_update_status = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
81 arm->controller.run(arm->rtConfig, arm->rtStatus);
82 double time_run_rt = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
87 coll->rtLimbControllerRun(arm->kinematicChainName,
88 arm->rtStatus.jointPos,
89 arm->rtStatus.qvelFiltered,
90 arm->rtConfig.torqueLimit,
91 arm->rtStatus.desiredJointTorques);
93 double time_coll_run = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
98 coll->collLimb.at(arm->kinematicChainName).rts.desiredJointTorques);
104 double time_set_target = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
106 time_measure = IceUtil::Time::now().toMicroSecondsDouble() - time_measure;
108 if (time_measure > 200)
111 "time_update_status: %.2f\n"
112 "run_rt_limb: %.2f\n"
113 "run_coll_rt_limb: %.2f\n"
114 "set_target_limb: %.2f\n"
117 time_run_rt - time_update_status,
118 time_coll_run - time_run_rt,
119 time_set_target - time_coll_run,
121 .deactivateSpam(1.0f);
130 double deltaT = timeSinceLastIteration.toSecondsDouble();
132 if (collReady.load())
135 coll->updateRtConfigFromUser();
136 coll->rtCollisionChecking();
138 for (
auto& pair :
limb)
140 this->
limbRT(pair.second, deltaT);
144 hands->updateRTStatus(deltaT);
152 const Ice::Current& iceCurrent)
155 auto cfg = common::control_law::arondto::CollisionAvoidanceConfigDict::FromAron(dto);
156 coll->setUserCfg(cfg);
161 const Ice::Current& iceCurrent)
163 if (not collReady.load())
167 return coll->userCfg.toAronDTO();
173 const Ice::Current& iceCurrent)
176 userCfgWithColl = CollisionCtrlCfg::FromAron(dto);
178 coll->setUserCfg(userCfgWithColl.coll);
187 return userCfgWithColl.toAronDTO();
200 datafields[
"trackingError"] =
new Variant(rtStatus.trackingError);
206 datafields,
"projectedImpedanceTorque", rtStatus.projImpedanceJointTorque);
212 Eigen::VectorXf selfCollNullspace = rtStatus.selfCollNullSpace.diagonal();
213 Eigen::VectorXf jointLimNullspace = rtStatus.jointLimNullSpace.diagonal();
572 debugObs->setDebugChannel(
"CollAvoid_ImpCtrl_" + arm.
nodeSetName, datafields);
584 for (
auto& pair : coll->collLimb)
595 "rt Preactivate controller NJointTaskspaceCollisionAvoidanceImpedanceController");
598 if (collReady.load())
601 coll->rtPreActivate();
609 if (collReady.load())
612 coll->rtPostDeactivate();
615 "post deactivate: NJointTaskspaceCollisionAvoidanceImpedanceController");
621 const std::map<std::string, ConstControlDevicePtr>& controlDevices,
622 const std::map<std::string, ConstSensorDevicePtr>&)
628 ::armarx::WidgetDescription::WidgetSeq widgets;
631 LabelPtr label =
new Label;
632 label->text =
"select a controller config";
634 StringComboBoxPtr cfgBox =
new StringComboBox;
635 cfgBox->name =
"config_box";
636 cfgBox->defaultIndex = 0;
637 cfgBox->multiSelect =
false;
640 std::vector<std::string>{
"default",
"default_a7_right",
"default_a7_right_zero_torque"};
643 layout->children.emplace_back(label);
644 layout->children.emplace_back(cfgBox);
647 layout->children.insert(layout->children.end(), widgets.begin(), widgets.end());
656 auto cfgName =
values.at(
"config_box")->getString();
659 "controller_config/NJointTaskspaceCollisionAvoidanceImpedanceController/" + cfgName +
664 auto cfgDTO = armarx::readFromJson<CollisionCtrlCfg>(configPath.
toSystemPath());
667 return new ConfigurableNJointControllerConfig{cfgDTO.toAronDTO()};