tf2_ros  master
This package contains the ROS bindings for the tf2 library, for both Python and C++.
buffer_server.h
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Eitan Marder-Eppstein
36 *********************************************************************/
37 #ifndef TF2_ROS_BUFFER_SERVER_H_
38 #define TF2_ROS_BUFFER_SERVER_H_
39 #include <memory>
40 #include <string>
41 
42 #include <geometry_msgs/msg/transform_stamped.hpp>
43 #include <rclcpp/create_timer.hpp>
44 #include <rclcpp/rclcpp.hpp>
45 #include <rclcpp_action/rclcpp_action.hpp>
46 #include <tf2_msgs/action/lookup_transform.hpp>
47 
48 #include <tf2/buffer_core_interface.h>
50 
51 namespace tf2_ros
52 {
58  class BufferServer
59  {
60  private:
61  using LookupTransformAction = tf2_msgs::action::LookupTransform;
63 
64  struct GoalInfo
65  {
66  GoalHandle handle;
67  tf2::TimePoint end_time;
68  };
69 
70  public:
77  template<typename NodePtr>
79  const tf2::BufferCoreInterface& buffer,
80  NodePtr node,
81  const std::string& ns,
82  tf2::Duration check_period = tf2::durationFromSec(0.01))
83  : buffer_(buffer),
84  logger_(node->get_logger())
85  {
86  using namespace std::placeholders;
87 
88  server_ = rclcpp_action::create_server<LookupTransformAction>(
89  node,
90  ns,
91  std::bind(&BufferServer::goalCB, this, _1, _2),
92  std::bind(&BufferServer::cancelCB, this, _1),
93  std::bind(&BufferServer::acceptedCB, this, _1));
94 
95  check_timer_ = rclcpp::create_timer(
96  node, node->get_clock(), check_period, std::bind(&BufferServer::checkTransforms, this));
97  RCLCPP_DEBUG(logger_, "Buffer server started");
98  }
99 
100  private:
102  rclcpp_action::GoalResponse goalCB(
103  const rclcpp_action::GoalUUID & uuid, std::shared_ptr<const LookupTransformAction::Goal> goal);
104 
106  void acceptedCB(GoalHandle gh);
107 
109  rclcpp_action::CancelResponse cancelCB(GoalHandle gh);
110 
112  void checkTransforms();
113 
115  bool canTransform(GoalHandle gh);
116 
118  geometry_msgs::msg::TransformStamped lookupTransform(GoalHandle gh);
119 
120  const tf2::BufferCoreInterface& buffer_;
121  rclcpp::Logger logger_;
122  rclcpp_action::Server<LookupTransformAction>::SharedPtr server_;
123  std::list<GoalInfo> active_goals_;
124  std::mutex mutex_;
125  rclcpp::TimerBase::SharedPtr check_timer_;
126  };
127 }
128 #endif
std::bind
T bind(T... args)
std::string
std::shared_ptr
std::list< GoalInfo >
std::placeholders
tf2_ros
Definition: async_buffer_interface.h:41
TF2_ROS_PUBLIC
#define TF2_ROS_PUBLIC
Definition: visibility_control.h:58
visibility_control.h
std::mutex
tf2_ros::BufferServer::BufferServer
BufferServer(const tf2::BufferCoreInterface &buffer, NodePtr node, const std::string &ns, tf2::Duration check_period=tf2::durationFromSec(0.01))
Constructor.
Definition: buffer_server.h:148