38 #include <gtest/gtest.h> 50 #define IK_NEAR_TRANSLATE 1e-5 57 double search_discretization;
61 std::string plugin_name;
62 if (!nh.
getParam(
"plugin_name", plugin_name))
63 throw std::runtime_error(
"No plugin name found on parameter server");
64 ROS_INFO(
"Plugin name: %s", plugin_name.c_str());
68 std::string root_name, tip_name;
69 if (!nh.
getParam(
"root_name", root_name))
70 throw std::runtime_error(
"No root name found on parameter server");
72 if (!nh.
getParam(
"tip_name", tip_name))
73 throw std::runtime_error(
"No tip name found on parameter server");
75 if (!nh.
getParam(
"search_discretization", search_discretization))
76 throw std::runtime_error(
"No search discretization found on parameter server");
79 kinematics_solver_->initialize(
"robot_description",
"right_arm", root_name, tip_name, search_discretization));
83 moveit_msgs::MoveItErrorCodes& error_code)
85 std::vector<std::string> link_names;
86 link_names.push_back(
"r_elbow_flex_link");
87 std::vector<geometry_msgs::Pose> solutions;
90 error_code.val = error_code.PLANNING_FAILED;
91 if (solutions[0].position.z > 0.0)
92 error_code.val = error_code.SUCCESS;
94 error_code.val = error_code.PLANNING_FAILED;
105 EXPECT_TRUE(root_name == std::string(
"torso_lift_link"));
107 EXPECT_TRUE(tool_name == std::string(
"r_wrist_roll_link"));
111 EXPECT_EQ(joint_names[0],
"r_shoulder_pan_joint");
112 EXPECT_EQ(joint_names[1],
"r_shoulder_lift_joint");
113 EXPECT_EQ(joint_names[2],
"r_upper_arm_roll_joint");
114 EXPECT_EQ(joint_names[3],
"r_elbow_flex_joint");
115 EXPECT_EQ(joint_names[4],
"r_forearm_roll_joint");
116 EXPECT_EQ(joint_names[5],
"r_wrist_flex_joint");
117 EXPECT_EQ(joint_names[6],
"r_wrist_roll_joint");
123 robot_model::RobotModelPtr kinematic_model;
125 const urdf::ModelInterfaceSharedPtr& urdf_model = rdf_loader_.
getURDF();
126 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf));
127 robot_model::JointModelGroup* joint_model_group =
130 std::vector<double> seed, fk_values, solution;
131 moveit_msgs::MoveItErrorCodes error_code;
134 std::vector<std::string> fk_names;
137 robot_state::RobotState kinematic_state(kinematic_model);
141 nh.
param(
"number_fk_tests", number_fk_tests, 100);
143 for (
unsigned int i = 0; i < (
unsigned int)number_fk_tests; ++i)
148 kinematic_state.setToRandomPositions(joint_model_group);
149 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
151 std::vector<geometry_msgs::Pose> poses;
154 ASSERT_TRUE(result_fk);
161 robot_model::RobotModelPtr kinematic_model;
163 const urdf::ModelInterfaceSharedPtr& urdf_model = rdf_loader_.
getURDF();
164 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf_model));
165 robot_model::JointModelGroup* joint_model_group =
169 std::vector<double> seed, fk_values, solution;
170 double timeout = 5.0;
171 moveit_msgs::MoveItErrorCodes error_code;
174 std::vector<std::string> fk_names;
177 robot_state::RobotState kinematic_state(kinematic_model);
183 nh.
param(
"number_ik_tests", number_ik_tests, 10);
184 unsigned int success = 0;
187 for (
unsigned int i = 0; i < (
unsigned int)number_ik_tests; ++i)
192 kinematic_state.setToRandomPositions(joint_model_group);
193 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
195 std::vector<geometry_msgs::Pose> poses;
198 ASSERT_TRUE(result_fk);
200 bool result =
kinematics_solver_->searchPositionIK(poses[0], seed, timeout, solution, error_code);
201 ROS_DEBUG(
"Pose: %f %f %f", poses[0].position.x, poses[0].position.y, poses[0].position.z);
202 ROS_DEBUG(
"Orient: %f %f %f %f", poses[0].orientation.x, poses[0].orientation.y, poses[0].orientation.z,
203 poses[0].orientation.w);
211 std::vector<geometry_msgs::Pose> new_poses;
224 ROS_INFO(
"Success Rate: %f", (
double)success / number_ik_tests);
225 bool success_count = (success > 0.99 * number_ik_tests);
233 robot_model::RobotModelPtr kinematic_model;
235 const urdf::ModelInterfaceSharedPtr& urdf_model = rdf_loader_.
getURDF();
236 kinematic_model.reset(
new robot_model::RobotModel(urdf_model, srdf));
237 robot_model::JointModelGroup* joint_model_group =
241 std::vector<double> seed, fk_values, solution;
242 double timeout = 5.0;
243 moveit_msgs::MoveItErrorCodes error_code;
246 std::vector<std::string> fk_names;
249 robot_state::RobotState kinematic_state(kinematic_model);
253 nh.
param(
"number_ik_tests_with_callbacks", number_ik_tests, 10);
254 unsigned int success = 0;
255 unsigned int num_actual_tests = 0;
257 for (
unsigned int i = 0; i < (
unsigned int)number_ik_tests; ++i)
262 kinematic_state.setToRandomPositions(joint_model_group);
263 kinematic_state.copyJointGroupPositions(joint_model_group, fk_values);
265 std::vector<geometry_msgs::Pose> poses;
268 ASSERT_TRUE(result_fk);
269 if (poses[0].position.z < 0.0)
280 std::vector<geometry_msgs::Pose> new_poses;
297 ROS_INFO(
"Success with callbacks (%%): %f", (
double)success / num_actual_tests * 100.0);
300 int main(
int argc,
char** argv)
302 testing::InitGoogleTest(&argc, argv);
303 ros::init(argc, argv,
"right_arm_kinematics");
304 return RUN_ALL_TESTS();
TEST_F(ArmIKPlugin, initialize)
void joint_state_callback(const geometry_msgs::Pose &ik_pose, const std::vector< double > &joint_state, moveit_msgs::MoveItErrorCodes &error_code)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::shared_ptr< pluginlib::ClassLoader< kinematics::KinematicsBase > > kinematics_loader_
#define EXPECT_NEAR(a, b, prec)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
bool getParam(const std::string &key, std::string &s) const
const srdf::ModelSharedPtr & getSRDF() const
const urdf::ModelInterfaceSharedPtr & getURDF() const
int main(int argc, char **argv)
std::shared_ptr< Model > ModelSharedPtr
#define EXPECT_TRUE(args)
boost::shared_ptr< kinematics::KinematicsBase > kinematics_solver_