pose_logger.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: transform_pointcloud.cpp 30719 2010-07-09 20:28:41Z rusu $
00035  *
00036  */
00037 
00046 // ROS core
00047 #include <ros/ros.h>
00048 
00049 #include <tf/transform_listener.h>
00050 
00051 #include <fstream>
00052 #include <iostream>
00053 
00054 using namespace std;
00055 
00056 class PoseLogger
00057 {
00058 protected:
00059   ros::NodeHandle nh_;
00060 
00061 public:
00062 
00063   ros::Subscriber sub_;
00064   ros::Publisher pub_;
00065   tf::TransformListener tf_;
00066 
00068   PoseLogger  (ros::NodeHandle &n) : nh_(n)
00069   {
00070 
00071   }
00072 
00074   // cloud_cb (!)
00075   void spin (double rate)
00076   {
00077     ros::Rate loop_rate(rate);
00078     std::ofstream a_file ( "poses.txt" );
00079     a_file<< "time" << " " << "x" << " " << "y" << std::endl;
00080     // Outputs to example.txt through a_file
00081 
00082     // Close the file stream explicitly
00083 
00084     while (ros::ok())
00085       {
00086         ros::Time time;
00087         time = ros::Time::now();
00088         bool found_transform = tf_.waitForTransform("map", "/base_link",
00089                                                     time, ros::Duration(1.0));
00090         if (found_transform)
00091           {
00092             //ROS_ASSERT_MSG(found_transform, "Could not transform to camera frame");
00093             tf::StampedTransform transform;
00094             tf_.lookupTransform("map", "base_link", time, transform);
00095             std::cerr << time << " " << transform.getOrigin().x() << " " << transform.getOrigin().y() << std::endl;
00096             a_file<< time << " " << transform.getOrigin().x() << " " << transform.getOrigin().y() << std::endl;
00097           }
00098         ros::spinOnce();
00099         loop_rate.sleep();
00100       }
00101     a_file.close();
00102   }
00103 };
00104 
00105 int main (int argc, char** argv)
00106 {
00107   ros::init (argc, argv, "pose_logger_node");
00108   if (argc != 2)
00109     {
00110       ROS_ERROR("Usage %s <logging rate>", argv[0]);
00111       exit (0);
00112     }
00113   ros::NodeHandle n("~");
00114   PoseLogger tp(n);
00115   tp.spin(atof(argv[1]));
00116   //  ros::spin ();
00117   return (0);
00118 }
00119 
00120 /* ]--- */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


pcl_cloud_tools
Author(s): Nico Blodow, Zoltan-Csaba Marton, Dejan Pangercic
autogenerated on Sun Oct 6 2013 11:58:08