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


opw_kinematics
Author(s): Jon Meyer , Jeroen De Maeyer
autogenerated on Thu Jan 16 2025 03:40:37