pose_transform.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <string>
31 
32 #include <ros/ros.h>
33 
34 #include <geometry_msgs/PoseWithCovarianceStamped.h>
37 
39 
41 {
42 private:
47 
48  std::string to_;
49 
52 
53  void cbPose(const geometry_msgs::PoseWithCovarianceStamped::Ptr& msg)
54  {
55  try
56  {
57  geometry_msgs::PoseStamped in;
58  geometry_msgs::PoseStamped out;
59  geometry_msgs::PoseWithCovarianceStamped out_msg;
60  in.header = msg->header;
61  in.header.stamp = ros::Time(0);
62  in.pose = msg->pose.pose;
63  geometry_msgs::TransformStamped trans = tfbuf_.lookupTransform(
64  to_, msg->header.frame_id, in.header.stamp, ros::Duration(0.5));
65  tf2::doTransform(in, out, trans);
66  out_msg = *msg;
67  out_msg.header = out.header;
68  out_msg.pose.pose = out.pose;
69  pub_pose_.publish(out_msg);
70  }
71  catch (tf2::TransformException& e)
72  {
73  ROS_WARN("pose_transform: %s", e.what());
74  }
75  }
76 
77 public:
79  : pnh_("~")
80  , tfl_(tfbuf_)
81  {
84  nh_, "pose_in",
85  pnh_, "pose_in", 1, &PoseTransformNode::cbPose, this);
86  pub_pose_ = neonavigation_common::compat::advertise<geometry_msgs::PoseWithCovarianceStamped>(
87  nh_, "pose_out",
88  pnh_, "pose_out", 1, false);
89  pnh_.param("to_frame", to_, std::string("map"));
90  }
91 };
92 
93 int main(int argc, char** argv)
94 {
95  ros::init(argc, argv, "pose_transform");
96 
97  PoseTransformNode ptn();
98  ros::spin();
99 
100  return 0;
101 }
void publish(const boost::shared_ptr< M > &message) const
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::NodeHandle pnh_
ros::Subscriber subscribe(ros::NodeHandle &nh_new, const std::string &topic_new, ros::NodeHandle &nh_old, const std::string &topic_old, uint32_t queue_size, void(*fp)(M), const ros::TransportHints &transport_hints=ros::TransportHints())
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
#define ROS_WARN(...)
ros::Publisher pub_pose_
ROSCPP_DECL void spin(Spinner &spinner)
ros::NodeHandle nh_
tf2_ros::Buffer tfbuf_
tf2_ros::TransformListener tfl_
int main(int argc, char **argv)
void cbPose(const geometry_msgs::PoseWithCovarianceStamped::Ptr &msg)
ros::Subscriber sub_pose_


map_organizer
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:33