HomePose.cpp
Go to the documentation of this file.
1#include "HomePose.h"
2
3#include <sstream>
4#include <string>
5#include <vector>
6
9
18
19#include <armarx/control/skills/aron/HandParam.aron.generated.h>
20#include <armarx/control/skills/aron/MoveJointsToNamedConfigurationParams.aron.generated.h>
21#include <armarx/control/skills/aron/NamedConfigurationParams.aron.generated.h>
22#include <armarx/control/skills/aron/ShapeHandParams.aron.generated.h>
25
27{
28
29 HomePose::HomePose(const std::string& homePoseConfiguration) :
30 SimpleSpecializedSkill(GetSkillDescription()), homePoseConfiguration_(homePoseConfiguration)
31 {
32 }
33
36 {
37 ParamType defaultParams;
38
39 defaultParams.disabledJoints = {"LeftHandFingers",
40 "RightHandFingers",
41 "LeftHandIndex",
42 "RightHandIndex",
43 "LeftHandThumbCircumduction",
44 "RightHandThumbCircumduction",
45 "LeftHandThumbFlexion",
46 "RightHandThumbFlexion"};
47
48 std::stringstream desc;
49 desc << "Move all joints to a natural idle position that also allows "
50 "safe movement and safe bus crashes."
51 << "\n\n"
52 << "The `enable*` parameters can be used to enable/disable movement for different "
53 "body parts of the robot.";
54
56 .skillId = {.skillName = constants::HOME_POSE_SKILL_NAME},
57 .description = desc.str(),
58 .rootProfileDefaults = defaultParams.toAron(),
59 .timeout = ::armarx::Duration::Seconds(30),
60 .parametersType = ParamType::ToAronType(),
61 };
62 }
63
65 HomePose::main(const SpecializedMainInput& in)
66 {
67 const ::armarx::skills::SkillID moveToConfigurationSkillId{
68 .providerId = getSkillId().providerId,
70 };
71
72 const ::armarx::skills::SkillID openHandSkillId{
73 .providerId = getSkillId().providerId,
75 };
76 std::unique_ptr<armarx::skills::SkillExecutionHandle> handleLeftHand;
77 if (in.parameters.enableLeftHand)
78 {
79 handleLeftHand = [&]
80 {
81 using Parameters = arondto::ShapeHandParams;
82
84 openHandSkillId,
85 [](Parameters& params)
86 {
87 params.shapeName = "Open";
88 params.hand = armarx::control::skills::arondto::Hand::Left;
89 });
90 }();
91 }
92
93 std::unique_ptr<armarx::skills::SkillExecutionHandle> handleRightHand;
94 if (in.parameters.enableRightHand)
95 {
96 handleRightHand = [&]
97 {
98 using Parameters = arondto::ShapeHandParams;
99
101 openHandSkillId,
102 [](Parameters& params)
103 {
104 params.shapeName = "Open";
105 params.hand = armarx::control::skills::arondto::Hand::Right;
106 });
107 }();
108 }
109
110 const auto handleHomePose = [&]
111 {
112 using Parameters =
113 armarx::control::skills::arondto::MoveJointsToNamedConfigurationParams;
114
116 moveToConfigurationSkillId,
117 [&](Parameters& subParams)
118 {
119 subParams.configuration = homePoseConfiguration_;
120
121 subParams.enableHead =
122 true; // should be via gaze controller, but due to dependency chain, this skill would have to be moved
123 subParams.enableLeftHand = false; // via hand unit
124 subParams.enableRightHand = false; // via hand unit
125
126 copy_params(in.parameters, subParams);
127 });
128 }();
129
130 ARMARX_INFO << "Waiting for subskills to join";
131
132 armarx::skills::util::JoinAllResult result;
133 if (in.parameters.enableLeftHand and in.parameters.enableRightHand)
134 {
135 result =
136 armarx::skills::util::joinAllAny(handleLeftHand, handleRightHand, handleHomePose);
137 }
138 if (in.parameters.enableLeftHand)
139 {
140 result = armarx::skills::util::joinAllAny(handleLeftHand, handleHomePose);
141 }
142 else if (in.parameters.enableRightHand)
143 {
144 result = armarx::skills::util::joinAllAny(handleRightHand, handleHomePose);
145 }
146 else
147 {
148 result = armarx::skills::util::joinAllAny(handleHomePose);
149 }
150 ARMARX_INFO << "All subskills have been joined.";
151
152 if (not result)
153 {
154 ARMARX_WARNING << "The skills " << result.failedSkillIDs() << " failed";
155 return MakeFailedResult();
156 }
157
158
159 return MakeSucceededResult();
160 }
161
162
163} // namespace armarx::control::skills::skills::meta
static Duration Seconds(std::int64_t seconds)
Constructs a duration in seconds.
Definition Duration.cpp:72
::armarx::skills::SkillDescription GetSkillDescription()
Definition HomePose.cpp:35
HomePose(const std::string &homePoseConfiguration="Home")
Definition HomePose.cpp:29
std::optional< ProviderID > providerId
Definition SkillID.h:40
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
SkillExecutionHandlePtr callSubskillAsync(const SkillID &skillId, std::function< void(aron::data::DictPtr &)> parametersFunction)
Definition Skill.cpp:148
static MainResult MakeFailedResult(aron::data::DictPtr data=nullptr)
Definition Skill.cpp:422
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
std::string MOVE_JOINTS_TO_NAMED_CONFIGURATION_SKILL_NAME
Definition constants.cpp:10
void copy_params(const arondto::MoveJointsParams &from, arondto::MoveJointsToPositionParams &to)
aron::data::DictPtr Parameters
JoinAllResult joinAllAny(Args &&... args)
A result struct for th main method of a skill.
Definition Skill.h:62