ZeroTorque.cpp
Go to the documentation of this file.
1 #include "ZeroTorque.h"
2 
3 #include <VirtualRobot/Robot.h>
4 #include <VirtualRobot/RobotNodeSet.h>
5 
6 #include <RobotAPI/interface/units/RobotUnit/NjointZeroTorqueController.h>
7 
9 {
12  {
13  ParamType defaults;
14  defaults.nodeSetName = "RightArm";
15  return ::armarx::skills::SkillDescription{
16  .skillId = {.skillName = "ZeroTorque"},
17  .description = "Enables zero torque mode for the runtime",
18  .rootProfileDefaults = defaults.toAron(),
19  .timeout = ::armarx::Duration::Minutes(10),
20  .parametersType = ParamType::ToAronType(),
21  };
22  }
23 
24  ZeroTorque::ZeroTorque(const config::ZeroTorque& r) :
25  ::armarx::skills::SimpleSpecializedSkill<params::ZeroTorque>(GetSkillDescription()),
26  config_(r)
27  {
28  }
29 
31  ZeroTorque::main(const SpecializedMainInput& in)
32  {
34  ARMARX_CHECK_NOT_NULL(controller_);
35  controller_->activateController();
37  while (not shouldSkillTerminate())
38  {
39  ARMARX_INFO << "Waiting";
41  }
42  controller_->deactivateController();
44  }
45 
46  void
48  {
49  context_ = context;
50  }
51 
55  {
57  NJointZeroTorqueControllerConfigPtr config(new NJointZeroTorqueControllerConfig());
58  config->maxTorque = 0;
59  controllerName_ = "ControlSkills_ZeroTorque_" + in.parameters.nodeSetName;
60  ARMARX_CHECK_EXPRESSION(context_.localRobot_->hasRobotNodeSet(in.parameters.nodeSetName))
61  << "RNS " << in.parameters.nodeSetName << " is unknown";
62  auto nodeSet = context_.localRobot_->getRobotNodeSet(in.parameters.nodeSetName);
63  for (auto& name : nodeSet->getNodeNames())
64  {
65  config->jointNames.push_back(name);
66  }
67  ARMARX_CHECK_GREATER(config->jointNames.size(), 0) << "RNS is empty!";
68  controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
69  context_.robotUnitPlugin_->getRobotUnit()->getNJointController(controllerName_));
70  if (not controller_)
71  {
72  controller_ = armarx::NJointZeroTorqueControllerInterfacePrx::checkedCast(
73  context_.robotUnitPlugin_->createNJointController(
75  controllerName_,
76  config));
77  }
79  }
80 
84  {
86  context_.robotUnitPlugin_->getRobotUnit()->deactivateAndDeleteNJointController(
87  controllerName_);
88  // controller_->deactivateAndDeleteController();
90  }
91 
92 } // namespace armarx::control::skills::skills
ZeroTorque.h
armarx::skills::SimpleSpecializedSkill< armarx::control::skills::params::ZeroTorque >::init
Skill::InitResult init() final
Definition: SimpleSpecializedSkill.h:62
armarx::skills::TerminatedSkillStatus::Succeeded
@ Succeeded
skills
This file is part of ArmarX.
armarx::skills::SimpleSpecializedSkill< armarx::control::skills::params::ZeroTorque >::ParamType
armarx::control::skills::params::ZeroTorque ParamType
Definition: SimpleSpecializedSkill.h:14
armarx::control::skills::skills::ZeroTorque::ZeroTorque
ZeroTorque(const config::ZeroTorque &)
Definition: ZeroTorque.cpp:24
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
armarx::core::time::Clock::WaitFor
static void WaitFor(const Duration &duration)
Wait for a certain duration on the virtual clock.
Definition: Clock.cpp:104
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::control::skills::skills::ZeroTorque::GetSkillDescription
::armarx::skills::SkillDescription GetSkillDescription()
Definition: ZeroTorque.cpp:11
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::control::skills::skills::ZeroTorque
Definition: ZeroTorque.h:16
ARMARX_CHECK_GREATER
#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...
Definition: ExpressionException.h:116
armarx::control::skills::skills::ZeroTorque::Context::localRobot_
VirtualRobot::RobotPtr localRobot_
Definition: ZeroTorque.h:24
armarx::control::skills::skills::ZeroTorque::connectTo
void connectTo(const Context &context)
Definition: ZeroTorque.cpp:47
armarx::skills::SimpleSpecializedSkill< armarx::control::skills::params::ZeroTorque >::exit
Skill::ExitResult exit() final
Definition: SimpleSpecializedSkill.h:81
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::control::RobotUnitControllerNames::NJointZeroTorqueController
const string NJointZeroTorqueController
Definition: ControllerInterface.ice:35
armarx::skills::SimpleSpecializedSkill::SpecializedInitInput::parameters
AronT parameters
Definition: SimpleSpecializedSkill.h:21
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::core::time::Duration::Minutes
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
Definition: Duration.cpp:111
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
armarx::control::skills::skills::ZeroTorque::Context::robotUnitPlugin_
std::experimental::observer_ptr< armarx::plugins::RobotUnitComponentPlugin > robotUnitPlugin_
Definition: ZeroTorque.h:26
armarx::skills::Skill::ExitResult
A result struct for skill exit function.
Definition: Skill.h:55
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::skills::SimpleSpecializedSkill::SpecializedInitInput
Definition: SimpleSpecializedSkill.h:18
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::skills::SimpleSpecializedSkill< armarx::control::skills::params::ZeroTorque >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::control::skills::skills
Definition: ExecuteTrajectory.cpp:18
armarx::skills::Skill::shouldSkillTerminate
bool shouldSkillTerminate() const
Returns whether the skill should terminate as soon as possible.
Definition: Skill.cpp:371
armarx::skills::Skill::InitResult
A result struct for skill initialization.
Definition: Skill.h:36
armarx::control::skills::skills::ZeroTorque::Context
Definition: ZeroTorque.h:21
armarx::skills::SimpleSpecializedSkill::SpecializedExitInput
Definition: SimpleSpecializedSkill.h:31
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55