moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
tf_publisher_capability.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2019, Hamburg University
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 Hamburg University 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: Jonas Tietz */
36
38
39#include <rclcpp/version.h>
40
44// For Rolling, Kilted, and newer
45#if RCLCPP_VERSION_GTE(29, 6, 0)
46#include <tf2_ros/transform_broadcaster.hpp>
47// For Jazzy and older
48#else
49#include <tf2_ros/transform_broadcaster.h>
50#endif
51#include <tf2_eigen/tf2_eigen.hpp>
55
56namespace move_group
57{
58
62
64{
65 keep_running_ = false;
66 thread_.join();
67}
68
69namespace
70{
71void publishSubframes(tf2_ros::TransformBroadcaster& broadcaster, const moveit::core::FixedTransformsMap& subframes,
72 const std::string& parent_object, const rclcpp::Time& stamp)
73{
74 geometry_msgs::msg::TransformStamped transform;
75 for (auto& subframe : subframes)
76 {
77 transform = tf2::eigenToTransform(subframe.second);
78 transform.child_frame_id = parent_object + "/" + subframe.first;
79 transform.header.stamp = stamp;
80 transform.header.frame_id = parent_object;
81 broadcaster.sendTransform(transform);
82 }
83}
84} // namespace
85
86void TfPublisher::publishPlanningSceneFrames()
87{
88// For Rolling, L-turtle, and newer
89#if RCLCPP_VERSION_GTE(30, 0, 0)
90 tf2_ros::TransformBroadcaster broadcaster(tf2_ros::TransformBroadcaster::RequiredInterfaces{
91 context_->moveit_cpp_->getNode()->get_node_parameters_interface(),
92 context_->moveit_cpp_->getNode()->get_node_topics_interface() });
93#else
94 tf2_ros::TransformBroadcaster broadcaster(context_->moveit_cpp_->getNode());
95#endif
96 geometry_msgs::msg::TransformStamped transform;
97 rclcpp::Rate rate(rate_);
98
99 while (keep_running_)
100 {
101 {
102 rclcpp::Time stamp = context_->moveit_cpp_->getNode()->get_clock()->now();
103 planning_scene_monitor::LockedPlanningSceneRO locked_planning_scene(context_->planning_scene_monitor_);
104 collision_detection::WorldConstPtr world = locked_planning_scene->getWorld();
105 std::string planning_frame = locked_planning_scene->getPlanningFrame();
106
107 for (const auto& obj : *world)
108 {
109 std::string object_frame = prefix_ + obj.second->id_;
110 transform = tf2::eigenToTransform(obj.second->pose_);
111 transform.child_frame_id = object_frame;
112 transform.header.stamp = stamp;
113 transform.header.frame_id = planning_frame;
114 broadcaster.sendTransform(transform);
115
116 const moveit::core::FixedTransformsMap& subframes = obj.second->subframe_poses_;
117 publishSubframes(broadcaster, subframes, object_frame, stamp);
118 }
119
120 const moveit::core::RobotState& rs = locked_planning_scene->getCurrentState();
121 std::vector<const moveit::core::AttachedBody*> attached_collision_objects;
122 rs.getAttachedBodies(attached_collision_objects);
123 for (const moveit::core::AttachedBody* attached_body : attached_collision_objects)
124 {
125 std::string object_frame = prefix_ + attached_body->getName();
126 transform = tf2::eigenToTransform(attached_body->getPose());
127 transform.child_frame_id = object_frame;
128 transform.header.stamp = stamp;
129 transform.header.frame_id = attached_body->getAttachedLinkName();
130 broadcaster.sendTransform(transform);
131
132 const moveit::core::FixedTransformsMap& subframes = attached_body->getSubframes();
133 publishSubframes(broadcaster, subframes, object_frame, stamp);
134 }
135 }
136
137 rate.sleep();
138 }
139}
140
142{
143 std::string prefix = context_->moveit_cpp_->getNode()->get_name();
144 context_->moveit_cpp_->getNode()->get_parameter_or("planning_scene_frame_publishing_rate", rate_, 10);
145 context_->moveit_cpp_->getNode()->get_parameter_or("planning_scene_tf_prefix", prefix_, prefix);
146 if (!prefix_.empty())
147 prefix_ += "/";
148
149 keep_running_ = true;
150
151 RCLCPP_INFO(moveit::getLogger("moveit.ros.move_group.tf_publisher"),
152 "Initializing MoveGroupTfPublisher with a frame publishing rate of %d", rate_);
153 thread_ = std::thread(&TfPublisher::publishPlanningSceneFrames, this);
154}
155} // namespace move_group
156
157#include <pluginlib/class_list_macros.hpp>
158
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
Object defining bodies that can be attached to robot links.
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void getAttachedBodies(std::vector< const AttachedBody * > &attached_bodies) const
Get all bodies attached to the model corresponding to this state.
This is a convenience class for obtaining access to an instance of a locked PlanningScene.
std::map< std::string, Eigen::Isometry3d, std::less< std::string >, Eigen::aligned_allocator< std::pair< const std::string, Eigen::Isometry3d > > > FixedTransformsMap
Map frame names to the transformation matrix that can transform objects from the frame name to the pl...
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
Definition logger.cpp:79