Robowflex  v0.1
Making MoveIt Easy
tf.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston, Constantinos Chamzas */
2 
3 #ifndef ROBOWFLEX_TF_
4 #define ROBOWFLEX_TF_
5 
6 #include <Eigen/Core>
7 #include <Eigen/Geometry>
8 
9 #include <geometry_msgs/Pose.h>
10 #include <geometry_msgs/Quaternion.h>
11 #include <geometry_msgs/Vector3.h>
12 #include <geometry_msgs/TransformStamped.h>
13 
14 #include <moveit_msgs/BoundingVolume.h>
15 #include <moveit_msgs/PositionConstraint.h>
16 #include <moveit_msgs/OrientationConstraint.h>
17 
21 
22 namespace robowflex
23 {
24  /** \cond IGNORE */
25  ROBOWFLEX_CLASS_FORWARD(Geometry);
26  /* \endcond */
27 
28  /** \brief Collection of methods relating to transforms and transform math.
29  */
30  namespace TF
31  {
32  /** \brief Creates the Identity pose.
33  * \return A new identity robot pose.
34  */
36 
37  /** \brief Creates a robot pose from a linear component and zero orientation.
38  * \param[in] x X-axis translation.
39  * \param[in] y Y-ayis translation.
40  * \param[in] z Z-azis translation.
41  * \return A new robot pose from components.
42  */
43  RobotPose createPoseXYZ(double x, double y, double z);
44 
45  /** \brief Creates a robot pose from a linear component and zero orientation.
46  * \param[in] translation Translation component.
47  * \return A new robot pose from components.
48  */
49  RobotPose createPoseXYZ(const Eigen::Ref<const Eigen::Vector3d> &translation);
50 
51  /** \brief Creates a robot pose from a linear component and XYZ convention Euler angles
52  * \param[in] x X-axis translation.
53  * \param[in] y Y-ayis translation.
54  * \param[in] z Z-azis translation.
55  * \param[in] X Rotation about X.
56  * \param[in] Y Rotation about Y.
57  * \param[in] Z Rotation about Z.
58  * \return A new robot pose from components.
59  */
60  RobotPose createPoseXYZ(double x, double y, double z, double X, double Y, double Z);
61 
62  /** \brief Creates a robot pose from a linear component and XYZ convention Euler angles
63  * \param[in] translation Translation component.
64  * \param[in] rotation Rotational component (X, Y, Z angles).
65  * \return A new robot pose from components.
66  */
67  RobotPose createPoseXYZ(const Eigen::Ref<const Eigen::Vector3d> &translation,
68  const Eigen::Ref<const Eigen::Vector3d> &rotation);
69 
70  /** \brief Creates a robot pose from a linear component and a Quaternion
71  * \param[in] x X-axis translation.
72  * \param[in] y Y-axis translation.
73  * \param[in] z Z-axis translation.
74  * \param[in] W Real quaternion component.
75  * \param[in] X i quaternion component.
76  * \param[in] Y j quaternion component.
77  * \param[in] Z k quaternion component.
78  * \return A new robot pose from components.
79  */
80  RobotPose createPoseQ(double x, double y, double z, double W, double X, double Y, double Z);
81 
82  /** \brief Creates a robot pose from a linear component and a quaternion.
83  * \param[in] translation translation component.
84  * \param[in] rotation rotational component (W, X, Y, Z quaternion values).
85  * \return A new robot pose from components.
86  */
87  RobotPose createPoseQ(const Eigen::Ref<const Eigen::Vector3d> &translation,
88  const Eigen::Ref<const Eigen::Vector4d> &rotation);
89 
90  /** \brief Creates a robot pose from a linear component and a quaternion.
91  * \param[in] translation translation component.
92  * \param[in] rotation rotational component.
93  * \return A new robot pose from components.
94  */
95  RobotPose createPoseQ(const Eigen::Ref<const Eigen::Vector3d> &translation,
96  const Eigen::Quaterniond &rotation);
97 
98  /** \brief Get the rotational component of a robot pose.
99  * \param[in] pose The pose to get the rotation from.
100  * \return The rotational component of the pose.
101  */
102  Eigen::Quaterniond getPoseRotation(const RobotPose &pose);
103 
104  /** \brief Converts a point message to an Eigen::Vector3d.
105  * \param[in] msg Message to convert.
106  * \return \a msg as an Eigen::Vector3d.
107  */
108  Eigen::Vector3d pointMsgToEigen(const geometry_msgs::Point &msg);
109 
110  /** \brief Converts an Eigen::Vector3d to a point message.
111  * \param[in] vector Vector to convert.
112  * \return \a vector as a point message.
113  */
114  geometry_msgs::Point pointEigenToMsg(const Eigen::Vector3d &vector);
115 
116  /** \brief Converts a vector message to an Eigen::Vector3d.
117  * \param[in] msg Message to convert.
118  * \return \a msg as an Eigen::Vector3d.
119  */
120  Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg);
121 
122  /** \brief Converts an Eigen::Vector3d to a vector message.
123  * \param[in] vector Vector to convert.
124  * \return \a vector as a vector message.
125  */
126  geometry_msgs::Vector3 vectorEigenToMsg(const Eigen::Vector3d &vector);
127 
128  /** \brief Converts a pose message to RobotPose.
129  * \param[in] msg Message to convert.
130  * \return \a msg an RobotPose.
131  */
132  RobotPose poseMsgToEigen(const geometry_msgs::Pose &msg);
133 
134  /** \brief Converts an RobotPose to a pose message.
135  * \param[in] pose Pose to convert.
136  * \return \a pose as a pose message.
137  */
138  geometry_msgs::Pose poseEigenToMsg(const RobotPose &pose);
139 
140  /** \brief Converts a quaternion message to Eigen::Quaterniond.
141  * \param[in] msg Message to convert.
142  * \return \a msg an Eigen::Quaterniond.
143  */
144  Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg);
145 
146  /** \brief Converts an Eigen::Quaterniond to a quaternion message.
147  * \param[in] quaternion Quaternion to convert.
148  * \return \a quaternion as a quaternion message.
149  */
150  geometry_msgs::Quaternion quaternionEigenToMsg(const Eigen::Quaterniond &quaternion);
151 
152  /** \brief Get a bounding volume message for given \a geometry at a \a pose.
153  * \param[in] pose Pose to place geometry at.
154  * \param[in] geometry Geometry to get bounding volume for.
155  * \return Bounding volume message for \a geometry at \a pose.
156  */
157  moveit_msgs::BoundingVolume getBoundingVolume(const RobotPose &pose,
158  const GeometryConstPtr &geometry);
159 
160  /** \brief Get a position constraint message.
161  * \param[in] ee_name The name of the end-effector link.
162  * \param[in] base_name The frame of pose and orientation.
163  * \param[in] pose The pose of \a geometry in \a base_frame.
164  * \param[in] geometry The geometry describing the position constraint.
165  * \return The position constraint as a MoveIt messsage.
166  */
167  moveit_msgs::PositionConstraint getPositionConstraint(const std::string &ee_name,
168  const std::string &base_name,
169  const RobotPose &pose,
170  const GeometryConstPtr &geometry);
171 
172  Eigen::Vector3d samplePositionConstraint(const moveit_msgs::PositionConstraint &pc);
173 
174  /** \brief Get an orientation constraint message.
175  * \param[in] ee_name The name of the end-effector link.
176  * \param[in] base_name The frame of pose and orientation.
177  * \param[in] orientation The desired orientation.
178  * \param[in] tolerances XYZ Euler angle tolerances about orientation.
179  * \return The orientation constraint as a MoveIt message.
180  */
181  moveit_msgs::OrientationConstraint getOrientationConstraint(const std::string &ee_name,
182  const std::string &base_name,
183  const Eigen::Quaterniond &orientation,
184  const Eigen::Vector3d &tolerances);
185 
186  /** \brief Sample an orientation from a given \a orientation with XYZ Euler angle \a tolerances.
187  * \param[in] orientation The desired mean orientation.
188  * \param[in] tolerances XYZ Euler angle tolerances about orientation.
189  * \return The sampled orientation.
190  */
191  Eigen::Quaterniond sampleOrientation(const Eigen::Quaterniond &orientation,
192  const Eigen::Vector3d &tolerances);
193 
194  /** \brief Sample an orientation within the XYZ Euler angle \a tolerances.
195  * \param[in] tolerances XYZ Euler angle tolerances about orientation.
196  * \return The sampled orientation.
197  */
198  Eigen::Quaterniond sampleOrientationUniform(const Eigen::Vector3d &tolerances);
199 
200  /** \brief Offset an orientation by a rotation about an axis.
201  * \param[in] orientation Orientation to offset.
202  * \param[in] axis Axis to offset orientation about.
203  * \param[in] value Value by which to offset.
204  * \return The new orientation.
205  */
206  Eigen::Quaterniond offsetOrientation(const Eigen::Quaterniond &orientation,
207  const Eigen::Vector3d &axis, double value);
208 
209  /** \brief Sample a position within the given \a bounds using a uniform distribution.
210  * \param[in] bounds The desired mean orientation.
211  * \return The sampled position.
212  */
213  Eigen::Vector3d samplePositionUniform(const Eigen::Vector3d &bounds);
214 
215  /** \brief Sample a position from a gaussian distribution with mean zero and given standard deviation
216  * \param[in] stddev The desired standard deviation for the position.
217  * \return The sampled position.
218  */
219  Eigen::Vector3d samplePositionGaussian(const Eigen::Vector3d &stddev);
220 
221  /** \brief Sample a pose within the given position, orientation bounds.
222  * \param[in] pos_bounds The desired position bounds.
223  * \param[in] orn_bounds The desired orientation bounds.
224  * \return The sampled pose.
225  */
226  RobotPose samplePoseUniform(const Eigen::Vector3d &pos_bounds, const Eigen::Vector3d &orn_bounds);
227 
228  /** \brief Sample a pose with gaussian sampling for the position with given standard deviations and
229  * uniform sampling for the orientation within the given bounds.
230  * \param[in] pos_stddev The desired position standard deviations.
231  * \param[in] orn_bounds The desired orientation bounds.
232  * \return The sampled pose.
233  */
234  RobotPose samplePoseGaussian(const Eigen::Vector3d &pos_stddev, const Eigen::Vector3d &orn_bounds);
235 
236  /** \brief Decode a message as a transform.
237  * \param[in] tf Transform message.
238  * \return The transform.
239  */
240  RobotPose transformMsgToEigen(const geometry_msgs::TransformStamped &tf);
241 
242  /** \brief Encode a transform as a message.
243  * \param[in] source Source frame.
244  * \param[in] target Target frame.
245  * \param[in] tf Transform between frames.
246  * \return Transform message.
247  */
248  geometry_msgs::TransformStamped transformEigenToMsg(const std::string &source,
249  const std::string &target, const RobotPose &tf);
250 
251  /** \brief Normalize an angle between -pi to pi.
252  * \param[in] v The angle.
253  * \return The normalized angle.
254  */
255  double angleNormalize(double v);
256 
257  /** \brief Convert an angle to degrees.
258  * \param[in] v The angle in radians.
259  * \return The angle in degrees.
260  */
261  double toDegrees(double v);
262 
263  /** \brief Convert an angle to radians.
264  * \param[in] v The angle in degrees.
265  * \return The angle in radians.
266  */
267  double toRadians(double v);
268 
269  /** \brief Checks if a vector is close to zero.
270  * \param[in] v Vector to check.
271  * \param[in] tolerance Tolerance of what is considered zero.
272  * \return Whether the vector's norm is below the tolerance threshold.
273  */
274  bool isVecZero(const Eigen::Ref<const Eigen::VectorXd> &v, double tolerance = constants::eps);
275 
276  } // namespace TF
277 } // namespace robowflex
278 
279 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
A const shared pointer wrapper for robowflex::Geometry.
moveit_msgs::OrientationConstraint getOrientationConstraint(const std::string &ee_name, const std::string &base_name, const Eigen::Quaterniond &orientation, const Eigen::Vector3d &tolerances)
Get an orientation constraint message.
Definition: tf.cpp:189
geometry_msgs::Vector3 vectorEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a vector message.
Definition: tf.cpp:104
Eigen::Vector3d vectorMsgToEigen(const geometry_msgs::Vector3 &msg)
Converts a vector message to an Eigen::Vector3d.
Definition: tf.cpp:94
double toDegrees(double v)
Convert an angle to degrees.
Definition: tf.cpp:298
geometry_msgs::TransformStamped transformEigenToMsg(const std::string &source, const std::string &target, const RobotPose &tf)
Encode a transform as a message.
Definition: tf.cpp:262
Eigen::Vector3d samplePositionConstraint(const moveit_msgs::PositionConstraint &pc)
RobotPose poseMsgToEigen(const geometry_msgs::Pose &msg)
Converts a pose message to RobotPose.
Definition: tf.cpp:114
RobotPose createPoseQ(double x, double y, double z, double W, double X, double Y, double Z)
Creates a robot pose from a linear component and a Quaternion.
Definition: tf.cpp:47
double toRadians(double v)
Convert an angle to radians.
Definition: tf.cpp:308
RobotPose createPoseXYZ(double x, double y, double z)
Creates a robot pose from a linear component and zero orientation.
Definition: tf.cpp:14
Eigen::Vector3d samplePositionGaussian(const Eigen::Vector3d &stddev)
Sample a position from a gaussian distribution with mean zero and given standard deviation.
Definition: tf.cpp:239
Eigen::Quaterniond sampleOrientation(const Eigen::Quaterniond &orientation, const Eigen::Vector3d &tolerances)
Sample an orientation from a given orientation with XYZ Euler angle tolerances.
Definition: tf.cpp:207
Eigen::Vector3d pointMsgToEigen(const geometry_msgs::Point &msg)
Converts a point message to an Eigen::Vector3d.
Definition: tf.cpp:74
geometry_msgs::Pose poseEigenToMsg(const RobotPose &pose)
Converts an RobotPose to a pose message.
Definition: tf.cpp:120
RobotPose samplePoseUniform(const Eigen::Vector3d &pos_bounds, const Eigen::Vector3d &orn_bounds)
Sample a pose within the given position, orientation bounds.
Definition: tf.cpp:244
double angleNormalize(double v)
Normalize an angle between -pi to pi.
Definition: tf.cpp:293
Eigen::Vector3d samplePositionUniform(const Eigen::Vector3d &bounds)
Sample a position within the given bounds using a uniform distribution.
Definition: tf.cpp:234
Eigen::Quaterniond quaternionMsgToEigen(const geometry_msgs::Quaternion &msg)
Converts a quaternion message to Eigen::Quaterniond.
Definition: tf.cpp:135
geometry_msgs::Point pointEigenToMsg(const Eigen::Vector3d &vector)
Converts an Eigen::Vector3d to a point message.
Definition: tf.cpp:84
Eigen::Quaterniond offsetOrientation(const Eigen::Quaterniond &orientation, const Eigen::Vector3d &axis, double value)
Offset an orientation by a rotation about an axis.
Definition: tf.cpp:228
moveit_msgs::BoundingVolume getBoundingVolume(const RobotPose &pose, const GeometryConstPtr &geometry)
Get a bounding volume message for given geometry at a pose.
Definition: tf.cpp:151
Eigen::Quaterniond sampleOrientationUniform(const Eigen::Vector3d &tolerances)
Sample an orientation within the XYZ Euler angle tolerances.
Definition: tf.cpp:218
RobotPose identity()
Creates the Identity pose.
Definition: tf.cpp:9
moveit_msgs::PositionConstraint getPositionConstraint(const std::string &ee_name, const std::string &base_name, const RobotPose &pose, const GeometryConstPtr &geometry)
Get a position constraint message.
Definition: tf.cpp:169
RobotPose samplePoseGaussian(const Eigen::Vector3d &pos_stddev, const Eigen::Vector3d &orn_bounds)
Sample a pose with gaussian sampling for the position with given standard deviations and uniform samp...
Definition: tf.cpp:253
bool isVecZero(const Eigen::Ref< const Eigen::VectorXd > &v, double tolerance=constants::eps)
Checks if a vector is close to zero.
Definition: tf.cpp:321
geometry_msgs::Quaternion quaternionEigenToMsg(const Eigen::Quaterniond &quaternion)
Converts an Eigen::Quaterniond to a quaternion message.
Definition: tf.cpp:140
RobotPose transformMsgToEigen(const geometry_msgs::TransformStamped &tf)
Decode a message as a transform.
Definition: tf.cpp:282
Eigen::Quaterniond getPoseRotation(const RobotPose &pose)
Get the rotational component of a robot pose.
Definition: tf.cpp:69
static const double eps
Definition: constants.h:16
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24