joint_tf_publisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017, the ypspur_ros 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 <ros/ros.h>
31 
32 #include <geometry_msgs/TransformStamped.h>
33 #include <sensor_msgs/JointState.h>
34 
37 
38 #include <signal.h>
39 #include <sys/types.h>
40 #include <sys/wait.h>
41 #include <map>
42 #include <string>
43 
44 #include <compatibility.h>
45 
47 {
48 private:
51  std::map<std::string, ros::Subscriber> subs_;
53  const tf2::Vector3 z_axis_;
54 
55  void cbJoint(const sensor_msgs::JointState::ConstPtr& msg)
56  {
57  for (size_t i = 0; i < msg->name.size(); i++)
58  {
59  geometry_msgs::TransformStamped trans;
60  trans.header = msg->header;
61  trans.header.frame_id = msg->name[i] + "_in";
62  trans.child_frame_id = msg->name[i] + "_out";
63 
64  trans.transform.rotation = tf2::toMsg(tf2::Quaternion(z_axis_, msg->position[i]));
65  tf_broadcaster_.sendTransform(trans);
66  }
67  }
68 
69 public:
71  : nh_()
72  , pnh_("~")
73  , z_axis_(0, 0, 1)
74  {
75  subs_["joint"] = compat::subscribe(
76  nh_, "joint_states",
77  pnh_, "joint", 1, &JointTfPublisherNode::cbJoint, this);
78  }
79 };
80 
81 int main(int argc, char* argv[])
82 {
83  ros::init(argc, argv, "joint_tf_publisher");
84 
86  ros::spin();
87 
88  return 0;
89 }
int main(int argc, char *argv[])
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::map< std::string, ros::Subscriber > subs_
ROSCPP_DECL void spin(Spinner &spinner)
void sendTransform(const geometry_msgs::TransformStamped &transform)
tf2_ros::TransformBroadcaster tf_broadcaster_
B toMsg(const A &a)
void cbJoint(const sensor_msgs::JointState::ConstPtr &msg)
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(T::*fp)(M) const, T *obj, const ros::TransportHints &transport_hints=ros::TransportHints())
Definition: compatibility.h:98
const tf2::Vector3 z_axis_


ypspur_ros
Author(s): Atsushi Watanabe
autogenerated on Thu May 13 2021 03:01:26