MoveJointsToNamedConfiguration.cpp
Go to the documentation of this file.
2 
3 #include <set>
4 
5 #include <VirtualRobot/RobotNodeSet.h>
6 
8 
10 
11 #include <armarx/control/skills/aron/MoveJointsToPositionParams.aron.generated.h>
14 
16 {
17 
19  SimpleSpecializedSkill(GetSkillDescription()), remote(remote)
20  {
21  }
22 
25  {
26  ParamType defaultParams;
27  // - arms
28  defaultParams.enableLeftArm = true;
29  defaultParams.enableRightArm = true;
30  // - hands
31  defaultParams.enableLeftHand = false;
32  defaultParams.enableRightHand = false;
33  // - torso
34  defaultParams.enableTorso = true;
35  // - head (-> should be controlled by GazeController)
36  defaultParams.enableHead = false;
37 
38  std::stringstream desc;
39  desc << "Move all joints to a named configuration of the robot model." << "\n\n"
40  << "The `enable*` parameters can be used to enable/disable movement for different "
41  "body parts of the robot.";
42 
45  .description = desc.str(),
46  .rootProfileDefaults = defaultParams.toAron(),
47  .timeout = ::armarx::Duration::Seconds(30),
48  .parametersType = ParamType::ToAronType(),
49  };
50  }
51 
53  MoveJointsToNamedConfiguration::main(const SpecializedMainInput& in)
54  {
55  const VirtualRobot::RobotPtr robot =
56  remote.virtualRobotReader.getRobotWaiting(remote.robotName);
57  if (not robot)
58  {
59  ARMARX_ERROR << "Could not get robot '" << remote.robotName << "'";
60  return MakeFailedResult();
61  }
62 
63  const auto configuration = robot->getConfiguration(in.parameters.configuration);
64  if (not configuration)
65  {
66  ARMARX_ERROR << "Robot '" << remote.robotName << "' does not have configuration '"
67  << in.parameters.configuration << "'.";
68  return MakeFailedResult();
69  }
70 
71  // for every enabled robot part, the nodes of the corresponding RobotNodeSet are enabled
72  std::set<std::string> enabledJoints;
73  const auto addJoints = [&](const std::string& nodeSetName)
74  {
75  if (not robot->hasRobotNodeSet(nodeSetName))
76  {
77  ARMARX_ERROR << "Robot '" << remote.robotName << "' does not have a RobotNodeSet '"
78  << in.parameters.configuration << "'.";
79  }
80  else
81  {
82  const auto robotNodes = robot->getRobotNodeSet(nodeSetName)->getNodeNames();
83  enabledJoints.insert(robotNodes.cbegin(), robotNodes.cend());
84  }
85  };
86 
87  if (in.parameters.enableLeftArm)
88  {
89  addJoints("LeftArm");
90  }
91  if (in.parameters.enableRightArm)
92  {
93  addJoints("RightArm");
94  }
95  if (in.parameters.enableLeftHand)
96  {
97  addJoints("LeftHand");
98  }
99  if (in.parameters.enableRightHand)
100  {
101  addJoints("RightHand");
102  }
103  if (in.parameters.enableTorso)
104  {
105  addJoints("Torso");
106  }
107  if (in.parameters.enableHead)
108  {
109  addJoints("Head");
110  }
111 
112  auto moveJoints =
114  this->manager,
118  });
119  auto subParams = moveJoints.getRootProfileParameters();
120  copy_params(in.parameters, subParams);
121 
122  // apply configuration for all enabled joints
123  for (const auto& [node, value] : *configuration)
124  {
125  if (enabledJoints.count(node))
126  {
127  subParams.jointsTargetValues[node] = value;
128  }
129  }
130 
131  this->callSubskill(moveJoints, subParams.toAron());
132 
133  return MakeSucceededResult();
134  }
135 
136 } // namespace armarx::control::skills::skills
armarx::skills::Skill::manager
manager::dti::SkillManagerInterfacePrx manager
Definition: Skill.h:327
armarx::skills::SimpleSpecializedSkill< arondto::MoveJointsToNamedConfigurationParams >::ParamType
arondto::MoveJointsToNamedConfigurationParams ParamType
Definition: SimpleSpecializedSkill.h:14
SpecializedSkillProxy.h
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
param_conversions.h
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::control::skills::skills::MoveJointsToNamedConfiguration::Services::virtualRobotReader
::armarx::armem::robot_state::VirtualRobotReader virtualRobotReader
Definition: MoveJointsToNamedConfiguration.h:26
armarx::skills::SkillID::providerId
std::optional< ProviderID > providerId
Definition: SkillID.h:59
armarx::control::skills::constants::MOVE_JOINTS_TO_POSITION_SKILL_NAME
std::string MOVE_JOINTS_TO_POSITION_SKILL_NAME
Definition: constants.cpp:8
armarx::skills::SpecializedSkillProxy::getRootProfileParameters
AronT getRootProfileParameters()
Definition: SpecializedSkillProxy.h:30
armarx::skills::Skill::callSubskill
std::optional< TerminatedSkillStatusUpdate > callSubskill(const skills::SkillProxy &proxy)
Call a subskill with default parameters and block until the subskill terminates.
Definition: Skill.cpp:22
armarx::control::skills::skills::MoveJointsToNamedConfiguration::Services
Definition: MoveJointsToNamedConfiguration.h:24
armarx::control::skills::skills::copy_params
void copy_params(const arondto::MoveJointsParams &from, arondto::MoveJointsToPositionParams &to)
Definition: param_conversions.h:12
MoveJointsToNamedConfiguration.h
armarx::skills::Skill::MakeFailedResult
static MainResult MakeFailedResult()
Definition: Skill.cpp:324
constants.h
armarx::core::time::Duration::Seconds
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition: Duration.cpp:83
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::control::skills::skills::MoveJointsToNamedConfiguration::GetSkillDescription
::armarx::skills::SkillDescription GetSkillDescription()
Definition: MoveJointsToNamedConfiguration.cpp:24
armarx::skills::SpecializedSkillProxy
Definition: SpecializedSkillProxy.h:10
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::skills::Skill::MakeSucceededResult
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition: Skill.cpp:315
armarx::skills::Skill::MainResult
A result struct for th main method of a skill.
Definition: Skill.h:48
armarx::control::skills::skills::MoveJointsToNamedConfiguration::MoveJointsToNamedConfiguration
MoveJointsToNamedConfiguration(const Services &remote)
Definition: MoveJointsToNamedConfiguration.cpp:18
armarx::skills::SimpleSpecializedSkill< arondto::MoveJointsToNamedConfigurationParams >::main
Skill::MainResult main() final
Definition: SimpleSpecializedSkill.h:71
armarx::control::skills::constants::MOVE_JOINTS_TO_NAMED_CONFIGURATION_SKILL_NAME
std::string MOVE_JOINTS_TO_NAMED_CONFIGURATION_SKILL_NAME
Definition: constants.cpp:10
armarx::control::skills::skills
Definition: ExecuteTrajectory.cpp:18
armarx::control::skills::skills::MoveJointsToNamedConfiguration::Services::robotName
std::string robotName
Definition: MoveJointsToNamedConfiguration.h:27
Logging.h
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::skills::Skill::getSkillId
SkillID getSkillId() const
Get the id of the skill.
Definition: Skill.h:74
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18