se2ez
frame.cpp
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #include <se2ez/core/log.h>
4 #include <se2ez/core/frame.h>
5 #include <se2ez/core/geometry.h>
6 
7 using namespace se2ez;
8 
10 {
11  static FramePtr root = std::make_shared<Frame>("root", Eigen::Isometry2d::Identity(), Joint::FIXED);
12  return root;
13 }
14 
15 Frame::Frame(const std::string &name, const Eigen::Isometry2d &tip, const std::vector<GeometryPtr> &geometry)
16  : Frame(name, tip, Joint::FIXED, Eigen::VectorXd{}, Eigen::VectorXd{}, geometry)
17 {
18 }
19 
20 Frame::Frame(const std::string &name, const Eigen::Vector3d &tip, const std::vector<GeometryPtr> &geometry)
21  : Frame(name, tf::toIsometry(tip), geometry)
22 {
23 }
24 
25 Frame::Frame(const std::string &name, const Eigen::Isometry2d &tip, const Joint::Type &type,
26  const Eigen::VectorXd &lower, const Eigen::VectorXd &upper,
27  const std::vector<GeometryPtr> &geometry)
28  : name_(name), tip_(tip), joint_(name, type, lower, upper), geometry_(geometry), segments_([&]() {
30  unsigned int s = joint_.joints.size();
31  for (unsigned int i = 0; i < s; ++i)
32  segments.emplace_back(joint_.joints[i].getName(), // Use joint name, as last joint is frame name)
33  joint_.joints[i],
34  (i == s - 1) ? tf::EigenToKDLFrame(tip_) : // Use tip transform only on last
35  KDL::Frame::Identity()); // Otherwise just identity
36  return segments;
37  }())
38 {
39  if (!name.size())
40  throw std::invalid_argument("Name for frame cannot be empty!");
41 }
42 
43 Frame::Frame(const std::string &name, const Eigen::Vector3d &tip, const Joint::Type &type,
44  const Eigen::VectorXd &lower, const Eigen::VectorXd &upper,
45  const std::vector<GeometryPtr> &geometry)
46  : Frame(name, tf::toIsometry(tip), type, lower, upper, geometry)
47 {
48 }
49 
50 Frame::Frame(const std::string &name, const Eigen::Isometry2d &tip, const Joint::Type &type,
51  const double lower, const double upper, const std::vector<GeometryPtr> &geometry)
52  : Frame(name, tip, type, math::toVector(lower), math::toVector(upper), geometry)
53 {
54 }
55 
56 Frame::Frame(const std::string &name, const Eigen::Vector3d &tip, const Joint::Type &type, const double lower,
57  const double upper, const std::vector<GeometryPtr> &geometry)
58  : Frame(name, tf::toIsometry(tip), type, lower, upper, geometry)
59 {
60 }
61 
63 {
64  return name_;
65 }
66 
68 {
69  return segments_;
70 }
71 
73 {
74  return geometry_;
75 }
76 
77 const Joint &Frame::getJoint() const
78 {
79  return joint_;
80 }
81 
82 const Eigen::Isometry2d &Frame::getTip() const
83 {
84  return tip_;
85 }
86 
87 Eigen::Isometry2d Frame::getPose(const Eigen::Ref<const Eigen::VectorXd> &q) const
88 {
89  KDL::Frame f = KDL::Frame::Identity();
90  for (unsigned int i = 0; i < segments_.size() - 1; ++i)
91  f = f * segments_[i].pose(q[i]);
92 
93  f = f * segments_.back().pose(0);
94  return tf::KDLToEigenFrame(f);
95 }
96 
97 void Frame::getGeometryPoses(const Eigen::Isometry2d &pose, tf::EigenVector<Eigen::Isometry2d> &poses) const
98 {
99  poses.resize(geometry_.size());
100  for (unsigned int i = 0; i < geometry_.size(); ++i)
101  poses[i] = (geometry_[i]->isOffset) ? pose * geometry_[i]->offset : pose;
102 }
103 
105 {
107  ss << log::format("[%1% %2% %3%", name_, tf::printFrame(tip_), joint_.printDebug());
108  for (const auto &geometry : geometry_)
109  ss << geometry->printGeometry();
110 
111  ss << "]";
112  return ss.str();
113 }
const std::vector< GeometryPtr > geometry_
Geometry attached to this frame (at the tip).
Definition: frame.h:178
Eigen::Isometry2d KDLToEigenFrame(const KDL::Frame &frame)
Converts an KDL transformation into a Eigen transformation.
Definition: math.cpp:55
std::string printFrame(const Eigen::Isometry2d &frame)
Returns a string "[x, y, t]" of the translation (x, y) and rotation (t) component of a transform...
Definition: math.cpp:79
Type
Type of joint.
Definition: joint.h:38
const std::vector< KDL::Segment > segments_
Underlying segments that compose this frame.
Definition: frame.h:179
const std::vector< KDL::Segment > & getSegments() const
Get the segments that compose this frame.
Definition: frame.cpp:67
Frame(const std::string &name, const Eigen::Isometry2d &tip, const std::vector< GeometryPtr > &geometry={})
Constuctor. Builds a fixed frame at the desired location.
Definition: frame.cpp:15
std::string printDebug() const
Print debug information about this frame.
Definition: frame.cpp:104
Fixed joint, just a rigid transformation.
Definition: joint.h:40
T resize(T... args)
Container class that stores the underlying joint representation. Can represent basic joints within th...
Definition: joint.h:31
A shared pointer wrapper for se2ez::Frame.
std::string printDebug() const
Print debug information about this frame.
Definition: joint.cpp:168
const std::string name_
Name of the frame.
Definition: frame.h:174
const Joint & getJoint() const
Get the joint within this frame.
Definition: frame.cpp:77
Eigen::Isometry2d toIsometry(double x, double y, double theta)
Converts a translation (x, y) and rotation from X-axis (theta) into a transform.
Definition: math.cpp:11
T str(T... args)
const std::vector< KDL::Joint > joints
Underlying KDL joints.
Definition: joint.h:139
Eigen::VectorXd toVector(double x)
Converts a single double value into a 1 x 1 matrix.
Definition: math.cpp:134
const Joint joint_
The joint associated with the frame.
Definition: frame.h:176
const Eigen::Isometry2d & getTip() const
Get the tip of this frame.
Definition: frame.cpp:82
void getGeometryPoses(const Eigen::Isometry2d &pose, tf::EigenVector< Eigen::Isometry2d > &poses) const
Get the poses of each of the attached geometry frames (in order).
Definition: frame.cpp:97
Eigen::Isometry2d getPose(const Eigen::Ref< const Eigen::VectorXd > &q) const
Gets the pose of this frame (respect to the root) given a configuration q (for this frame only...
Definition: frame.cpp:87
Representation of a single frame (possibly with a joint) in a kinematic tree.
Definition: frame.h:36
T size(T... args)
static SE2EZ_EIGEN_CLASS FramePtr getRoot()
Definition: frame.cpp:9
std::string format(const std::string &fmt, Args &&... args)
Definition: log.h:25
const std::vector< GeometryPtr > & getGeometry() const
Get the geometries attached to this frame.
Definition: frame.cpp:72
T back(T... args)
KDL::Frame EigenToKDLFrame(const Eigen::Isometry2d &iso)
Converts an Eigen transformation into a KDL transformation.
Definition: math.cpp:48
Main namespace.
Definition: collision.h:11
const std::string & getName() const
Get the name of this frame.
Definition: frame.cpp:62
T emplace_back(T... args)
const Eigen::Isometry2d tip_
The transform after joint transformation to the tip of the frame.
Definition: frame.h:175