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 
41 robot_interaction::KinematicOptions::KinematicOptions() : timeout_seconds_(0.0) // 0.0 = use default timeout
42 {
43 }
44 
45 // This is intended to be called as a ModifyStateFunction to modify the state
46 // maintained by a LockedRobotState in place.
48  const std::string& tip, const geometry_msgs::Pose& pose) const
49 {
50  const moveit::core::JointModelGroup* jmg = state.getJointModelGroup(group);
51  if (!jmg)
52  {
53  ROS_ERROR("No getJointModelGroup('%s') found", group.c_str());
54  return false;
55  }
56  bool result = state.setFromIK(jmg, pose, tip,
57  // limit timeout to 0.1s if set from JMG's default, i.e. when timeout_seconds_ == 0
58  timeout_seconds_ > 0.0 ? timeout_seconds_ : std::min(0.1, jmg->getDefaultIKTimeout()),
59  state_validity_callback_, options_);
60  state.update();
61  return result;
62 }
63 
65 {
66 // This function is implemented with the O_FIELDS and QO_FIELDS macros to
67 // ensure that any fields added to robot_interaction::KinematicOptions or
68 // kinematics::KinematicsQueryOptions are also added here and to the
69 // KinematicOptions::OptionBitmask enum.
70 
71 // This needs to represent all the fields in
72 // robot_interaction::KinematicOptions except options_
73 #define O_FIELDS(F) \
74  F(double, timeout_seconds_, TIMEOUT) \
75  F(moveit::core::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_interaction::KinematicOptions::OptionBitmask
OptionBitmask
Definition: kinematic_options.h:120
robot_interaction::KinematicOptions::setOptions
void setOptions(const KinematicOptions &source, OptionBitmask fields=ALL)
Definition: kinematic_options.cpp:64
O_FIELDS
#define O_FIELDS(F)
moveit::core::RobotState
moveit::core::RobotState::setFromIK
bool setFromIK(const JointModelGroup *group, const geometry_msgs::Pose &pose, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions())
robot_interaction::KinematicOptions::KinematicOptions
KinematicOptions()
Constructor - set all options to reasonable default values.
Definition: kinematic_options.cpp:41
console.h
moveit::core::RobotState::update
void update(bool force=false)
ROS_ERROR
#define ROS_ERROR(...)
moveit::core::JointModelGroup::getDefaultIKTimeout
double getDefaultIKTimeout() const
kinematics::KinematicsQueryOptions
robot_interaction::KinematicOptions
Definition: kinematic_options.h:80
robot_interaction::KinematicOptions::setStateFromIK
bool setStateFromIK(moveit::core::RobotState &state, const std::string &group, const std::string &tip, const geometry_msgs::Pose &pose) const
Definition: kinematic_options.cpp:47
moveit::core::JointModelGroup
kinematic_options.h
moveit::core::RobotState::getJointModelGroup
const JointModelGroup * getJointModelGroup(const std::string &group) const
F
#define F(type, member, enumval)
QO_FIELDS
#define QO_FIELDS(F)


robot_interaction
Author(s): Ioan Sucan
autogenerated on Sat Mar 15 2025 02:26:54