test_fanuc.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <ros/ros.h>
3 
9 
10 #include "test_utils.h"
11 
12 // Names to read values from the parameter server
13 const std::string GROUP_PARAM = "group";
14 const std::string TIP_LINK_PARAM = "tip_link";
15 const std::string ROOT_LINK_PARAM = "root_link";
16 
17 // Robot description almost always called "robot_description" and therefore hardcoded below
18 const std::string ROBOT_DESCRIPTION = "robot_description";
19 
20 // unused dummy value for kinematics solver instance
21 const double DEFAULT_SEARCH_DISCRETIZATION = 0.01f;
22 
28 class TestKinematicsFanuc : public ::testing::Test
29 {
30 protected:
31  void SetUp() override
32  {
33  ros::NodeHandle pnh("~");
36  {
38  robot_model_ = robot_model_loader.getModel();
39  robot_state_.reset(new robot_state::RobotState(robot_model_));
40  robot_state_->setToDefaultValues();
41  joint_model_group_ = robot_model_->getJointModelGroup(group_name_);
42  }
43  else
44  {
45  ROS_ERROR_STREAM("Failed to load parameters necessary to load plugin.");
46  }
47  }
48  void TearDown() override
49  {
50  }
51 
52  std::string root_link_;
53  std::string tip_link_;
54  std::string group_name_;
55 
56  robot_model::RobotModelPtr robot_model_;
57  robot_state::RobotStatePtr robot_state_;
58  robot_model::JointModelGroup* joint_model_group_;
59 };
60 
62 {
63  ASSERT_EQ(robot_model_->getJointModelGroupNames()[0], group_name_);
64 }
65 
68 TEST_F(TestKinematicsFanuc, TestAllIkSingleJointPose)
69 {
70  const std::vector<double> joint_angles = { 0, 0.1, 0.2, 0.3, 0.4, 0.5 };
71  robot_state_->setJointGroupPositions(joint_model_group_, joint_angles);
72 
73  // find reachable pose
74  auto fk_pose = robot_state_->getGlobalLinkTransform(tip_link_);
75 
76  // type conversions
77  geometry_msgs::Pose fk_pose_msgs;
78  tf::poseEigenToMsg(fk_pose, fk_pose_msgs);
79  const std::vector<geometry_msgs::Pose> fk_poses = { fk_pose_msgs };
80 
81  // calculate all ik solutions for the pose in fk_poses
82  std::vector<std::vector<double> > solutions;
85  const auto solver = joint_model_group_->getSolverInstance();
86 
88 
89  bool success = solver->getPositionIK(fk_poses, joint_angles, solutions, result, options);
90  ASSERT_TRUE(success);
91 
92  std::size_t num_solutions = solutions.size();
93  ASSERT_GT(num_solutions, 0);
94 
95  // check if fk for all this solutions gives the same pose
96  Eigen::Affine3d actual_pose;
97  for (auto js : solutions)
98  {
99  robot_state_->setJointGroupPositions(joint_model_group_, js);
100  actual_pose = robot_state_->getGlobalLinkTransform(tip_link_);
102  }
103 }
104 
105 int main(int argc, char** argv)
106 {
107  ros::init(argc, argv, "moveit_opw_kinematics_test_fanuc");
108  testing::InitGoogleTest(&argc, argv);
109  return RUN_ALL_TESTS();
110 }
const std::string GROUP_PARAM
Definition: test_fanuc.cpp:13
int main(int argc, char **argv)
Definition: test_fanuc.cpp:105
robot_model::RobotModelPtr robot_model_
Definition: test_fanuc.cpp:56
void TearDown() override
Definition: test_fanuc.cpp:48
void poseEigenToMsg(const Eigen::Affine3d &e, geometry_msgs::Pose &m)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const std::string TIP_LINK_PARAM
Definition: test_fanuc.cpp:14
TEST_F(TestKinematicsFanuc, InitOk)
Definition: test_fanuc.cpp:61
std::string group_name_
Definition: test_fanuc.cpp:54
std::string root_link_
Definition: test_fanuc.cpp:52
void comparePoses(const Transform< T > &Ta, const Transform< T > &Tb)
Compare every element of two eigen affine3 poses.
Definition: test_utils.h:20
options
robot_model::JointModelGroup * joint_model_group_
Definition: test_fanuc.cpp:58
bool getParam(const std::string &key, std::string &s) const
const std::string ROBOT_DESCRIPTION
Definition: test_fanuc.cpp:18
void SetUp() override
Definition: test_fanuc.cpp:31
const robot_model::RobotModelPtr & getModel() const
const std::string ROOT_LINK_PARAM
Definition: test_fanuc.cpp:15
#define ROS_ERROR_STREAM(args)
const double DEFAULT_SEARCH_DISCRETIZATION
Definition: test_fanuc.cpp:21
std::string tip_link_
Definition: test_fanuc.cpp:53
robot_state::RobotStatePtr robot_state_
Definition: test_fanuc.cpp:57


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