tf_rt_broadcaster.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2021, Qiayuan Liao
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 are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *******************************************************************************/
33 
34 //
35 // Created by qiayuan on 1/3/21.
36 //
38 
39 #include <vector>
40 #include <tf2_msgs/TFMessage.h>
41 
42 namespace rm_common
43 {
45 {
47 }
48 
49 void TfRtBroadcaster::sendTransform(const geometry_msgs::TransformStamped& transform)
50 {
51  std::vector<geometry_msgs::TransformStamped> v1;
52  v1.push_back(transform);
53  sendTransform(v1);
54 }
55 
56 void TfRtBroadcaster::sendTransform(const std::vector<geometry_msgs::TransformStamped>& transforms)
57 {
58  tf2_msgs::TFMessage message;
59  for (const auto& transform : transforms)
60  {
61  message.transforms.push_back(transform);
62  }
63  if (realtime_pub_->trylock())
64  {
65  realtime_pub_->msg_ = message;
66  realtime_pub_->unlockAndPublish();
67  }
68 }
69 
71 {
72  realtime_pub_.reset(new realtime_tools::RealtimePublisher<tf2_msgs::TFMessage>(root_nh, "/tf_static", 100, true));
73 }
74 
75 void StaticTfRtBroadcaster::sendTransform(const geometry_msgs::TransformStamped& transform)
76 {
77  std::vector<geometry_msgs::TransformStamped> v1;
78  v1.push_back(transform);
79  sendTransform(v1);
80 }
81 
82 void StaticTfRtBroadcaster::sendTransform(const std::vector<geometry_msgs::TransformStamped>& transforms)
83 {
84  for (const auto& transform : transforms)
85  {
86  bool match_found = false;
87  for (auto& it_msg : net_message_.transforms)
88  {
89  if (transform.child_frame_id == it_msg.child_frame_id)
90  {
91  it_msg = transform;
92  match_found = true;
93  break;
94  }
95  }
96  if (!match_found)
97  net_message_.transforms.push_back(transform);
98  }
99  if (realtime_pub_->trylock())
100  {
102  realtime_pub_->unlockAndPublish();
103  }
104 }
105 
106 } // namespace rm_common
rm_common::StaticTfRtBroadcaster::init
void init(ros::NodeHandle &root_nh) override
Definition: tf_rt_broadcaster.cpp:101
rm_common::TfRtBroadcaster::sendTransform
virtual void sendTransform(const geometry_msgs::TransformStamped &transform)
Definition: tf_rt_broadcaster.cpp:80
rm_common::TfRtBroadcaster::init
virtual void init(ros::NodeHandle &root_nh)
Definition: tf_rt_broadcaster.cpp:75
realtime_tools::RealtimePublisher
rm_common::StaticTfRtBroadcaster::net_message_
tf2_msgs::TFMessage net_message_
Definition: tf_rt_broadcaster.h:99
rm_common::TfRtBroadcaster::realtime_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< tf2_msgs::TFMessage > > realtime_pub_
Definition: tf_rt_broadcaster.h:119
rm_common
Definition: calibration_queue.h:43
rm_common::StaticTfRtBroadcaster::sendTransform
void sendTransform(const geometry_msgs::TransformStamped &transform) override
Definition: tf_rt_broadcaster.cpp:106
ros::NodeHandle
tf_rt_broadcaster.h


rm_common
Author(s):
autogenerated on Sun Apr 6 2025 02:22:01