sign_corrections_tests.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <vector>
3 #include <Eigen/Dense>
4 #include <array>
5 
9 
10 const double TOLERANCE = 1e-5; // absolute tolerance for EXPECT_NEAR checks
11 
13 
16 template <typename T>
17 void comparePoses(const Transform<T> & Ta, const Transform<T> & Tb)
18 {
19  using Matrix = Eigen::Matrix<T, 3, 3>;
20  using Vector = Eigen::Matrix<T, 3, 1>;
21 
22  Matrix Ra = Ta.rotation(), Rb = Tb.rotation();
23  for (int i = 0; i < Ra.rows(); ++i)
24  {
25  for (int j = 0; j < Ra.cols(); ++j)
26  {
27  EXPECT_NEAR(Ra(i, j), Rb(i, j), TOLERANCE);
28  }
29  }
30 
31  Vector pa = Ta.translation(), pb = Tb.translation();
32  EXPECT_NEAR(pa[0], pb[0], TOLERANCE);
33  EXPECT_NEAR(pa[1], pb[1], TOLERANCE);
34  EXPECT_NEAR(pa[2], pb[2], TOLERANCE);
35 }
36 
37 TEST(kuka_kr6, forward_kinematics)
38 {
39  const auto kuka = opw_kinematics::makeKukaKR6_R700_sixx<float>();
40 
41  std::vector<float> joint_values = {0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f};
42  Transform<float> forward_pose = opw_kinematics::forward(kuka, &joint_values[0]);
43 
44  // Compare with copied results from forward kinematics using MoveIt!
45  Transform<float> actual_pose;
46  actual_pose.matrix() << -0.5965795, 0.000371195, 0.8025539, 0,
47  -0.2724458, 0.9405218, -0.202958, 0,
48  -0.7548948, -0.3397331, -0.5609949, 0,
49  0 , 0 , 0 , 1;
50  actual_pose.translation() << 0.7341169, -0.1520347, 0.182639;
51 
52  comparePoses(forward_pose, actual_pose);
53 }
54 
55 TEST(kuka_kr6, inverse_kinematics)
56 {
57  // this test assumes that the forward kinematics for joint values
58  // {0.2, 0.2, 0.2, 0.2, 0.2, 0.2} are correct
59 
60  const auto kuka = opw_kinematics::makeKukaKR6_R700_sixx<float>();
61 
62  std::vector<float> joint_values = {0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f};
63  Transform<float> forward_pose = opw_kinematics::forward(kuka, &joint_values[0]);
64 
65  std::array<float, 6 * 8> sols;
66  opw_kinematics::inverse(kuka, forward_pose, sols.data());
67 
68  Transform<float> pose;
69  for (int i = 0; i < 8; ++i)
70  {
71  if (opw_kinematics::isValid(&sols[6 * i]))
72  {
73  // Forward kinematics of a solution should result in the same pose
74  pose = opw_kinematics::forward(kuka, &sols[6 * i]);
75  comparePoses(forward_pose, pose);
76  }
77  }
78 }
79 
80 int main(int argc, char **argv)
81 {
82  testing::InitGoogleTest(&argc, argv);
83  return RUN_ALL_TESTS();
84 }
TEST(kuka_kr6, forward_kinematics)
void comparePoses(const Transform< T > &Ta, const Transform< T > &Tb)
Compare every element of two eigen Isometry3 poses.
const double TOLERANCE
#define EXPECT_NEAR(a, b, prec)
int main(int argc, char **argv)
bool isValid(const T *qs)
Definition: opw_utilities.h:10
Eigen::Transform< T, 3, Eigen::Isometry > Transform
void inverse(const Parameters< T > &params, const Transform< T > &pose, T *out) noexcept
Computes up to 8 kinematically unique joint solutions that put the tool flange of the robot described...
opw_kinematics::Transform< double > Transform
Transform< T > forward(const Parameters< T > &p, const T *qs) noexcept
Computes the tool pose of the robot described by when said robot has the joint positions given by qs...


moveit_opw_kinematics_plugin
Author(s): Jeroen De Maeyer, Simon Schmeisser (isys vision)
autogenerated on Wed Jun 3 2020 03:17:14