7 #include <SimoxUtility/math/convert/deg_to_rad.h>
8 #include <VirtualRobot/VirtualRobot.h>
16 #include <RobotAPI/libraries/aron/common/aron/framed.aron.generated.h>
20 #include <armarx/navigation/skills/aron/MoveRelativePlanar.aron.generated.h>
29 ParamType defaultParams;
30 defaultParams.translationCartesian = std::nullopt;
31 defaultParams.translationPolar = std::nullopt;
32 defaultParams.rotationRadians = std::nullopt;
33 defaultParams.rotationDegrees = std::nullopt;
35 static const std::string nl =
"\n\n";
37 std::stringstream desc;
38 desc <<
"**Move the robot relatively to its current pose in the horizontal plane.**";
41 <<
"The parameters `translationCartesian` and `translationPolar` specify the "
42 "translation of the robot. (If both are given, `translationCartesian` takes "
43 "precedence over `translationPolar`.)";
46 <<
"`translationCartesian` specifies the relative translation in Cartesian"
47 " coordinates (x, y). The corresponding coordinate system is specified by its "
48 "`frameID`. If `frameID` is not given, the robot's root coordinate system is used."
49 "To define a translation in the global frame, set `frame` to `Global` (and leave "
53 <<
"`translationPolar` specifies the relative translation in polar coordinates"
54 " (direction, distance), where"
55 << nl <<
"- `direction = 0` moves the robot forward," << nl
56 <<
"- `direction > 0` moves the robot to the left," << nl
57 <<
"- `direction < 0` moves the robot to the right." << nl
58 <<
" (Generally, `forward` is defined as the +y axis of the robot root frame.)";
61 <<
"`rotationRadians` and `rotationDegrees` specify the rotation around the +z axis"
64 <<
"(If both are given, `rotationRadians` takes precedence over `rotationDegrees`.)"
65 << nl <<
"- `directionDegrees = 0` does not turn the robot," << nl
66 <<
"- `directionDegrees > 0` turns the robot to the left," << nl
67 <<
"- `directionDegrees < 0` turns the robot to the right.";
71 .description = desc.str(),
72 .rootProfileDefaults = defaultParams.toAron(),
74 .parametersType = ParamType::ToAronType(),
84 DefaultSkillDescription()),
85 properties{properties},
86 services{.robotReader = srv.robotReader}
93 const std::string& defaultRobotName)
95 Eigen::Vector3f translation;
96 translation << cartesian.translationCartesian.cast<
float>(), 0;
99 if (cartesian.frameID.has_value())
101 armarx::arondto::FrameID frameID = cartesian.frameID.value();
103 if (frameID.agent.empty())
106 frameID.agent = defaultRobotName;
111 <<
"Robot " <<
QUOTED(frameID.agent) <<
" not found in robot reader";
114 <<
"Failed to synchronize robot " <<
QUOTED(frameID.agent);
116 if (frameID.frame.empty())
118 frameID.frame = robot->getRootNode()->getName();
134 const Eigen::Vector3f forward,
135 const Eigen::Vector3f
up)
137 const Eigen::AngleAxisf rotation(simox::math::deg_to_rad(polar.directionDegrees),
up);
138 const Eigen::Vector3f translation = polar.distanceMillimeters * (rotation * forward);
146 return Eigen::AngleAxisf(rotationRadians,
up);
150 MoveRelativePlanar::relativeTarget(
const Base::SpecializedMainInput& in)
153 static const Eigen::Vector3f forward = Eigen::Vector3f::UnitY();
154 static const Eigen::Vector3f
up = Eigen::Vector3f::UnitZ();
156 const ParamType& parameters = in.parameters;
161 if (parameters.translationCartesian.has_value())
163 relativeTarget.translation() =
makeTranslation(parameters.translationCartesian.value(),
164 services.robotReader,
167 else if (parameters.translationPolar.has_value())
169 relativeTarget.translation() =
174 std::optional<float> rotationRadians = parameters.rotationRadians;
175 if (not rotationRadians.has_value() and parameters.rotationDegrees.has_value())
177 rotationRadians = simox::math::deg_to_rad(parameters.rotationDegrees.value());
179 if (rotationRadians.has_value())
181 relativeTarget.linear() =
182 relativeTarget.linear() *
makeRotation(rotationRadians.value(),
up);
185 return relativeTarget;