39 #include <gtest/gtest.h> 55 #define IK_NEAR_TRANSLATE 1e-5 62 double search_discretization;
67 std::string plugin_name;
68 if (!nh.
getParam(
"plugin_name", plugin_name))
70 ROS_ERROR(
"No plugin name found on parameter server");
74 ROS_INFO(
"Plugin name: %s", plugin_name.c_str());
81 ROS_ERROR(
"The plugin failed to load. Error: %s", ex.what());
85 std::string root_name, tip_name, finger_group_name;
90 if (!nh.
getParam(
"root_name", root_name))
92 ROS_ERROR(
"No root name found on parameter server");
97 if (!nh.
getParam(
"tip_name", tip_name))
99 ROS_ERROR(
"No tip name found on parameter server");
104 if (!nh.
getParam(
"search_discretization", search_discretization))
106 ROS_ERROR(
"No search discretization found on parameter server");
111 if (!nh.
getParam(
"group_name", finger_group_name))
113 ROS_ERROR(
"No group name given, using fingers");
114 finger_group_name =
"fingers";
127 if (
kinematics_solver_->initialize(
"robot_description", finger_group_name, root_name, tip_name,
128 search_discretization))
140 const std::vector<double> &joint_state,
141 moveit_msgs::MoveItErrorCodes &error_code)
143 std::vector<std::string> link_names;
145 std::vector<geometry_msgs::Pose> solutions;
149 error_code.val = error_code.PLANNING_FAILED;
151 if (solutions[0].position.z > 0.0)
153 error_code.val = error_code.SUCCESS;
157 error_code.val = error_code.PLANNING_FAILED;
174 EXPECT_TRUE(tool_name.find(
"tip") != std::string::npos);
177 if (tool_name.find(
"fftip") != std::string::npos)
179 EXPECT_EQ(static_cast<int>(joint_names.size()), 4);
180 EXPECT_TRUE(joint_names[0].find(
"FFJ4") != std::string::npos);
181 EXPECT_TRUE(joint_names[1].find(
"FFJ3") != std::string::npos);
182 EXPECT_TRUE(joint_names[2].find(
"FFJ2") != std::string::npos);
183 EXPECT_TRUE(joint_names[3].find(
"FFJ1") != std::string::npos);
185 if (tool_name.find(
"mftip") != std::string::npos)
187 EXPECT_EQ(static_cast<int>(joint_names.size()), 4);
188 EXPECT_TRUE(joint_names[0].find(
"MFJ4") != std::string::npos);
189 EXPECT_TRUE(joint_names[1].find(
"MFJ3") != std::string::npos);
190 EXPECT_TRUE(joint_names[2].find(
"MFJ2") != std::string::npos);
191 EXPECT_TRUE(joint_names[3].find(
"MFJ1") != std::string::npos);
193 if (tool_name.find(
"rftip") != std::string::npos)
195 EXPECT_EQ(static_cast<int>(joint_names.size()), 4);
196 EXPECT_TRUE(joint_names[0].find(
"RFJ4") != std::string::npos);
197 EXPECT_TRUE(joint_names[1].find(
"RFJ3") != std::string::npos);
198 EXPECT_TRUE(joint_names[2].find(
"RFJ2") != std::string::npos);
199 EXPECT_TRUE(joint_names[3].find(
"RFJ1") != std::string::npos);
201 if (tool_name.find(
"lftip") != std::string::npos)
203 EXPECT_EQ(static_cast<int>(joint_names.size()), 5);
204 EXPECT_TRUE(joint_names[0].find(
"LFJ5") != std::string::npos);
205 EXPECT_TRUE(joint_names[1].find(
"LFJ4") != std::string::npos);
206 EXPECT_TRUE(joint_names[2].find(
"LFJ3") != std::string::npos);
207 EXPECT_TRUE(joint_names[3].find(
"LFJ2") != std::string::npos);
208 EXPECT_TRUE(joint_names[4].find(
"LFJ1") != std::string::npos);
210 if (tool_name.find(
"thtip") != std::string::npos)
212 EXPECT_EQ(static_cast<int>(joint_names.size()), 5);
213 EXPECT_TRUE(joint_names[0].find(
"THJ5") != std::string::npos);
214 EXPECT_TRUE(joint_names[1].find(
"THJ4") != std::string::npos);
215 EXPECT_TRUE(joint_names[2].find(
"THJ3") != std::string::npos);
216 EXPECT_TRUE(joint_names[3].find(
"THJ2") != std::string::npos);
217 EXPECT_TRUE(joint_names[4].find(
"THJ1") != std::string::npos);
224 robot_model::RobotModelPtr kinematic_model;
227 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf));
228 robot_model::JointModelGroup *joint_model_group = kinematic_model->getJointModelGroup(
231 std::vector<double> seed, fk_values, solution;
232 moveit_msgs::MoveItErrorCodes error_code;
235 std::vector<std::string> fk_names;
238 robot_state::RobotState kinematic_state(kinematic_model);
242 nh.
param(
"number_fk_tests", number_fk_tests, 100);
244 for (
unsigned int i = 0; i < (
unsigned int) number_fk_tests; ++i)
249 kinematic_state.setToRandomPositions(joint_model_group);
250 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
252 std::vector<geometry_msgs::Pose> poses;
254 bool result_fk = my_test.
kinematics_solver_->getPositionFK(fk_names, fk_values, poses);
255 ASSERT_TRUE(result_fk);
262 robot_model::RobotModelPtr kinematic_model;
265 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf_model));
266 robot_model::JointModelGroup *joint_model_group = kinematic_model->getJointModelGroup(
270 std::vector<double> seed, fk_values, solution;
271 double timeout = 5.0;
272 moveit_msgs::MoveItErrorCodes error_code;
275 std::vector<std::string> fk_names;
278 robot_state::RobotState kinematic_state(kinematic_model);
282 nh.
param(
"number_ik_tests", number_ik_tests, 10);
283 unsigned int success = 0;
288 for (
unsigned int i = 0; i < (
unsigned int) number_ik_tests; ++i)
292 kinematic_state.setToRandomPositions(joint_model_group);
293 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
296 if (joint_names[0].find(
"TH") == std::string::npos && joint_names[0].find(
"LF") == std::string::npos)
298 fk_values[3] = fk_values[2];
300 else if (joint_names[0].find(
"LF") != std::string::npos)
302 fk_values[4] = fk_values[3];
305 std::vector<geometry_msgs::Pose> poses;
307 bool result_fk = my_test.
kinematics_solver_->getPositionFK(fk_names, fk_values, poses);
308 ASSERT_TRUE(result_fk);
310 bool result = my_test.
kinematics_solver_->searchPositionIK(poses[0], seed, timeout, solution, error_code);
311 ROS_DEBUG(
"Pose: %f %f %f", poses[0].position.x, poses[0].position.y, poses[0].position.z);
312 ROS_DEBUG(
"Orient: %f %f %f %f", poses[0].orientation.x, poses[0].orientation.y, poses[0].orientation.z,
313 poses[0].orientation.w);
317 result = my_test.
kinematics_solver_->getPositionIK(poses[0], solution, solution, error_code);
322 if (fk_names[0].find(
"TH") != std::string::npos)
323 ROS_DEBUG(
"fk values: %f %f %f %f %f", fk_values[0], fk_values[1], fk_values[2], fk_values[3], fk_values[4]);
326 std::vector<geometry_msgs::Pose> new_poses;
334 ROS_INFO(
"Success Rate: %f", static_cast<double>(success / number_ik_tests));
335 bool success_count = (success > 0.99 * number_ik_tests);
340 TEST(HandIKPlugin, searchIKWithCallbacks)
343 robot_model::RobotModelPtr kinematic_model;
346 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf));
347 robot_model::JointModelGroup *joint_model_group = kinematic_model->getJointModelGroup(
351 std::vector<double> seed, fk_values, solution;
352 double timeout = 5.0;
353 moveit_msgs::MoveItErrorCodes error_code;
356 std::vector<std::string> fk_names;
359 robot_state::RobotState kinematic_state(kinematic_model);
363 nh.
param(
"number_ik_tests_with_callbacks", number_ik_tests, 10);
364 unsigned int success = 0;
365 unsigned int num_actual_tests = 0;
367 for (
unsigned int i = 0; i < (
unsigned int) number_ik_tests; ++i)
372 kinematic_state.setToRandomPositions(joint_model_group);
373 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
376 if (joint_names[0].find(
"TH") == std::string::npos && joint_names[0].find(
"LF") == std::string::npos)
378 fk_values[3] = fk_values[2];
380 else if (joint_names[0].find(
"LF") != std::string::npos)
382 fk_values[4] = fk_values[3];
385 std::vector<geometry_msgs::Pose> poses;
387 bool result_fk = my_test.
kinematics_solver_->getPositionFK(fk_names, fk_values, poses);
388 ASSERT_TRUE(result_fk);
389 if (poses[0].position.z < 0.0)
395 bool result = my_test.
kinematics_solver_->searchPositionIK(poses[0], seed, timeout, solution,
397 _2, _3), error_code);
402 std::vector<geometry_msgs::Pose> new_poses;
416 ROS_INFO(
"Success with callbacks (%%): %f", static_cast<double>(success / num_actual_tests) * 100.0);
420 int main(
int argc,
char **argv)
422 testing::InitGoogleTest(&argc, argv);
423 ros::init(argc, argv,
"right_hand_kinematics");
424 return RUN_ALL_TESTS();
const srdf::ModelSharedPtr & getSRDF() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
boost::shared_ptr< pluginlib::ClassLoader< kinematics::KinematicsBase > > kinematics_loader_
#define EXPECT_NEAR(a, b, prec)
void joint_state_callback(const geometry_msgs::Pose &ik_pose, const std::vector< double > &joint_state, moveit_msgs::MoveItErrorCodes &error_code)
TEST(HandIKPlugin, initialize)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const
#define EXPECT_TRUE(args)
kinematics::KinematicsBasePtr kinematics_solver_
const urdf::ModelInterfaceSharedPtr & getURDF() const