kinematics_speed_and_validity_evaluator.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
40 #include <ros/ros.h>
41 
42 static const std::string ROBOT_DESCRIPTION = "robot_description";
43 
44 int main(int argc, char** argv)
45 {
46  ros::init(argc, argv, "inverse_kinematics_test");
47 
49  spinner.start();
50 
51  if (argc <= 1)
52  ROS_ERROR("An argument specifying the group name is needed");
53  else
54  {
56  std::string group = argv[1];
57  ROS_INFO_STREAM("Evaluating IK for " << group);
58 
59  const robot_model::JointModelGroup* jmg = rml.getModel()->getJointModelGroup(group);
60  if (jmg)
61  {
62  const kinematics::KinematicsBaseConstPtr& solver = jmg->getSolverInstance();
63  if (solver)
64  {
65  const std::string& tip = solver->getTipFrame();
66  robot_state::RobotState state(rml.getModel());
67  state.setToDefaultValues();
68 
69  ROS_INFO_STREAM("Tip Frame: " << solver->getTipFrame());
70  ROS_INFO_STREAM("Base Frame: " << solver->getBaseFrame());
71  ROS_INFO_STREAM("IK Timeout: " << solver->getDefaultTimeout());
72  ROS_INFO_STREAM("Search res: " << solver->getSearchDiscretization());
73 
74  unsigned int test_count = 1000;
75  if (argc > 2)
76  try
77  {
78  test_count = boost::lexical_cast<unsigned int>(argv[2]);
79  }
80  catch (...)
81  {
82  }
83 
84  ROS_INFO("Running %u tests", test_count);
85 
87  for (unsigned int i = 0; i < test_count; ++i)
88  {
89  state.setToRandomPositions(jmg);
90  Eigen::Affine3d pose = state.getGlobalLinkTransform(tip);
91  state.setToRandomPositions(jmg);
93  state.setFromIK(jmg, pose);
95  const Eigen::Affine3d& pose_upd = state.getGlobalLinkTransform(tip);
96  Eigen::Affine3d diff = pose_upd * pose.inverse(Eigen::Isometry);
97  double rot_err = (diff.linear() - Eigen::Matrix3d::Identity()).norm();
98  double trans_err = diff.translation().norm();
99  moveit::tools::Profiler::Average("Rotation error", rot_err);
100  moveit::tools::Profiler::Average("Translation error", trans_err);
101  if (rot_err < 1e-3 && trans_err < 1e-3)
102  {
103  moveit::tools::Profiler::Event("Valid IK");
104  moveit::tools::Profiler::Average("Success Rate", 100);
105  }
106  else
107  {
108  moveit::tools::Profiler::Event("Invalid IK");
109  moveit::tools::Profiler::Average("Success Rate", 0);
110  }
111  }
114  }
115  else
116  ROS_ERROR_STREAM("No kinematics solver specified for group " << group);
117  }
118  }
119 
120  ros::shutdown();
121  return 0;
122 }
static void Stop(void)
static void Start(void)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static void Average(const std::string &name, const double value)
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
static void Begin(const std::string &name)
int main(int argc, char **argv)
void spinner()
static void End(const std::string &name)
#define ROS_INFO(...)
#define ROS_INFO_STREAM(args)
static void Event(const std::string &name, const unsigned int times=1)
ROSCPP_DECL void shutdown()
const robot_model::RobotModelPtr & getModel() const
Get the constructed planning_models::RobotModel.
#define ROS_ERROR_STREAM(args)
static void Status(std::ostream &out=std::cout, bool merge=true)
#define ROS_ERROR(...)
static const std::string ROBOT_DESCRIPTION


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:17:33