Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00042
00043 #include <iostream>
00044 #include <float.h>
00045
00046
00047 #include <ros/ros.h>
00048 #include <ros/node_handle.h>
00049 #include <sensor_msgs/LaserScan.h>
00050
00051 using namespace std;
00052
00053
00054 class LoggerNode
00055 {
00056 public:
00057 ros::NodeHandle nh_;
00058
00059 ros::Subscriber scan_;
00060
00061 string filename_;
00062 string input_scan_topic_;
00063 FILE *f_out_;
00064 int scan_id_;
00065
00066
00070 LoggerNode() : nh_("~")
00071 {
00072 nh_.param("input_scan_topic", input_scan_topic_, std::string("/base_scan_front"));
00073 scan_ = nh_.subscribe<sensor_msgs::LaserScan>(input_scan_topic_, 10, &LoggerNode::scan_cb, this);
00074 }
00075
00079 ~LoggerNode()
00080 {
00081 fclose( f_out_ );
00082 }
00083
00087 void init ()
00088 {
00089 scan_id_ = 0;
00090
00091 f_out_ = fopen(filename_.c_str(), "w");
00092 if ( f_out_ == NULL )
00093 {
00094 ROS_ERROR("ERROR opening output file %s", filename_.c_str());
00095 }
00096 }
00097
00102 void scan_cb(const sensor_msgs::LaserScan::ConstPtr &msg)
00103 {
00104 double value;
00105 double angle;
00106 int num_readings = msg->ranges.size();
00107
00108 scan_id_ ++;
00109
00110 fprintf(f_out_, "%d %.8f 1 %d", scan_id_, msg->header.stamp.toSec(), num_readings);
00111 for (int i = 0; i < num_readings; i++)
00112 {
00113 value = msg->ranges[i];
00114 angle = msg->angle_min + i * msg->angle_increment;
00115
00116 fprintf(f_out_, " %.8f %.8f", angle, value);
00117 }
00118 fprintf(f_out_, "\n");
00119 ROS_INFO("Scan nr %d saved to disk.", scan_id_);
00120 }
00121
00122 };
00123
00124
00125
00126 int main (int argc, char** argv)
00127 {
00128
00129 if (argc < 2) {
00130 cerr << "USE: " << argv[0] << " <output_file>" << endl;
00131 return 1;
00132 }
00133 ros::init (argc, argv, "logger_node");
00134 LoggerNode lg_node;
00135 lg_node.filename_.assign(argv[1]);
00136 ROS_INFO("filename %s", lg_node.filename_.c_str());
00137 lg_node.init();
00138 ros::spin ();
00139 return (0);
00140 }
00141
00142