joint_tf_publisher.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2015-2017, the ypspur_ros authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its 
00014  *       contributors may be used to endorse or promote products derived from 
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <ros/ros.h>
00031 
00032 #include <geometry_msgs/TransformStamped.h>
00033 #include <sensor_msgs/JointState.h>
00034 
00035 #include <tf/transform_broadcaster.h>
00036 
00037 #include <signal.h>
00038 #include <sys/types.h>
00039 #include <sys/wait.h>
00040 #include <map>
00041 #include <string>
00042 
00043 #include <compatibility.h>
00044 
00045 class JointTfPublisherNode
00046 {
00047 private:
00048   ros::NodeHandle nh_;
00049   ros::NodeHandle pnh_;
00050   std::map<std::string, ros::Subscriber> subs_;
00051   tf::TransformBroadcaster tf_broadcaster_;
00052 
00053   void cbJoint(const sensor_msgs::JointState::ConstPtr& msg)
00054   {
00055     for (size_t i = 0; i < msg->name.size(); i++)
00056     {
00057       geometry_msgs::TransformStamped trans;
00058       trans.header = msg->header;
00059       trans.header.frame_id = msg->name[i] + "_in";
00060       trans.child_frame_id = msg->name[i] + "_out";
00061       trans.transform.rotation = tf::createQuaternionMsgFromYaw(msg->position[i]);
00062       tf_broadcaster_.sendTransform(trans);
00063     }
00064   }
00065 
00066 public:
00067   JointTfPublisherNode()
00068     : nh_()
00069     , pnh_("~")
00070   {
00071     subs_["joint"] = compat::subscribe(
00072         nh_, "joint_states",
00073         pnh_, "joint", 1, &JointTfPublisherNode::cbJoint, this);
00074   }
00075 };
00076 
00077 int main(int argc, char* argv[])
00078 {
00079   ros::init(argc, argv, "joint_tf_publisher");
00080 
00081   JointTfPublisherNode jp;
00082   ros::spin();
00083 
00084   return 0;
00085 }


ypspur_ros
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 6 2019 20:19:02