Skip to content

Commit 7499196

Browse files
rr-markmergify[bot]
authored andcommitted
Reverts #2985, Ports moveit #3388 #3470 #3539 (#3284)
* Revert "Fix RobotState::getRigidlyConnectedParentLinkModel() (#2985)" This reverts commit 1f23344. * Merge PR #3388: Generalize RobotState::setFromIK() So far, setFromIK only accepted target (link) frames that were rigidly connected to a solver's tip frame. This, for example, excluded the fingertip of an actuated gripper, because that would be separated by an active joint from the arm's tooltip. However, as long as this joint is not part of the JMG, the corresponding transform can be considered as fixed as well. This PR generalizes the functions getRigidlyConnectedParentLinkModel() in RobotState and RobotModel to receive an optional JMG pointer. If present, only (active) joints from that group are considered non-fixed. This PR also enables subframe support for setFromIK - simply by using getRigidlyConnectedParentLinkModel(), which already supported that. There is one drawback of this approach: A repeated application of setFromIK with the same target frame and JMG (as in computeCartesianPath()), will repeat the search for the common fixed parent link. Additionally, the passed RobotState needs to be up-to-date. We could mitigate this by pulling the corresponding code into a separate function and calling it once in computeCartesianPath(). * Merge PR #3470: Avoid global transforms in getRigidlyConnectedParentLinkModel() Fixes #3388 * Merge pull request #3539 from v4hn/find-links-with-slashes-again find links with slashes again * Ports to ROS2 and fixes problems introduced in merge conflicts. * Fixes formatting. * Makes robot_state_test.cpp include gmock. * Updates trajectory_msgs::JointTrajectory to trajectory_msgs::msg::JointTrajectory. * Adds braces to make clang-tidy happy. * Removes test-only arguments; adds more comments. * Fixes formatting. * Fixes formatting. * Adds missing class scope. --------- Co-authored-by: Robert Haschke <[email protected]> Co-authored-by: Robert Haschke <[email protected]> Co-authored-by: Michael Görner <[email protected]> Co-authored-by: Sebastian Jahr <[email protected]> (cherry picked from commit 1794b8e) # Conflicts: # moveit_core/robot_model/include/moveit/robot_model/robot_model.hpp # moveit_core/robot_state/CMakeLists.txt # moveit_core/robot_state/include/moveit/robot_state/attached_body.hpp # moveit_core/robot_state/include/moveit/robot_state/robot_state.hpp # moveit_core/robot_state/src/cartesian_interpolator.cpp # moveit_core/robot_state/src/robot_state.cpp # moveit_core/robot_state/test/robot_state_test.cpp
1 parent 77b646e commit 7499196

File tree

10 files changed

+3049
-55
lines changed

10 files changed

+3049
-55
lines changed

moveit_core/robot_model/include/moveit/robot_model/robot_model.hpp

Lines changed: 650 additions & 0 deletions
Large diffs are not rendered by default.

moveit_core/robot_model/src/robot_model.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,14 +1275,32 @@ LinkModel* RobotModel::getLinkModel(const std::string& name, bool* has_link)
12751275
return nullptr;
12761276
}
12771277

1278-
const LinkModel* RobotModel::getRigidlyConnectedParentLinkModel(const LinkModel* link)
1278+
const LinkModel* RobotModel::getRigidlyConnectedParentLinkModel(const LinkModel* link, const JointModelGroup* jmg)
12791279
{
12801280
if (!link)
12811281
return link;
1282+
12821283
const moveit::core::LinkModel* parent_link = link->getParentLinkModel();
12831284
const moveit::core::JointModel* joint = link->getParentJointModel();
1285+
decltype(jmg->getJointModels().cbegin()) begin{}, end{};
1286+
if (jmg)
1287+
{
1288+
begin = jmg->getJointModels().cbegin();
1289+
end = jmg->getJointModels().cend();
1290+
}
1291+
1292+
// Returns whether `joint` is part of the rigidly connected chain.
1293+
// This is only false if the joint is both in `jmg` and not fixed.
1294+
auto is_fixed_or_not_in_jmg = [begin, end](const JointModel* joint) {
1295+
if (joint->getType() == JointModel::FIXED)
1296+
return true;
1297+
if (begin != end && // we do have a non-empty jmg
1298+
std::find(begin, end, joint) == end) // joint does not belong to jmg
1299+
return true;
1300+
return false;
1301+
};
12841302

1285-
while (parent_link && joint->getType() == moveit::core::JointModel::FIXED)
1303+
while (parent_link && is_fixed_or_not_in_jmg(joint))
12861304
{
12871305
link = parent_link;
12881306
joint = link->getParentJointModel();

moveit_core/robot_state/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ if(BUILD_TESTING)
3535
set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_BINARY_DIR}/../utils")
3636
endif()
3737

38+
<<<<<<< HEAD
3839
ament_add_gtest(test_robot_state test/robot_state_test.cpp
3940
APPEND_LIBRARY_DIRS "${append_library_dirs}")
41+
=======
42+
ament_add_gmock(test_robot_state test/robot_state_test.cpp
43+
APPEND_LIBRARY_DIRS "${APPEND_LIBRARY_DIRS}")
44+
>>>>>>> 1794b8efa (Reverts #2985, Ports moveit #3388 #3470 #3539 (#3284))
4045

4146
target_link_libraries(test_robot_state
4247
moveit_test_utils
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2012, 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, Inc. 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+
37+
#pragma once
38+
39+
#include <moveit/robot_model/link_model.hpp>
40+
#include <moveit/transforms/transforms.hpp>
41+
#include <geometric_shapes/check_isometry.h>
42+
#include <eigen_stl_containers/eigen_stl_containers.h>
43+
#include <trajectory_msgs/msg/joint_trajectory.hpp>
44+
#include <set>
45+
#include <functional>
46+
47+
namespace moveit
48+
{
49+
namespace core
50+
{
51+
class AttachedBody;
52+
typedef std::function<void(AttachedBody* body, bool attached)> AttachedBodyCallback;
53+
54+
/** @brief Object defining bodies that can be attached to robot links.
55+
*
56+
* This is useful when handling objects picked up by the robot. */
57+
class AttachedBody
58+
{
59+
public:
60+
/** \brief Construct an attached body for a specified \e link.
61+
*
62+
* The name of this body is \e id and it consists of \e shapes that attach to the link by the transforms
63+
* \e shape_poses. The set of links that are allowed to be touched by this object is specified by \e touch_links.
64+
* detach_posture may describe a detach motion for the gripper when placing the object.
65+
* The shape and subframe poses are relative to the \e pose, and \e pose is relative to the parent link. */
66+
AttachedBody(const LinkModel* parent, const std::string& id, const Eigen::Isometry3d& pose,
67+
const std::vector<shapes::ShapeConstPtr>& shapes, const EigenSTL::vector_Isometry3d& shape_poses,
68+
const std::set<std::string>& touch_links, const trajectory_msgs::msg::JointTrajectory& detach_posture,
69+
const moveit::core::FixedTransformsMap& subframe_poses = moveit::core::FixedTransformsMap());
70+
71+
~AttachedBody();
72+
73+
/** \brief Get the name of the attached body */
74+
const std::string& getName() const
75+
{
76+
return id_;
77+
}
78+
79+
/** \brief Get the pose of the attached body relative to the parent link */
80+
const Eigen::Isometry3d& getPose() const
81+
{
82+
return pose_;
83+
}
84+
85+
/** \brief Get the pose of the attached body, relative to the world */
86+
const Eigen::Isometry3d& getGlobalPose() const
87+
{
88+
return global_pose_;
89+
}
90+
91+
/** \brief Get the name of the link this body is attached to */
92+
const std::string& getAttachedLinkName() const
93+
{
94+
return parent_link_model_->getName();
95+
}
96+
97+
/** \brief Get the model of the link this body is attached to */
98+
const LinkModel* getAttachedLink() const
99+
{
100+
return parent_link_model_;
101+
}
102+
103+
/** \brief Get the shapes that make up this attached body */
104+
const std::vector<shapes::ShapeConstPtr>& getShapes() const
105+
{
106+
return shapes_;
107+
}
108+
109+
/** \brief Get the shape poses (the transforms to the shapes of this body, relative to the pose). The returned
110+
* transforms are guaranteed to be valid isometries. */
111+
const EigenSTL::vector_Isometry3d& getShapePoses() const
112+
{
113+
return shape_poses_;
114+
}
115+
116+
/** \brief Get the links that the attached body is allowed to touch */
117+
const std::set<std::string>& getTouchLinks() const
118+
{
119+
return touch_links_;
120+
}
121+
122+
/** \brief Return the posture that is necessary for the object to be released, (if any). This is useful for example
123+
when storing the configuration of a gripper holding an object */
124+
const trajectory_msgs::msg::JointTrajectory& getDetachPosture() const
125+
{
126+
return detach_posture_;
127+
}
128+
129+
/** \brief Get the fixed transforms (the transforms to the shapes of this body, relative to the link). The returned
130+
* transforms are guaranteed to be valid isometries. */
131+
const EigenSTL::vector_Isometry3d& getShapePosesInLinkFrame() const
132+
{
133+
return shape_poses_in_link_frame_;
134+
}
135+
136+
/** \brief Get subframes of this object (relative to the object pose). The returned transforms are guaranteed to be
137+
* valid isometries. */
138+
const moveit::core::FixedTransformsMap& getSubframes() const
139+
{
140+
return subframe_poses_;
141+
}
142+
143+
/** \brief Get subframes of this object (in the world frame) */
144+
const moveit::core::FixedTransformsMap& getGlobalSubframeTransforms() const
145+
{
146+
return global_subframe_poses_;
147+
}
148+
149+
/** \brief Set all subframes of this object.
150+
*
151+
* Use these to define points of interest on the object to plan with
152+
* (e.g. screwdriver/tip, kettle/spout, mug/base).
153+
*/
154+
void setSubframeTransforms(const moveit::core::FixedTransformsMap& subframe_poses)
155+
{
156+
for (const auto& t : subframe_poses)
157+
{
158+
ASSERT_ISOMETRY(t.second) // unsanitized input, could contain a non-isometry
159+
}
160+
subframe_poses_ = subframe_poses;
161+
}
162+
163+
/** \brief Get the fixed transform to a named subframe on this body (relative to the body's pose)
164+
*
165+
* The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's
166+
* name is "screwdriver"). Returns an identity transform if frame_name is unknown (and set found to false).
167+
* The returned transform is guaranteed to be a valid isometry. */
168+
const Eigen::Isometry3d& getSubframeTransform(const std::string& frame_name, bool* found = nullptr) const;
169+
170+
/** \brief Get the fixed transform to a named subframe on this body, relative to the world frame.
171+
* The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's
172+
* name is "screwdriver"). Returns an identity transform if frame_name is unknown (and set found to false).
173+
* The returned transform is guaranteed to be a valid isometry. */
174+
const Eigen::Isometry3d& getGlobalSubframeTransform(const std::string& frame_name, bool* found = nullptr) const;
175+
176+
/** \brief Check whether a subframe of given @frame_name is present in this object.
177+
*
178+
* The frame_name needs to have the object's name prepended (e.g. "screwdriver/tip" returns true if the object's
179+
* name is "screwdriver"). */
180+
bool hasSubframeTransform(const std::string& frame_name) const;
181+
182+
/** \brief Get the global transforms (in world frame) for the collision bodies. The returned transforms are
183+
* guaranteed to be valid isometries. */
184+
const EigenSTL::vector_Isometry3d& getGlobalCollisionBodyTransforms() const
185+
{
186+
return global_collision_body_transforms_;
187+
}
188+
189+
/** \brief Set the padding for the shapes of this attached object */
190+
void setPadding(double padding);
191+
192+
/** \brief Set the scale for the shapes of this attached object */
193+
void setScale(double scale);
194+
195+
/** \brief Recompute global_collision_body_transform given the transform of the parent link */
196+
void computeTransform(const Eigen::Isometry3d& parent_link_global_transform);
197+
198+
private:
199+
/** \brief The link that owns this attached body */
200+
const LinkModel* parent_link_model_;
201+
202+
/** \brief string id for reference */
203+
std::string id_;
204+
205+
/** \brief The transform from the parent link to the attached body's pose*/
206+
Eigen::Isometry3d pose_;
207+
208+
/** \brief The transform from the model frame to the attached body's pose */
209+
Eigen::Isometry3d global_pose_;
210+
211+
/** \brief The geometries of the attached body */
212+
std::vector<shapes::ShapeConstPtr> shapes_;
213+
214+
/** \brief The transforms from the object's pose to the object's geometries*/
215+
EigenSTL::vector_Isometry3d shape_poses_;
216+
217+
/** \brief The transforms from the link to the object's geometries*/
218+
EigenSTL::vector_Isometry3d shape_poses_in_link_frame_;
219+
220+
/** \brief The global transforms for the attached bodies (computed by forward kinematics) */
221+
EigenSTL::vector_Isometry3d global_collision_body_transforms_;
222+
223+
/** \brief The set of links this body is allowed to touch */
224+
std::set<std::string> touch_links_;
225+
226+
/** \brief Posture of links for releasing the object (if any). This is useful for example when storing
227+
the configuration of a gripper holding an object */
228+
trajectory_msgs::msg::JointTrajectory detach_posture_;
229+
230+
/** \brief Transforms to subframes on the object, relative to the object's pose. */
231+
moveit::core::FixedTransformsMap subframe_poses_;
232+
233+
/** \brief Transforms to subframes on the object, relative to the model frame. */
234+
moveit::core::FixedTransformsMap global_subframe_poses_;
235+
};
236+
} // namespace core
237+
} // namespace moveit

0 commit comments

Comments
 (0)