MoveJointsToNamedConfiguration.cpp
Go to the documentation of this file.
2
3#include <set>
4
5#include <VirtualRobot/RobotNodeSet.h>
6
8
11
12#include <armarx/control/skills/aron/MoveJointsToPositionParams.aron.generated.h>
15
17{
18
20 SimpleSpecializedSkill(GetSkillDescription()), remote(remote)
21 {
22 }
23
26 {
27 ParamType defaultParams;
28 // - arms
29 defaultParams.enableLeftArm = true;
30 defaultParams.enableRightArm = true;
31 // - hands
32 defaultParams.enableLeftHand = false;
33 defaultParams.enableRightHand = false;
34 // - torso
35 defaultParams.enableTorso = true;
36 // - head (-> should be controlled by GazeController)
37 defaultParams.enableHead = false;
38
39 std::stringstream desc;
40 desc << "Move all joints to a named configuration of the robot model."
41 << "\n\n"
42 << "The `enable*` parameters can be used to enable/disable movement for different "
43 "body parts of the robot.";
44
47 .description = desc.str(),
48 .rootProfileDefaults = defaultParams.toAron(),
49 .timeout = ::armarx::Duration::Seconds(30),
50 .parametersType = ParamType::ToAronType(),
51 };
52 }
53
55 MoveJointsToNamedConfiguration::main(const SpecializedMainInput& in)
56 {
57 const VirtualRobot::RobotPtr robot =
59 if (not robot)
60 {
61 ARMARX_ERROR << "Could not get robot '" << remote.robotName << "'";
62 return MakeFailedResult();
63 }
64
65 const auto configuration = robot->getConfiguration(in.parameters.configuration);
66 if (not configuration)
67 {
68 ARMARX_ERROR << "Robot '" << remote.robotName << "' does not have configuration '"
69 << in.parameters.configuration << "'.";
70 return MakeFailedResult();
71 }
72
73 // for every enabled robot part, the nodes of the corresponding RobotNodeSet are enabled
74 std::set<std::string> enabledJoints;
75 const auto addJoints = [&](const std::string& nodeSetName)
76 {
77 if (not robot->hasRobotNodeSet(nodeSetName))
78 {
79 ARMARX_ERROR << "Robot '" << remote.robotName << "' does not have a RobotNodeSet '"
80 << in.parameters.configuration << "'.";
81 }
82 else
83 {
84 const auto robotNodes = robot->getRobotNodeSet(nodeSetName)->getNodeNames();
85 enabledJoints.insert(robotNodes.cbegin(), robotNodes.cend());
86 }
87 };
88
89 if (in.parameters.enableLeftArm)
90 {
91 addJoints("LeftArm");
92 }
93 if (in.parameters.enableRightArm)
94 {
95 addJoints("RightArm");
96 }
97 if (in.parameters.enableLeftHand)
98 {
99 addJoints("LeftHand");
100 }
101 if (in.parameters.enableRightHand)
102 {
103 addJoints("RightHand");
104 }
105 if (in.parameters.enableTorso)
106 {
107 addJoints("Torso");
108 }
109 if (in.parameters.enableHead)
110 {
111 addJoints("Head");
112 }
113
114
115 {
116 ::armarx::skills::SkillID skillId{
117 .providerId = getSkillId().providerId,
119 };
120
121 using Parameters = arondto::MoveJointsToPositionParams;
122
123 auto status =
125 [&](Parameters& params)
126 {
127 copy_params(in.parameters, params);
128
129 // apply configuration for all enabled joints
130 for (const auto& [node, value] : *configuration)
131 {
132 if (enabledJoints.count(node))
133 {
134 params.jointsTargetValues[node] = value;
135 }
136 }
137 });
138
140 {
141 return MakeFailedResult();
142 }
143
144 return MakeSucceededResult();
145 }
146 }
147
148} // namespace armarx::control::skills::skills
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
VirtualRobot::RobotPtr getRobotWaiting(const std::string &name, const armem::Time &timestamp=armem::Time::Invalid(), const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure)
In contrast to getRobot(), this function will retry to query the robot until it exists.
std::optional< ProviderID > providerId
Definition SkillID.h:40
std::optional< TerminatedSkillStatusUpdate > callSubskill(const SkillID &skillId)
Call a subskill with the given ID and its default parameters.
Definition Skill.cpp:119
static MainResult MakeSucceededResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:413
virtual MainResult main()
Override this method with the actual implementation.
Definition Skill.cpp:542
SkillID getSkillId() const
Get the id of the skill.
Definition Skill.cpp:587
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:422
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
std::string MOVE_JOINTS_TO_NAMED_CONFIGURATION_SKILL_NAME
Definition constants.cpp:10
std::string MOVE_JOINTS_TO_POSITION_SKILL_NAME
Definition constants.cpp:8
void copy_params(const arondto::MoveJointsParams &from, arondto::MoveJointsToPositionParams &to)
aron::data::DictPtr Parameters
bool skillExecutionFailed(const std::optional< armarx::skills::TerminatedSkillStatusUpdate > &update)
std::shared_ptr< Value > value()
Definition cxxopts.hpp:855
A result struct for th main method of a skill.
Definition Skill.h:62