test_plugin.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <ros/ros.h>
3 
5 #include <moveit/robot_model_loader/robot_model_loader.h>
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 
26 class TestPlugin : public ::testing::Test
27 {
28 protected:
29  void SetUp() override
30  {
31  ros::NodeHandle nh;
34  {
35  rdf_loader::RDFLoader rdf_loader(ROBOT_DESCRIPTION);
36  const srdf::ModelSharedPtr& srdf = rdf_loader.getSRDF();
37  const urdf::ModelInterfaceSharedPtr& urdf_model = rdf_loader.getURDF();
38 
39  if (!urdf_model || !srdf)
40  {
41  ROS_ERROR_NAMED("opw", "URDF and SRDF must be loaded for OPW kinematics "
42  "tests to work.");
43  return;
44  }
45 
46  robot_model_.reset(new robot_model::RobotModel(urdf_model, srdf));
47 
48  // the last parameter specifies "search_discretization", which is not used by the opw plugin
50  }
51  else
52  {
53  ROS_ERROR_STREAM("Failed to load parameters necessary to load plugin.");
54  }
55  }
56  void TearDown() override
57  {
58  }
59 
60  robot_model::RobotModelPtr robot_model_;
62  std::string root_link_;
63  std::string tip_link_;
64  std::string group_name_;
65  std::string robot_description_name_;
66 };
67 
69 {
70  ASSERT_EQ(plugin_.getGroupName(), group_name_);
71 }
72 
73 TEST_F(TestPlugin, CompareIKAndFK)
74 {
75  std::vector<std::string> link_names;
76  const std::vector<double> joint_angles = { 0, 0.1, 0.2, 0.3, 0.4, 0.5 };
77  std::vector<geometry_msgs::Pose> poses_out;
78 
79  // find reachable pose
80  plugin_.getPositionFK(plugin_.getLinkNames(), joint_angles, poses_out);
81 
82  // calculate all ik solutions for this pose
83  const std::vector<geometry_msgs::Pose> poses_in = { poses_out[0] };
84  std::vector<std::vector<double> > solutions;
86  bool res = plugin_.getPositionIK(poses_in, joint_angles, solutions, result);
87  EXPECT_TRUE(res);
88 
89  // check if fk for all this solutions gives the same pose
90  Eigen::Isometry3d actual, desired;
91  tf::poseMsgToEigen(poses_out[0], desired);
92  for (auto js : solutions)
93  {
94  plugin_.getPositionFK(plugin_.getLinkNames(), js, poses_out);
95  tf::poseMsgToEigen(poses_out[0], actual);
97  }
98 }
99 
100 int main(int argc, char** argv)
101 {
102  ros::init(argc, argv, "moveit_opw_kinematics_test_fanuc");
103  testing::InitGoogleTest(&argc, argv);
104  return RUN_ALL_TESTS();
105 }
int main(int argc, char **argv)
const std::string ROOT_LINK_PARAM
Definition: test_plugin.cpp:15
virtual bool getPositionFK(const std::vector< std::string > &link_names, const std::vector< double > &joint_angles, std::vector< geometry_msgs::Pose > &poses) const override
const std::vector< std::string > & getLinkNames() const override
Return all the link names in the order they are represented internally.
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
void TearDown() override
Definition: test_plugin.cpp:56
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void SetUp() override
Definition: test_plugin.cpp:29
robot_model::RobotModelPtr robot_model_
const std::string GROUP_PARAM
Definition: test_plugin.cpp:13
std::string tip_link_
virtual bool getPositionIK(const geometry_msgs::Pose &ik_pose, const std::vector< double > &ik_seed_state, std::vector< double > &solution, moveit_msgs::MoveItErrorCodes &error_code, const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions()) const override
Specific implementation of kinematics using ROS service calls to communicate with external IK solvers...
void comparePoses(const Transform< T > &Ta, const Transform< T > &Tb)
Compare every element of two transforms.
Definition: test_utils.h:18
const std::string ROBOT_DESCRIPTION
Definition: test_plugin.cpp:18
bool getParam(const std::string &key, std::string &s) const
std::string robot_description_name_
moveit_opw_kinematics_plugin::MoveItOPWKinematicsPlugin plugin_
std::string root_link_
std::shared_ptr< Model > ModelSharedPtr
std::string group_name_
virtual const std::string & getGroupName() const
#define ROS_ERROR_NAMED(name,...)
virtual bool initialize(const moveit::core::RobotModel &robot_model, const std::string &group_name, const std::string &base_frame, const std::vector< std::string > &tip_frames, double search_discretization) override
#define ROS_ERROR_STREAM(args)
#define EXPECT_TRUE(args)
TEST_F(TestPlugin, InitOk)
Definition: test_plugin.cpp:68
const std::string TIP_LINK_PARAM
Definition: test_plugin.cpp:14


moveit_opw_kinematics_plugin
Author(s): Jeroen De Maeyer, Simon Schmeisser (isys vision)
autogenerated on Mon Feb 28 2022 22:50:11