se2ez
joint.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef SE2EZ_CORE_JOINT_
4 #define SE2EZ_CORE_JOINT_
5 
6 #include <vector>
7 
8 #include <Eigen/Core>
9 
10 #include <kdl/joint.hpp>
11 
13 
14 namespace se2ez
15 {
16  /** \cond IGNORE */
17  SE2EZ_CLASS_FORWARD(Joint)
18  /** \endcond */
19 
20  /** \class se2ez::JointPtr
21  \brief A shared pointer wrapper for se2ez::Joint. */
22 
23  /** \class se2ez::JointConstPtr
24  \brief A const shared pointer wrapper for se2ez::Joint. */
25 
26  /** \brief Container class that stores the underlying joint representation.
27  * Can represent basic joints within the plane, such as fixed (rigid attachment), float (free-flying in
28  * SE(2)), translate (free translation in R^2), prismatic (extension along the X-axis), and revolute
29  * (rotation).
30  */
31  class Joint
32  {
33  public:
35 
36  /** \brief Type of joint.
37  */
38  enum Type
39  {
40  FIXED = 0, ///< Fixed joint, just a rigid transformation.
41  FLOAT = 1, ///< Floating joint, free movement in SE(2). Uses Euclidean metric.
42  FLYING = 2, ///< Floating joint, free movement in SE(2). Continuous rotation, uses SE(2) metric.
43  TRANSLATE = 3, ///< Translating joint, free X- and Y-axis movement.
44  PRISMATIC = 4, ///< Prismatic joint, extends along X-axis.
45  REVOLUTE = 5, ///< Revolute joint, rotates. Uses Euclidean metric.
46  CONTINUOUS = 6 ///< Revolute joint, rotates. Continuous rotation, uses SO(2) metric.
47  };
48  /** \brief Maximum value a joint type can have */
49  static const unsigned int TYPE_MAX = CONTINUOUS;
50  /** \brief String representation of joint type. */
51  static const std::string TYPE_STRINGS[];
52 
53  /** \brief Try to convert a string into a joint type. Not case-sensitive.
54  * \param[in] joint String of joint type. See TYPE_STRINGS.
55  * \return The type of joint specified by the string, or an exception on failure.
56  */
57  static Type stringToType(const std::string &joint);
58 
59  /** \brief Converts a joint type into its string representation.
60  * \param[in] type The type to convert.
61  * \return The joint type as a string.
62  */
63  static const std::string &typeToString(const Type &type);
64 
65  /** \name Constructors
66  \{ */
67 
68  /** \brief Constructor. Takes in name of joint (the frame this joint is associated with, normally) and
69  * the joint type to create underlying structures.
70  * \param[in] name Name of the joint.
71  * \param[in] type Type of the joint.
72  * \param[in] lower Lower limits of frame joint.
73  * \param[in] upper Upper limits of frame joint.
74  */
75  Joint(const std::string &name, Type type, const Eigen::VectorXd &lower, const Eigen::VectorXd &upper);
76 
77  // non-copyable
78  Joint(const Joint &) = delete;
79  Joint(Joint &&) = delete;
80 
81  /** \} */
82 
83  /** \name Joint-based Operations
84  \{ */
85 
86  /** \brief Enforces joint limits on a joint configuration.
87  * \param[in] q Configuration for the joint.
88  */
89  void enforceBounds(Eigen::Ref<Eigen::VectorXd> q) const;
90 
91  /** \brief sets the Joint at a random state respecting the limits.
92  * \param[in] q Configuration for the joint.
93  */
94  void setRandom(Eigen::Ref<Eigen::VectorXd> q) const;
95 
96  /** \brief Checks if joint limits are satisfied for a joint configuration.
97  * \param[in] q Configuration for the joint.
98  * \return True if configuration is within bounds.
99  */
100  bool inBounds(const Eigen::Ref<const Eigen::VectorXd> &q) const;
101 
102  /** \brief Measures distance between two joint configurations.
103  * \param[in] a First configuration.
104  * \param[in] b First configuration.
105  * \return Distance between a and b
106  */
107  double distance(const Eigen::Ref<const Eigen::VectorXd> &a,
108  const Eigen::Ref<const Eigen::VectorXd> &b) const;
109 
110  /** \brief Interpolate between two joint configurations.
111  * \param[in] from Initial configuration.
112  * \param[in] to Destination configuration.
113  * \param[in] t Interpolation parameter.
114  * \param[out] state Output configuration.
115  * \return Fills state with interpolated parameters.
116  */
117  void interpolate(const Eigen::Ref<const Eigen::VectorXd> &from,
118  const Eigen::Ref<const Eigen::VectorXd> &to, double t,
119  Eigen::Ref<Eigen::VectorXd> state) const;
120 
121  /** \brief Get the bounds for this joint. For continuous joints, [-pi, pi] is returned.
122  * \return A pair of lower and upper bounds for the joint.
123  */
125 
126  /** \} */
127 
128  /** \name Informative
129  \{ */
130 
131  /** \brief Print debug information about this frame.
132  * \return A string of information about the frame.
133  */
134  std::string printDebug() const;
135 
136  /** \} */
137 
138  const Type type; ///< Type of joint.
139  const std::vector<KDL::Joint> joints; ///< Underlying KDL joints.
140  const bool continuous; ///< Is this a continuous type joint?
141  const bool fixed; ///< Is this joint fixed?
142  const unsigned int n; ///< Number of joints.
143 
144  const Eigen::VectorXd lower; ///< Lower limits of this frame's joint value (closed).
145  const Eigen::VectorXd upper; ///< Upper limits of this frame's joint value (closed).
146 
147  private:
148  const unsigned int top_; ///< Top index for internal computations.
149  };
150 } // namespace se2ez
151 
152 #endif
Type
Type of joint.
Definition: joint.h:38
const unsigned int top_
Top index for internal computations.
Definition: joint.h:148
const Eigen::VectorXd upper
Upper limits of this frame&#39;s joint value (closed).
Definition: joint.h:145
const Eigen::VectorXd lower
Lower limits of this frame&#39;s joint value (closed).
Definition: joint.h:144
Container class that stores the underlying joint representation. Can represent basic joints within th...
Definition: joint.h:31
#define SE2EZ_EIGEN_CLASS
Definition: class_forward.h:14
const std::vector< KDL::Joint > joints
Underlying KDL joints.
Definition: joint.h:139
const bool fixed
Is this joint fixed?
Definition: joint.h:141
const bool continuous
Is this a continuous type joint?
Definition: joint.h:140
const Type type
Type of joint.
Definition: joint.h:138
Main namespace.
Definition: collision.h:11
const unsigned int n
Number of joints.
Definition: joint.h:142
#define SE2EZ_CLASS_FORWARD(C)
Definition: class_forward.h:9