helpers.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2012-2016, Institute of Flight Systems and Automatic Control,
3 // Technische Universität Darmstadt.
4 // All rights reserved.
5 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of hector_quadrotor nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
30 #include <urdf_parser/urdf_parser.h>
31 
33 {
34 
35 bool getMassAndInertia(const ros::NodeHandle &nh, double &mass, double inertia[3])
36 {
37 
38  std::string robot_description;
39  if (!nh.getParam("robot_description", robot_description))
40  {
41  ROS_ERROR_STREAM("getMassAndInertia() couldn't find URDF at " << nh.getNamespace() << "/robot_description");
42  return false;
43  }
44 
45  urdf::ModelInterfaceSharedPtr model;
46  try
47  {
48  model = urdf::parseURDF(robot_description);
49  }
50  catch (std::exception ex)
51  {
53  "getMassAndInertia() couldn't parse URDF at " << nh.getNamespace() << "/robot_description: " << ex.what());
54  return false;
55  }
56 
57  urdf::InertialSharedPtr inertial = model->getRoot()->inertial;
58  if (!inertial || !inertial->mass || !inertial->ixx || !inertial->iyy || !inertial->izz)
59  {
61  "getMassAndInertia() requires inertial information stored on the root link " << nh.getNamespace() <<
62  "/robot_description");
63  return false;
64  }
65 
66  mass = inertial->mass;
67  inertia[0] = inertial->ixx;
68  inertia[1] = inertial->iyy;
69  inertia[2] = inertial->izz;
70  return true;
71 }
72 
73 bool poseWithinTolerance(const geometry_msgs::Pose &pose_current, const geometry_msgs::Pose &pose_target,
74  const double dist_tolerance, const double yaw_tolerance)
75 {
76 
77  if(yaw_tolerance > 0.0)
78  {
79  double yaw_current, yaw_target;
81  double temp;
82  tf2::fromMsg(pose_current.orientation, q);
83  tf2::Matrix3x3(q).getRPY(temp, temp, yaw_current);
84  tf2::fromMsg(pose_target.orientation, q);
85  tf2::Matrix3x3(q).getRPY(temp, temp, yaw_target);
86 
87  double yaw_error = yaw_current - yaw_target;
88  // detect wrap around pi and compensate
89  if (yaw_error > M_PI)
90  {
91  yaw_error -= 2 * M_PI;
92  }
93  else if (yaw_error < -M_PI)
94  {
95  yaw_error += 2 * M_PI;
96  }
97  if (std::abs(yaw_error) > yaw_tolerance)
98  {
99  ROS_DEBUG_STREAM("Waiting for yaw " << std::abs(yaw_current - yaw_target));
100  return false;
101  }
102 
103  }
104 
105  if(dist_tolerance > 0.0)
106  {
107  tf2::Vector3 v_current(pose_current.position.x, pose_current.position.y, pose_current.position.z);
108  tf2::Vector3 v_target(pose_target.position.x, pose_target.position.y, pose_target.position.z);
109  if ((v_current - v_target).length() > dist_tolerance)
110  {
111  ROS_DEBUG_STREAM("Waiting for distance " << (v_current - v_target).length());
112  return false;
113  }
114  }
115 
116  return true;
117 
118 }
119 
120 } // namespace hector_quadrotor_interface
void getRPY(tf2Scalar &roll, tf2Scalar &pitch, tf2Scalar &yaw, unsigned int solution_number=1) const
bool poseWithinTolerance(const geometry_msgs::Pose &pose_current, const geometry_msgs::Pose &pose_target, const double dist_tolerance, const double yaw_tolerance)
Definition: helpers.cpp:73
TF2SIMD_FORCE_INLINE tf2Scalar length(const Quaternion &q)
void fromMsg(const A &, B &b)
const std::string & getNamespace() const
#define ROS_DEBUG_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
bool getMassAndInertia(const ros::NodeHandle &nh, double &mass, double inertia[3])
Definition: helpers.cpp:35
#define ROS_ERROR_STREAM(args)


hector_quadrotor_interface
Author(s): Johannes Meyer , Paul Bovbel
autogenerated on Mon Jun 10 2019 13:36:46