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]));
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 }
compatibility.h
JointTfPublisherNode::pnh_
ros::NodeHandle pnh_
Definition: joint_tf_publisher.cpp:50
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
JointTfPublisherNode::z_axis_
const tf2::Vector3 z_axis_
Definition: joint_tf_publisher.cpp:53
transform_broadcaster.h
JointTfPublisherNode::nh_
ros::NodeHandle nh_
Definition: joint_tf_publisher.cpp:49
compat::subscribe
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
tf2_ros::TransformBroadcaster::sendTransform
void sendTransform(const geometry_msgs::TransformStamped &transform)
JointTfPublisherNode::tf_broadcaster_
tf2_ros::TransformBroadcaster tf_broadcaster_
Definition: joint_tf_publisher.cpp:52
JointTfPublisherNode::cbJoint
void cbJoint(const sensor_msgs::JointState::ConstPtr &msg)
Definition: joint_tf_publisher.cpp:55
main
int main(int argc, char *argv[])
Definition: joint_tf_publisher.cpp:81
tf2_ros::TransformBroadcaster
tf2::Quaternion
tf2_geometry_msgs.h
tf2::toMsg
B toMsg(const A &a)
ros::spin
ROSCPP_DECL void spin()
JointTfPublisherNode
Definition: joint_tf_publisher.cpp:46
JointTfPublisherNode::subs_
std::map< std::string, ros::Subscriber > subs_
Definition: joint_tf_publisher.cpp:51
ros::NodeHandle
JointTfPublisherNode::JointTfPublisherNode
JointTfPublisherNode()
Definition: joint_tf_publisher.cpp:70


ypspur_ros
Author(s): Atsushi Watanabe
autogenerated on Mon Feb 19 2024 03:32:25