RobotArmLib  0.0.4
Robot Arm Library [WIP]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
kinematic_chain.h
Go to the documentation of this file.
1 
7 #ifndef RB_KINEMATIC_CHAIN_H_
8 #define RB_KINEMATIC_CHAIN_H_
9 #include <iostream>
10 #include <iomanip>
11 #include <string>
12 #include <vector>
13 #include <array>
14 
15 #include "link.h"
16 
17 #include <Eigen/StdVector>
18 
19 namespace rb
20 {
21 namespace kin
22 {
28 {
34 };
35 
40 struct ArmPose
41 {
43  double x;
44  double y;
45  double z;
46 
47  double a;
48  double b;
49  double c;
50 };
51 
57 std::ostream& operator<< (std::ostream& ost, const ArmPose& pose);
58 
59 #if __cplusplus == 201103L
60 
64 template<typename T>
65  void ostrVec(std::ostream& ost, std::vector<T> vec_inp, int width=12)
66  {
67  ost << '\n';
68  for(auto& inp : vec_inp)
69  ost << std::right << std::setw(width) << inp;
70  return;
71  }
72 #endif
73 
79 {
83  int fit;
84  std::array<bool, 8> solution_check = {{0}};
85  std::array<bool, 8> singular_check = {{0}};
86  std::array<bool, 8> limit_check = {{0}};
87 
88  ArmAxisValue()
89  {
90  axis_value = rb::math::MatrixX::Constant(8, 6, 0.0);
91  fit = 0;
92  for (int i = 0; i < 8; i++)
93  {
94  solution_check[i] = singular_check[i] = limit_check[i] = 0;
95  }
96  }
97 };
98 
99 
105 {
106 public:
107  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
109  KinematicChain();
110 
113  std::vector<rb::kin::Link*>& links,
114  rb::math::Matrix4 base=rb::math::Matrix4::Identity(),
115  rb::math::Matrix4 tool=rb::math::Matrix4::Identity(),
116  rb::math::Vector3 gravity={0., 0., rb::math::GRAVITY},
117  std::string manufactor="None",
118  std::string model="None"
119  );
120 
122  virtual ~KinematicChain();
123 
131  virtual ArmPose forwardKin(const rb::math::VectorX& q, const bool update=true);
132 
138  virtual IK_RESULT inverseKin(
139  const rb::math::Matrix4& world_tcp_tf,
140  rb::math::VectorX& joints,
141  ArmAxisValue& all_sols
142  ) = 0;
143 
153  rb::math::Matrix4 homoTrans(double& A, double& alpha, double& D, const double& theta);
154 
161  bool setTool(const ArmPose& tool_pose);
162 
169  bool getTool(ArmPose& tool_pose) const;
170 
176  void setBase(const rb::math::Matrix4& base);
177 
182  rb::math::Matrix4 getBase(void) const;
183 
188  rb::math::Matrix4 getTCP(void) const;
189 
194  void setDOF(void);
195 
200  int getDOF(void) const;
201 
202 protected:
204  std::vector<rb::kin::Link*> links_;
205  //std::vector<rb::kin::Link*, Eigen::aligned_allocator<rb::kin::Link*> > links_;
206 
208  std::vector<rb::math::Matrix4*> frames_;
209  //std::vector<rb::math::Matrix4*, Eigen::aligned_allocator<rb::math::Matrix4*> > frames_;
210 
211  int dof_;
216 
217  std::string manufactor_;
218  std::string model_;
219 
220 private:
221  // private functions
222  // TODO: could move functions for matrix manipulating, such as rpy2tr & tr2rpy to math.h
223  void tr2rpy(const rb::math::Matrix4& m, double& roll_z, double& pitch_y, double& yaw_x) const;
224  void rpy2tr(double& roll_z, double& pitch_y, double& yaw_x, rb::math::Matrix4& tool_mat);
225  rb::math::Matrix4 rotateX(const double& deg);
226  rb::math::Matrix4 rotateY(const double& deg);
227  rb::math::Matrix4 rotateZ(const double& deg);
228 };
229 
230 } // namespace kin
231 } // namespace rb
232 
233 #endif // RB_KINEMATIC_CHAIN_H_
bool getTool(ArmPose &tool_pose) const
Get the HT matrix of the offset b/w the arm flange and equipped tool or end-effector.
Definition: kinematic_chain.cpp:133
IK_RESULT
A set of enumeration to present the result of inverse kinematics (IK)
Definition: kinematic_chain.h:27
rb::math::Matrix4 world_tcp_tf_
HT matrix of TCP with respected to world coordination.
Definition: kinematic_chain.h:214
A kinematics class for general serial links.
Definition: kinematic_chain.h:104
A struct variable for Tool Center Point (TCP) ArmPose storages the output of forward kinematic...
Definition: kinematic_chain.h:40
double x
Position of TCP (mm)
Definition: kinematic_chain.h:43
std::string model_
the model of the robot named by its manufactor
Definition: kinematic_chain.h:218
double a
Orientation of TCP (degree)
Definition: kinematic_chain.h:47
value 1
Definition: kinematic_chain.h:30
int getDOF(void) const
Get the degree of freedom of this kinematic chain.
Definition: kinematic_chain.cpp:170
value 4
Definition: kinematic_chain.h:33
int dof_
A integer indicates the degree of freedom.
Definition: kinematic_chain.h:211
std::array< bool, 8 > solution_check
check if having solution.
Definition: kinematic_chain.h:84
void setDOF(void)
Set the degree of freedom according to the property of links.
Definition: kinematic_chain.cpp:164
rb::math::Matrix4 getBase(void) const
Get the HT matrix of the working base of the robot arm.
Definition: kinematic_chain.cpp:154
Eigen::Matrix4d Matrix4
make Matrix4 as alias of Eigen::Matrix4d
Definition: matrix.h:20
Eigen::MatrixXd MatrixX
make MatrixX as alias of Eigen::MatrixXd
Definition: matrix.h:18
bool setTool(const ArmPose &tool_pose)
Set the HT matrix of the offset b/w the arm flange and equipped tool or end-effector.
Definition: kinematic_chain.cpp:118
double y
left and right
Definition: kinematic_chain.h:44
rb::math::Matrix4 getTCP(void) const
Get the HT matrix of TCP w.r.t world coordination.
Definition: kinematic_chain.cpp:159
rb::math::Vector3 gravity_
Gravity set as a vector.
Definition: kinematic_chain.h:215
rb::math::Matrix4 homoTrans(double &A, double &alpha, double &D, const double &theta)
Compute homogeneous transformation matrix for given link properties, and return the matrix...
Definition: kinematic_chain.cpp:180
Eigen::Vector3d Vector3
make Vector3 as alias of Eigen::Vector3d
Definition: matrix.h:23
double c
yaw
Definition: kinematic_chain.h:49
rb::math::MatrixX axis_value
Joints Angle of 8 solutions.
Definition: kinematic_chain.h:81
EIGEN_MAKE_ALIGNED_OPERATOR_NEW KinematicChain()
Default Constuctor.
Definition: kinematic_chain.cpp:42
value 2
Definition: kinematic_chain.h:31
std::array< bool, 8 > limit_check
check if over angle limit.
Definition: kinematic_chain.h:86
virtual IK_RESULT inverseKin(const rb::math::Matrix4 &world_tcp_tf, rb::math::VectorX &joints, ArmAxisValue &all_sols)=0
Compute inverse kinematics for given tranformation matrix of TCP in Cartesian coordination system...
rb::math::Matrix4 tool_tf_
HT matrix of TCP with respected to robot flange (last joint)
Definition: kinematic_chain.h:213
std::vector< rb::math::Matrix4 * > frames_
< A vector of HT matrix to the pose of each joint and TCP.
Definition: kinematic_chain.h:208
value 0
Definition: kinematic_chain.h:29
std::array< bool, 8 > singular_check
check if in singular point.
Definition: kinematic_chain.h:85
std::string manufactor_
the name of manufactor of the robot
Definition: kinematic_chain.h:217
value 3
Definition: kinematic_chain.h:32
std::vector< rb::kin::Link * > links_
A vector of Link class.
Definition: kinematic_chain.h:204
double b
pitch
Definition: kinematic_chain.h:48
virtual ArmPose forwardKin(const rb::math::VectorX &q, const bool update=true)
Compute forward Kinematics for given angle, update each joint value, and return current current posit...
Definition: kinematic_chain.cpp:84
std::ostream & operator<<(std::ostream &ost, const ArmPose &pose)
Overload << operator to print position & orientation in ArmPose.
Definition: kinematic_chain.cpp:24
void setBase(const rb::math::Matrix4 &base)
Set the Homogeneous Transformation matrix of the working base of the robot arm.
Definition: kinematic_chain.cpp:148
double z
up and down
Definition: kinematic_chain.h:45
virtual ~KinematicChain()
Destructor.
Definition: kinematic_chain.cpp:82
A struct variable for joints of robot arm ArmAxisValue storage the output of Inverse kinematic...
Definition: kinematic_chain.h:78
int fit
Use following method to find the fittest solution.
Definition: kinematic_chain.h:83
rb::math::Matrix4 base_tf_
HT matrix of robot base with respected to world coordination.
Definition: kinematic_chain.h:212
static const double GRAVITY
Constant to present value of gravity.
Definition: unit.h:28
Eigen::VectorXd VectorX
make VectorX as alias of Eigen::VectorXd
Definition: matrix.h:22