tinyrobotics
Loading...
Searching...
No Matches
Joint.hpp
Go to the documentation of this file.
1#ifndef TR_JOINT_HPP
2#define TR_JOINT_HPP
3
4#include <Eigen/Core>
5#include <Eigen/Geometry>
6
10namespace tinyrobotics {
11
13 enum class JointType {
14 UNKNOWN,
15 REVOLUTE,
17 PRISMATIC,
18 FLOATING,
19 PLANAR,
20 FIXED
21 };
22
27 template <typename Scalar>
28 struct Joint {
29
31 int joint_id = -1;
32
34 int idx = -1;
35
37 std::string name = "";
38
40 JointType type = JointType::UNKNOWN;
41
43 Eigen::Matrix<Scalar, 3, 1> axis = Eigen::Matrix<Scalar, 3, 1>::Zero();
44
46 Eigen::Transform<Scalar, 3, Eigen::Isometry> parent_transform =
47 Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
48
50 Eigen::Transform<Scalar, 3, Eigen::Isometry> child_transform =
51 Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
52
54 std::string parent_link_name = "";
55
57 std::string child_link_name = "";
58
60 Eigen::Matrix<Scalar, 6, 6> X = Eigen::Matrix<Scalar, 6, 6>::Identity();
61
63 Eigen::Matrix<Scalar, 6, 1> S = Eigen::Matrix<Scalar, 6, 1>::Zero();
64
70 std::string get_type() const {
71 switch (type) {
72 case JointType::UNKNOWN: return "Unknown";
73 case JointType::REVOLUTE: return "Revolute";
74 case JointType::CONTINUOUS: return "Continuous";
75 case JointType::PRISMATIC: return "Prismatic";
76 case JointType::FLOATING: return "Floating";
77 case JointType::PLANAR: return "Planar";
78 case JointType::FIXED: return "Fixed";
79 default: return "Invalid";
80 }
81 }
82
88 Eigen::Transform<Scalar, 3, Eigen::Isometry> get_joint_transform(const Scalar& q) const {
89 Eigen::Transform<Scalar, 3, Eigen::Isometry> T = Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
90 switch (type) {
91 case JointType::REVOLUTE: {
92 T.linear() = Eigen::AngleAxis<Scalar>(q, Eigen::Matrix<Scalar, 3, 1>(axis[0], axis[1], axis[2]))
93 .toRotationMatrix();
94 return T;
95 break;
96 }
97 case JointType::PRISMATIC: {
98 T.translation() = q * Eigen::Matrix<Scalar, 3, 1>(axis[0], axis[1], axis[2]);
99 return T;
100 break;
101 }
102 case JointType::FIXED: {
103 return T;
104 break;
105 }
106 default: {
107 std::cout << "Joint type not supported." << std::endl;
108 break;
109 }
110 }
111 return T;
112 }
113
119 Eigen::Transform<Scalar, 3, Eigen::Isometry> get_parent_to_child_transform(const Scalar& q) {
121 }
122
128 template <typename NewScalar>
131 new_joint.joint_id = joint_id;
132 new_joint.idx = idx;
133 new_joint.name = name;
134 new_joint.type = type;
135 new_joint.axis = axis.template cast<NewScalar>();
136 new_joint.parent_transform = parent_transform.template cast<NewScalar>();
137 new_joint.child_transform = child_transform.template cast<NewScalar>();
140 new_joint.X = X.template cast<NewScalar>();
141 return new_joint;
142 }
143 };
144
145
146} // namespace tinyrobotics
147#endif
JointType
The types of joints.
Definition: Joint.hpp:13
@ REVOLUTE
Revolute joint, can rotate about an axis.
@ PLANAR
Planar joint.
@ UNKNOWN
Unknown joint type.
@ FLOATING
Floating joint, can translate and rotate about any axis.
@ PRISMATIC
Prismatic joint, can translate along an axis.
@ CONTINUOUS
Continuous joint.
@ FIXED
Fixed joint, cannot move.
Represents a joint in a tinyrobotics model which connects two links.
Definition: Joint.hpp:28
std::string get_type() const
Get joint type as a string.
Definition: Joint.hpp:70
Eigen::Matrix< Scalar, 6, 6 > X
Spatial transformation matrix from the parent to the child link.
Definition: Joint.hpp:60
Joint< NewScalar > cast() const
Casts the joint to a new scalar type.
Definition: Joint.hpp:129
std::string parent_link_name
Name of the joints parent link.
Definition: Joint.hpp:54
Eigen::Matrix< Scalar, 3, 1 > axis
Axis of motion for the joint.
Definition: Joint.hpp:43
Eigen::Transform< Scalar, 3, Eigen::Isometry > get_parent_to_child_transform(const Scalar &q)
Compute the transform from parent to child.
Definition: Joint.hpp:119
Eigen::Transform< Scalar, 3, Eigen::Isometry > get_joint_transform(const Scalar &q) const
Compute the joint transform.
Definition: Joint.hpp:88
JointType type
Type of the joint.
Definition: Joint.hpp:40
std::string child_link_name
Name of the joints child link.
Definition: Joint.hpp:57
std::string name
Name of the joint.
Definition: Joint.hpp:37
int joint_id
Index of the joint in the tinyrobotics model's joint vector.
Definition: Joint.hpp:31
Eigen::Transform< Scalar, 3, Eigen::Isometry > parent_transform
Homogeneous transform to the parent link.
Definition: Joint.hpp:46
Eigen::Transform< Scalar, 3, Eigen::Isometry > child_transform
Homogeneous transform to the child link.
Definition: Joint.hpp:50
Eigen::Matrix< Scalar, 6, 1 > S
Spatial axis.
Definition: Joint.hpp:63
int idx
Index of the joint in the tinyrobotics model's configuration vector.
Definition: Joint.hpp:34