3 #include <SimoxUtility/math/convert/deg_to_rad.h>
13 ParamType defaultParams;
14 defaultParams.translationCartesian = std::nullopt;
15 defaultParams.translationPolar = std::nullopt;
16 defaultParams.rotationRadians = std::nullopt;
17 defaultParams.rotationDegrees = std::nullopt;
19 static const std::string nl =
"\n\n";
21 std::stringstream desc;
22 desc <<
"**Move the robot relatively to its current pose in the horizontal plane.**";
25 <<
"The parameters `translationCartesian` and `translationPolar` specify the "
26 "translation of the robot. (If both are given, `translationCartesian` takes "
27 "precedence over `translationPolar`.)";
30 <<
"`translationCartesian` specifies the relative translation in Cartesian"
31 " coordinates (x, y). The corresponding coordinate system is specified by its "
32 "`frameID`. If `frameID` is not given, the robot's root coordinate system is used."
33 "To define a translation in the global frame, set `frame` to `Global` (and leave "
37 <<
"`translationPolar` specifies the relative translation in polar coordinates"
38 " (direction, distance), where"
39 << nl <<
"- `direction = 0` moves the robot forward," << nl
40 <<
"- `direction > 0` moves the robot to the left," << nl
41 <<
"- `direction < 0` moves the robot to the right." << nl
42 <<
" (Generally, `forward` is defined as the +y axis of the robot root frame.)";
45 <<
"`rotationRadians` and `rotationDegrees` specify the rotation around the +z axis"
48 <<
"(If both are given, `rotationRadians` takes precedence over `rotationDegrees`.)"
49 << nl <<
"- `directionDegrees = 0` does not turn the robot," << nl
50 <<
"- `directionDegrees > 0` turns the robot to the left," << nl
51 <<
"- `directionDegrees < 0` turns the robot to the right.";
55 .description = desc.str(),
56 .rootProfileDefaults = defaultParams.toAron(),
58 .parametersType = ParamType::ToAronType(),
68 DefaultSkillDescription()),
69 properties{properties},
70 services{.robotReader = srv.robotReader}
77 const std::string& defaultRobotName)
79 Eigen::Vector3f translation;
80 translation << cartesian.translationCartesian.cast<
float>(), 0;
83 if (cartesian.frameID.has_value())
85 armarx::arondto::FrameID frameID = cartesian.frameID.value();
87 if (frameID.agent.empty())
90 frameID.agent = defaultRobotName;
95 if (frameID.frame.empty())
97 frameID.frame = robot->getRootNode()->getName();
113 const Eigen::Vector3f forward,
114 const Eigen::Vector3f up)
116 const Eigen::AngleAxisf rotation(simox::math::deg_to_rad(polar.directionDegrees), up);
117 const Eigen::Vector3f translation = polar.distanceMillimeters * (rotation * forward);
125 return Eigen::AngleAxisf(rotationRadians, up);
129 MoveRelativePlanar::relativeTarget(
const Base::SpecializedMainInput& in)
132 static const Eigen::Vector3f forward = Eigen::Vector3f::UnitY();
133 static const Eigen::Vector3f up = Eigen::Vector3f::UnitZ();
135 const ParamType& parameters = in.parameters;
140 if (parameters.translationCartesian.has_value())
142 relativeTarget.translation() =
makeTranslation(parameters.translationCartesian.value(),
143 services.robotReader,
146 else if (parameters.translationPolar.has_value())
148 relativeTarget.translation() =
153 std::optional<float> rotationRadians = parameters.rotationRadians;
154 if (not rotationRadians.has_value() and parameters.rotationDegrees.has_value())
156 rotationRadians = simox::math::deg_to_rad(parameters.rotationDegrees.value());
158 if (rotationRadians.has_value())
160 relativeTarget.linear() =
161 relativeTarget.linear() *
makeRotation(rotationRadians.value(), up);
164 return relativeTarget;