moveit2
The MoveIt Motion Planning Framework for ROS 2.
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 <rclcpp/logging.hpp>
39 
40 static const rclcpp::Logger LOGGER = rclcpp::get_logger("moveit_ros_robot_interaction.kinematic_options");
41 
42 robot_interaction::KinematicOptions::KinematicOptions() : timeout_seconds_(0.0) // 0.0 = use default timeout
43 {
44 }
45 
46 // This is intended to be called as a ModifyStateFunction to modify the state
47 // maintained by a LockedRobotState in place.
49  const std::string& tip,
50  const geometry_msgs::msg::Pose& pose) const
51 {
53  if (!jmg)
54  {
55  RCLCPP_ERROR(LOGGER, "No getJointModelGroup('%s') found", group.c_str());
56  return false;
57  }
58  bool result = state.setFromIK(jmg, pose, tip,
59  // limit timeout to 0.1s if set from JMG's default, i.e. when timeout_seconds_ == 0
60  timeout_seconds_ > 0.0 ? timeout_seconds_ : std::min(0.1, jmg->getDefaultIKTimeout()),
61  state_validity_callback_, options_);
62  state.update();
63  return result;
64 }
65 
67 {
68 // This function is implemented with the O_FIELDS and QO_FIELDS macros to
69 // ensure that any fields added to robot_interaction::KinematicOptions or
70 // kinematics::KinematicsQueryOptions are also added here and to the
71 // KinematicOptions::OptionBitmask enum.
72 
73 // This needs to represent all the fields in
74 // robot_interaction::KinematicOptions except options_
75 #define O_FIELDS(F) \
76  F(double, timeout_seconds_, TIMEOUT) \
77  F(moveit::core::GroupStateValidityCallbackFn, state_validity_callback_, STATE_VALIDITY_CALLBACK)
78 
79 // This needs to represent all the fields in
80 // kinematics::KinematicsQueryOptions
81 #define QO_FIELDS(F) \
82  F(bool, lock_redundant_joints, LOCK_REDUNDANT_JOINTS) \
83  F(bool, return_approximate_solution, RETURN_APPROXIMATE_SOLUTION) \
84  F(::kinematics::DiscretizationMethods::DiscretizationMethod, discretization_method, DISCRETIZATION_METHOD)
85 
86  // This structure should be identical to kinematics::KinematicsQueryOptions
87  // This is only used in the static_assert below.
88  struct DummyKinematicsQueryOptions
89  {
90 #define F(type, member, enumval) type member;
91  QO_FIELDS(F)
92 #undef F
93  };
94  // This structure should be identical to robot_interaction::KinematicOptions
95  // This is only used in the static_assert below.
96  struct DummyKinematicOptions
97  {
98 #define F(type, member, enumval) type member;
99  O_FIELDS(F)
100 #undef F
101  DummyKinematicsQueryOptions options_;
102  };
103 
104  // If these asserts fails it means that fields were added to
105  // kinematics::KinematicsQueryOptions or robot_interaction::KinematicOptions
106  // and not added to the O_FIELDS and QO_FIELDS definitions above. To fix add
107  // any new fields to the definitions above.
108  static_assert(sizeof(kinematics::KinematicsQueryOptions) == sizeof(DummyKinematicsQueryOptions));
109  static_assert(sizeof(KinematicOptions) == sizeof(DummyKinematicOptions));
110 
111 // copy fields from other to this if its bit is set in fields
112 #define F(type, member, enumval) \
113  if (fields & KinematicOptions::enumval) \
114  member = source.member;
115  O_FIELDS(F)
116 #undef F
117 
118 // copy fields from other.options_ to this.options_ if its bit is set in
119 // fields
120 #define F(type, member, enumval) \
121  if (fields & KinematicOptions::enumval) \
122  options_.member = source.options_.member;
123  QO_FIELDS(F)
124 #undef F
125 }
double getDefaultIKTimeout() const
Get the default IK timeout.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
Definition: robot_state.h:90
const JointModelGroup * getJointModelGroup(const std::string &group) const
Get the model of a particular joint group.
Definition: robot_state.h:134
void update(bool force=false)
Update all transforms.
bool setFromIK(const JointModelGroup *group, const geometry_msgs::msg::Pose &pose, double timeout=0.0, const GroupStateValidityCallbackFn &constraint=GroupStateValidityCallbackFn(), const kinematics::KinematicsQueryOptions &options=kinematics::KinematicsQueryOptions(), const kinematics::KinematicsBase::IKCostFn &cost_function=kinematics::KinematicsBase::IKCostFn())
If the group this state corresponds to is a chain and a solver is available, then the joint values ca...
#define QO_FIELDS(F)
#define O_FIELDS(F)
#define F(type, member, enumval)
const rclcpp::Logger LOGGER
Definition: async_test.h:31
A set of options for the kinematics solver.
void setOptions(const KinematicOptions &source, OptionBitmask fields=ALL)
bool setStateFromIK(moveit::core::RobotState &state, const std::string &group, const std::string &tip, const geometry_msgs::msg::Pose &pose) const
KinematicOptions()
Constructor - set all options to reasonable default values.