2#include <Ice/Exception.h>
4#include <VirtualRobot/Robot.h>
5#include <VirtualRobot/RobotNodeSet.h>
14#include <RobotAPI/interface/units/RobotUnit/NjointZeroTorqueController.h>
19#include <armarx/control/skills/aron/ZeroTorque.aron.generated.h>
23 armarx::skills::SkillDescription
27 defaults.nodeSetName =
"RightArm";
28 return ::armarx::skills::SkillDescription{
29 .skillId = {.skillName =
"ZeroTorque"},
30 .description =
"Enables zero torque mode for the runtime",
31 .rootProfileDefaults = defaults.toAron(),
33 .parametersType = ParamType::ToAronType(),
53 bool terminate =
false;
54 bool isControllerActive =
false;
58 bool hasControllerBeenActive =
false;
59 bool hasTerminationBeenRequested =
false;
62 ARMARX_INFO <<
"Requesting to start the zero-torque controller.";
65 controller_->activateController();
67 catch (
const Ice::Exception& e)
69 ARMARX_WARNING <<
"Failed to request the controller getting activated: " << e.what();
83 hasControllerBeenActive = isControllerActive;
84 isControllerActive = controller_->isControllerActive();
87 hasTerminationBeenRequested or (hasControllerBeenActive and not isControllerActive);
90 if (not hasControllerBeenActive and isControllerActive)
99 <<
"Waiting for termination request or controller getting inactive.";
102 }
while (not terminate);
103 ARMARX_INFO <<
"Terminating the zero-torque controller. Current state:\n"
104 <<
"explicit termination request: " << hasTerminationBeenRequested <<
"\n"
105 <<
"controller has been active: " << hasControllerBeenActive <<
"\n"
106 <<
"controller is (still) active: " << isControllerActive;
109 if (armarx::NJointZeroTorqueControllerInterfacePrx::uncheckedCast(controller_))
113 if (controller_->isControllerActive())
118 ARMARX_INFO <<
"About to deactivate the controller";
119 controller_->deactivateController();
121 catch (
const Ice::Exception& e)
123 ARMARX_WARNING <<
"Failed to request the controller getting deactivated: "
129 while (controller_->isControllerActive())
132 <<
"Waiting for the controller to get deactivated.";
137 ARMARX_WARNING <<
"Trying to deactivate the controller timed out: "
156 controller_->deleteController();
158 catch (
const Ice::Exception& e)
160 ARMARX_WARNING <<
"Failed to request the controller getting deleted: "
165 while (armarx::NJointZeroTorqueControllerInterfacePrx::uncheckedCast(controller_))
168 <<
"Waiting for the controller to get deleted.";
182 ARMARX_INFO <<
"Performing an additional explicit deletion of the controller is "
183 "not attempted at the moment.";
188 if (hasTerminationBeenRequested)
190 if (hasControllerBeenActive)
196 ARMARX_INFO <<
"ZeroTorque controller has successfully been cleaned up, "
197 "but has never been active.";
203 ARMARX_INFO <<
"ZeroTorque controller has successfully been cleaned up, "
204 "but was terminated due to having gone inactive instead of "
205 "due to an explicit request.";
222 auto robot = context_.virtualRobotReader->getRobot(config_.robotName);
228 NJointZeroTorqueControllerConfigPtr config(
new NJointZeroTorqueControllerConfig());
229 config->maxTorque = 0;
230 controllerName_ =
"ControlSkills_ZeroTorque_" + in.
parameters.nodeSetName;
233 <<
"RNS " << in.
parameters.nodeSetName <<
" is unknown";
234 auto nodeSet = robot->getRobotNodeSet(in.
parameters.nodeSetName);
235 for (
auto& name : nodeSet->getNodeNames())
237 config->jointNames.push_back(name);
240 controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
241 context_.robotUnitPlugin_->getRobotUnit()->getNJointController(controllerName_));
244 controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
245 context_.robotUnitPlugin_->createNJointController(
246 armarx::RobotUnitControllerNames::NJointZeroTorqueController,
258 context_.robotUnitPlugin_->getRobotUnit()->deactivateAndDeleteNJointController(
static DateTime Now()
Current time on the virtual clock.
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
::armarx::skills::SkillDescription GetSkillDescription()
void connectTo(const Context &context)
ZeroTorque(const config::ZeroTorque &)
Represents a point in time.
armarx::control::skills::params::ZeroTorque ParamType
virtual InitResult init()
Override this method with the actual implementation.
bool shouldSkillTerminate() const override
Returns whether the skill should terminate as soon as possible.
virtual MainResult main()
Override this method with the actual implementation.
virtual ExitResult exit()
Override this method with the actual implementation.
#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...
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
This file is part of ArmarX.
A result struct for skill exit function.
A result struct for skill initialization.
A result struct for th main method of a skill.