kinematic_options.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, SRI International
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: Acorn Pooley */
36 
38 #include <boost/static_assert.hpp>
39 #include <ros/console.h>
40 
42  : timeout_seconds_(0.0) // 0.0 = use default timeout
43  , max_attempts_(0) // 0 = use default max attempts
44 {
45 }
46 
47 // This is intended to be called as a ModifyStateFunction to modify the state
48 // maintained by a LockedRobotState in place.
49 bool robot_interaction::KinematicOptions::setStateFromIK(robot_state::RobotState& state, const std::string& group,
50  const std::string& tip, const geometry_msgs::Pose& pose) const
51 {
52  const robot_model::JointModelGroup* jmg = state.getJointModelGroup(group);
53  if (!jmg)
54  {
55  ROS_ERROR("No getJointModelGroup('%s') found", group.c_str());
56  return false;
57  }
58  bool result = state.setFromIK(jmg, pose, tip, max_attempts_, timeout_seconds_, state_validity_callback_, options_);
59  state.update();
60  return result;
61 }
62 
64 {
65 // This function is implemented with the O_FIELDS and QO_FIELDS macros to
66 // ensure that any fields added to robot_interaction::KinematicOptions or
67 // kinematics::KinematicsQueryOptions are also added here and to the
68 // KinematicOptions::OptionBitmask enum.
69 
70 // This needs to represent all the fields in
71 // robot_interaction::KinematicOptions except options_
72 #define O_FIELDS(F) \
73  F(double, timeout_seconds_, TIMEOUT) \
74  F(unsigned int, max_attempts_, MAX_ATTEMPTS) \
75  F(robot_state::GroupStateValidityCallbackFn, state_validity_callback_, STATE_VALIDITY_CALLBACK)
76 
77 // This needs to represent all the fields in
78 // kinematics::KinematicsQueryOptions
79 #define QO_FIELDS(F) \
80  F(bool, lock_redundant_joints, LOCK_REDUNDANT_JOINTS) \
81  F(bool, return_approximate_solution, RETURN_APPROXIMATE_SOLUTION) \
82  F(::kinematics::DiscretizationMethods::DiscretizationMethod, discretization_method, DISCRETIZATION_METHOD)
83 
84  // This structure should be identical to kinematics::KinematicsQueryOptions
85  // This is only used in the BOOST_STATIC_ASSERT below.
86  struct DummyKinematicsQueryOptions
87  {
88 #define F(type, member, enumval) type member;
89  QO_FIELDS(F)
90 #undef F
91  };
92  // This structure should be identical to robot_interaction::KinematicOptions
93  // This is only used in the BOOST_STATIC_ASSERT below.
94  struct DummyKinematicOptions
95  {
96 #define F(type, member, enumval) type member;
97  O_FIELDS(F)
98 #undef F
99  DummyKinematicsQueryOptions options_;
100  };
101 
102  // If these asserts fails it means that fields were added to
103  // kinematics::KinematicsQueryOptions or robot_interaction::KinematicOptions
104  // and not added to the O_FIELDS and QO_FIELDS definitions above. To fix add
105  // any new fields to the definitions above.
106  BOOST_STATIC_ASSERT(sizeof(kinematics::KinematicsQueryOptions) == sizeof(DummyKinematicsQueryOptions));
107  BOOST_STATIC_ASSERT(sizeof(KinematicOptions) == sizeof(DummyKinematicOptions));
108 
109 // copy fields from other to this if its bit is set in fields
110 #define F(type, member, enumval) \
111  if (fields & KinematicOptions::enumval) \
112  member = source.member;
113  O_FIELDS(F)
114 #undef F
115 
116 // copy fields from other.options_ to this.options_ if its bit is set in
117 // fields
118 #define F(type, member, enumval) \
119  if (fields & KinematicOptions::enumval) \
120  options_.member = source.options_.member;
121  QO_FIELDS(F)
122 #undef F
123 }
robot_state::GroupStateValidityCallbackFn state_validity_callback_
This is called to determine if the state is valid.
#define F(type, member, enumval)
#define QO_FIELDS(F)
void setOptions(const KinematicOptions &source, OptionBitmask fields=ALL)
double timeout_seconds_
max time an IK attempt can take before we give up.
#define O_FIELDS(F)
KinematicOptions()
Constructor - set all options to reasonable default values.
kinematics::KinematicsQueryOptions options_
other options
unsigned int max_attempts_
how many attempts before we give up.
#define ROS_ERROR(...)
bool setStateFromIK(robot_state::RobotState &state, const std::string &group, const std::string &tip, const geometry_msgs::Pose &pose) const


robot_interaction
Author(s): Ioan Sucan
autogenerated on Wed Jul 10 2019 04:04:01