robot_pose_publisher.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2012, Worcester Polytechnic Institute
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the Worcester Polytechnic Institute nor the
00019  *     names of its contributors may be used to endorse or promote
00020  *     products derived from this software without specific prior
00021  *     written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *********************************************************************/
00037 
00049 #include <geometry_msgs/Pose.h>
00050 #include <ros/ros.h>
00051 #include <tf/transform_listener.h>
00052 
00060 int main(int argc, char ** argv)
00061 {
00062   // initialize ROS and the node
00063   ros::init(argc, argv, "robot_pose_publisher");
00064   ros::NodeHandle nh;
00065 
00066   ros::Publisher pose_pub = nh.advertise<geometry_msgs::Pose>("/robot_pose", 1);
00067 
00068   // create the listener
00069   tf::TransformListener listener;
00070   listener.waitForTransform("/map", "/base_link", ros::Time(), ros::Duration(1.0));
00071 
00072   ros::Rate rate(10.0);
00073   while (nh.ok())
00074   {
00075     tf::StampedTransform transform;
00076     try
00077     {
00078       listener.lookupTransform("/map", "/base_link", ros::Time(0), transform);
00079     }
00080     catch (tf::TransformException &ex)
00081     {
00082       ROS_ERROR("%s", ex.what());
00083     }
00084 
00085     // construct a pose message
00086     geometry_msgs::Pose pose;
00087     pose.orientation.x = transform.getRotation().getX();
00088     pose.orientation.y = transform.getRotation().getY();
00089     pose.orientation.z = transform.getRotation().getZ();
00090     pose.orientation.w = transform.getRotation().getW();
00091 
00092     pose.position.x = transform.getOrigin().getX();
00093     pose.position.y = transform.getOrigin().getY();
00094     pose.position.z = transform.getOrigin().getZ();
00095 
00096     pose_pub.publish(pose);
00097 
00098     rate.sleep();
00099   }
00100 
00101   return EXIT_SUCCESS;
00102 }


robot_pose_publisher
Author(s): Russell Toris
autogenerated on Thu Jan 2 2014 11:50:58