3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotNodeSet.h>
8 #include <RobotAPI/interface/units/RobotUnit/NjointZeroTorqueController.h>
16 defaults.nodeSetName =
"RightArm";
17 return ::armarx::skills::SkillDescription{
19 .description =
"Enables zero torque mode for the runtime",
20 .rootProfileDefaults = defaults.toAron(),
22 .parametersType = ParamType::ToAronType(),
43 bool isControllerActive =
false;
47 bool hasControllerBeenActive =
false;
48 bool hasTerminationBeenRequested =
false;
51 ARMARX_INFO <<
"Requesting to start the zero-torque controller.";
54 controller_->activateController();
56 catch (
const Ice::Exception& e)
58 ARMARX_WARNING <<
"Failed to request the controller getting activated: " << e.what();
72 hasControllerBeenActive = isControllerActive;
73 isControllerActive = controller_->isControllerActive();
76 hasTerminationBeenRequested or (hasControllerBeenActive and not isControllerActive);
79 if (not hasControllerBeenActive and isControllerActive)
88 <<
"Waiting for termination request or controller getting inactive.";
92 ARMARX_INFO <<
"Terminating the zero-torque controller. Current state:\n"
93 <<
"explicit termination request: " << hasTerminationBeenRequested <<
"\n"
94 <<
"controller has been active: " << hasControllerBeenActive <<
"\n"
95 <<
"controller is (still) active: " << isControllerActive;
98 if (armarx::NJointZeroTorqueControllerInterfacePrx::uncheckedCast(controller_))
102 if (controller_->isControllerActive())
107 ARMARX_INFO <<
"About to deactivate the controller";
108 controller_->deactivateController();
110 catch (
const Ice::Exception& e)
112 ARMARX_WARNING <<
"Failed to request the controller getting deactivated: "
118 while (controller_->isControllerActive())
121 <<
"Waiting for the controller to get deactivated.";
126 ARMARX_WARNING <<
"Trying to deactivate the controller timed out: "
145 controller_->deleteController();
147 catch (
const Ice::Exception& e)
149 ARMARX_WARNING <<
"Failed to request the controller getting deleted: "
154 while (armarx::NJointZeroTorqueControllerInterfacePrx::uncheckedCast(controller_))
157 <<
"Waiting for the controller to get deleted.";
171 ARMARX_INFO <<
"Performing an additional explicit deletion of the controller is "
172 "not attempted at the moment.";
177 if (hasTerminationBeenRequested)
179 if (hasControllerBeenActive)
185 ARMARX_INFO <<
"ZeroTorque controller has successfully been cleaned up, "
186 "but has never been active.";
192 ARMARX_INFO <<
"ZeroTorque controller has successfully been cleaned up, "
193 "but was terminated due to having gone inactive instead of "
194 "due to an explicit request.";
210 NJointZeroTorqueControllerConfigPtr config(
new NJointZeroTorqueControllerConfig());
211 config->maxTorque = 0;
212 controllerName_ =
"ControlSkills_ZeroTorque_" + in.
parameters.nodeSetName;
214 <<
"RNS " << in.
parameters.nodeSetName <<
" is unknown";
216 for (
auto& name : nodeSet->getNodeNames())
218 config->jointNames.push_back(name);
221 controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
222 context_.
robotUnitPlugin_->getRobotUnit()->getNJointController(controllerName_));
225 controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
239 context_.
robotUnitPlugin_->getRobotUnit()->deactivateAndDeleteNJointController(