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#include <iostream>
7
11namespace tinyrobotics {
12
14 enum class JointType {
15 UNKNOWN,
16 REVOLUTE,
18 PRISMATIC,
19 FLOATING,
20 PLANAR,
21 FIXED
22 };
23
28 template <typename Scalar>
29 struct Joint {
30
32 int joint_id = -1;
33
35 int idx = -1;
36
38 std::string name = "";
39
41 JointType type = JointType::UNKNOWN;
42
44 Eigen::Matrix<Scalar, 3, 1> axis = Eigen::Matrix<Scalar, 3, 1>::Zero();
45
47 Eigen::Transform<Scalar, 3, Eigen::Isometry> parent_transform =
48 Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
49
51 Eigen::Transform<Scalar, 3, Eigen::Isometry> child_transform =
52 Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
53
55 std::string parent_link_name = "";
56
58 std::string child_link_name = "";
59
61 Eigen::Matrix<Scalar, 6, 6> X = Eigen::Matrix<Scalar, 6, 6>::Identity();
62
64 Eigen::Matrix<Scalar, 6, 1> S = Eigen::Matrix<Scalar, 6, 1>::Zero();
65
71 std::string get_type() const {
72 switch (type) {
73 case JointType::UNKNOWN: return "Unknown";
74 case JointType::REVOLUTE: return "Revolute";
75 case JointType::CONTINUOUS: return "Continuous";
76 case JointType::PRISMATIC: return "Prismatic";
77 case JointType::FLOATING: return "Floating";
78 case JointType::PLANAR: return "Planar";
79 case JointType::FIXED: return "Fixed";
80 default: return "Invalid";
81 }
82 }
83
89 Eigen::Transform<Scalar, 3, Eigen::Isometry> get_joint_transform(const Scalar& q) const {
90 Eigen::Transform<Scalar, 3, Eigen::Isometry> T = Eigen::Transform<Scalar, 3, Eigen::Isometry>::Identity();
91 switch (type) {
92 case JointType::REVOLUTE: T.linear() = Eigen::AngleAxis<Scalar>(q, axis).toRotationMatrix(); break;
93 case JointType::PRISMATIC: T.translation() = q * axis; break;
94 case JointType::FIXED: break;
95 default: throw std::runtime_error("Joint type not supported.");
96 }
97 return T;
98 }
99
105 Eigen::Transform<Scalar, 3, Eigen::Isometry> get_parent_to_child_transform(const Scalar& q) {
107 }
108
114 template <typename NewScalar>
117 new_joint.joint_id = joint_id;
118 new_joint.idx = idx;
119 new_joint.name = name;
120 new_joint.type = type;
121 new_joint.axis = axis.template cast<NewScalar>();
122 new_joint.parent_transform = parent_transform.template cast<NewScalar>();
123 new_joint.child_transform = child_transform.template cast<NewScalar>();
126 new_joint.X = X.template cast<NewScalar>();
127 new_joint.S = S.template cast<NewScalar>();
128 return new_joint;
129 }
130 };
131
132
133} // namespace tinyrobotics
134#endif
JointType
The types of joints.
Definition: joint.hpp:14
@ 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:29
std::string get_type() const
Get joint type as a string.
Definition: joint.hpp:71
Eigen::Matrix< Scalar, 6, 6 > X
Spatial transformation matrix from the parent to the child link.
Definition: joint.hpp:61
Joint< NewScalar > cast() const
Casts the joint to a new scalar type.
Definition: joint.hpp:115
std::string parent_link_name
Name of the joints parent link.
Definition: joint.hpp:55
Eigen::Matrix< Scalar, 3, 1 > axis
Axis of motion for the joint.
Definition: joint.hpp:44
Eigen::Transform< Scalar, 3, Eigen::Isometry > get_parent_to_child_transform(const Scalar &q)
Compute the transform from parent to child.
Definition: joint.hpp:105
Eigen::Transform< Scalar, 3, Eigen::Isometry > get_joint_transform(const Scalar &q) const
Compute the joint transform.
Definition: joint.hpp:89
JointType type
Type of the joint.
Definition: joint.hpp:41
std::string child_link_name
Name of the joints child link.
Definition: joint.hpp:58
std::string name
Name of the joint.
Definition: joint.hpp:38
int joint_id
Index of the joint in the tinyrobotics model's joint vector.
Definition: joint.hpp:32
Eigen::Transform< Scalar, 3, Eigen::Isometry > parent_transform
Homogeneous transform to the parent link.
Definition: joint.hpp:47
Eigen::Transform< Scalar, 3, Eigen::Isometry > child_transform
Homogeneous transform to the child link.
Definition: joint.hpp:51
Eigen::Matrix< Scalar, 6, 1 > S
Spatial axis.
Definition: joint.hpp:64
int idx
Index of the joint in the tinyrobotics model's configuration vector.
Definition: joint.hpp:35