MoveRelativePlanar.cpp
Go to the documentation of this file.
1 #include "MoveRelativePlanar.h"
2 
3 #include <SimoxUtility/math/convert/deg_to_rad.h>
4 
6 
8 {
9 
12  {
13  ParamType defaultParams;
14  defaultParams.translationCartesian = std::nullopt;
15  defaultParams.translationPolar = std::nullopt;
16  defaultParams.rotationRadians = std::nullopt;
17  defaultParams.rotationDegrees = std::nullopt;
18 
19  static const std::string nl = "\n\n";
20 
21  std::stringstream desc;
22  desc << "**Move the robot relatively to its current pose in the horizontal plane.**";
23 
24  desc << nl
25  << "The parameters `translationCartesian` and `translationPolar` specify the "
26  "translation of the robot. (If both are given, `translationCartesian` takes "
27  "precedence over `translationPolar`.)";
28 
29  desc << nl
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 "
34  "`agent` empty).";
35 
36  desc << nl
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.)";
43 
44  desc << nl
45  << "`rotationRadians` and `rotationDegrees` specify the rotation around the +z axis"
46  " (up). "
47  << nl
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.";
52 
55  .description = desc.str(),
56  .rootProfileDefaults = defaultParams.toAron(),
58  .parametersType = ParamType::ToAronType(),
59  };
60  }
61 
63  Base(
64  Base::Services{
66  .memoryNameSystem = srv.memoryNameSystem,
67  },
68  DefaultSkillDescription()),
69  properties{properties},
70  services{.robotReader = srv.robotReader}
71  {
72  }
73 
74  Eigen::Vector3f
75  makeTranslation(const arondto::FramedCartesian2D& cartesian,
77  const std::string& defaultRobotName)
78  {
79  Eigen::Vector3f translation;
80  translation << cartesian.translationCartesian.cast<float>(), 0;
81 
82  // Target translation must be given in root frame of robot.
83  if (cartesian.frameID.has_value())
84  {
85  armarx::arondto::FrameID frameID = cartesian.frameID.value();
86 
87  if (frameID.agent.empty())
88  {
89  // If frame == armarx::GlobalFrame, the agent is ignored, so we can set it anyway.
90  frameID.agent = defaultRobotName;
91  }
92 
93  VirtualRobot::RobotPtr robot = robotReader.getSynchronizedRobot(frameID.agent);
94 
95  if (frameID.frame.empty())
96  {
97  frameID.frame = robot->getRootNode()->getName();
98  }
99 
100  armarx::FramedDirection dir(translation, frameID.frame, frameID.agent);
101 
102  return dir.toRootFrame(robot)->toEigen();
103  }
104  else
105  {
106  // If not given, we fall back to the robot root frame => no transformation necessary.
107  return translation;
108  }
109  }
110 
111  Eigen::Vector3f
112  makeTranslation(const arondto::Polar& polar,
113  const Eigen::Vector3f forward,
114  const Eigen::Vector3f up)
115  {
116  const Eigen::AngleAxisf rotation(simox::math::deg_to_rad(polar.directionDegrees), up);
117  const Eigen::Vector3f translation = polar.distanceMillimeters * (rotation * forward);
118 
119  return translation;
120  }
121 
122  Eigen::AngleAxisf
123  makeRotation(float rotationRadians, const Eigen::Vector3f up)
124  {
125  return Eigen::AngleAxisf(rotationRadians, up);
126  }
127 
128  Eigen::Isometry3f
129  MoveRelativePlanar::relativeTarget(const Base::SpecializedMainInput& in)
130  {
131  // Note: In theory, it depends on the robot.
132  static const Eigen::Vector3f forward = Eigen::Vector3f::UnitY();
133  static const Eigen::Vector3f up = Eigen::Vector3f::UnitZ();
134 
135  const ParamType& parameters = in.parameters;
136 
137  Eigen::Isometry3f relativeTarget = Eigen::Isometry3f::Identity();
138 
139  // Translation.
140  if (parameters.translationCartesian.has_value())
141  {
142  relativeTarget.translation() = makeTranslation(parameters.translationCartesian.value(),
143  services.robotReader,
144  properties.robotName);
145  }
146  else if (parameters.translationPolar.has_value())
147  {
148  relativeTarget.translation() =
149  makeTranslation(parameters.translationPolar.value(), forward, up);
150  }
151 
152  // Rotation.
153  std::optional<float> rotationRadians = parameters.rotationRadians;
154  if (not rotationRadians.has_value() and parameters.rotationDegrees.has_value())
155  {
156  rotationRadians = simox::math::deg_to_rad(parameters.rotationDegrees.value());
157  }
158  if (rotationRadians.has_value())
159  {
160  relativeTarget.linear() =
161  relativeTarget.linear() * makeRotation(rotationRadians.value(), up);
162  }
163 
164  return relativeTarget;
165  }
166 
167 } // namespace armarx::navigation::skills
constants.h
armarx::armem::robot_state::VirtualRobotReader
The VirtualRobotReader class.
Definition: VirtualRobotReader.h:40
armarx::navigation::skills::MoveRelativePlanar::DefaultSkillDescription
static armarx::skills::SkillDescription DefaultSkillDescription()
Definition: MoveRelativePlanar.cpp:11
armarx::navigation::skills::MoveRelativePlanar::Properties::robotName
std::string robotName
Definition: MoveRelativePlanar.h:26
armarx::navigation::skills::constants::skill_names::MoveRelativePlanar
const std::string MoveRelativePlanar
Definition: constants.h:36
armarx::navigation::skills::MoveRelativePlanar::Services::iceNavigator
client::IceNavigator & iceNavigator
Definition: MoveRelativePlanar.h:19
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::navigation::skills::NavigateRelativeSkill< arondto::MoveRelativePlanarParams >
armarx::FramedDirection::toRootFrame
FramedDirectionPtr toRootFrame(const SharedRobotInterfacePrx &referenceRobot) const
Definition: FramedPose.cpp:231
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::navigation::skills::MoveRelativePlanar::Properties
Definition: MoveRelativePlanar.h:24
armarx::navigation::skills::makeRotation
Eigen::AngleAxisf makeRotation(float rotationRadians, const Eigen::Vector3f up)
Definition: MoveRelativePlanar.cpp:123
armarx::skills::SkillDescription::skillId
SkillID skillId
Definition: SkillDescription.h:20
armarx::core::time::Duration::Minutes
static Duration Minutes(std::int64_t minutes)
Constructs a duration in minutes.
Definition: Duration.cpp:111
armarx::armem::robot_state::VirtualRobotReader::getSynchronizedRobot
VirtualRobot::RobotPtr getSynchronizedRobot(const std::string &name, const VirtualRobot::RobotIO::RobotDescription &loadMode=VirtualRobot::RobotIO::RobotDescription::eStructure, bool blocking=true)
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:83
MoveRelativePlanar.h
armarx::navigation::skills::MoveRelativePlanar::Services
Definition: MoveRelativePlanar.h:17
armarx::navigation::skills::MoveRelativePlanar::Services::memoryNameSystem
armem::client::MemoryNameSystem & memoryNameSystem
Definition: MoveRelativePlanar.h:20
armarx::navigation::skills::makeTranslation
Eigen::Vector3f makeTranslation(const arondto::FramedCartesian2D &cartesian, armem::robot_state::VirtualRobotReader &robotReader, const std::string &defaultRobotName)
Definition: MoveRelativePlanar.cpp:75
armarx::navigation::skills
Definition: constants.cpp:25
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
armarx::navigation::skills::MoveRelativePlanar::MoveRelativePlanar
MoveRelativePlanar(const Properties &properties, const Services &srv)
Definition: MoveRelativePlanar.cpp:62