00001
00002
00003
00004
00005
00006
00007
00008
00009
00026 #include <fstream>
00027
00028 #include <ros/ros.h>
00029 #include <ros/package.h>
00030 #include <angles/angles.h>
00031
00032 #include <velodyne/data_base.h>
00033
00034 namespace Velodyne
00035 {
00037
00038
00039
00041
00042 Data::Data(std::string ofile, std::string anglesFile)
00043 {
00044 ofile_ = ofile;
00045 anglesFile_ = anglesFile;
00046
00047 ofp_ = NULL;
00048 memset(&upper_, 0, sizeof(upper_));
00049 memset(&lower_, 0, sizeof(lower_));
00050 getParams();
00051 }
00052
00053
00062 int Data::getParams()
00063 {
00064
00065 ros::NodeHandle private_nh("~/data");
00066
00067 private_nh.getParam("output", ofile_);
00068
00069
00070 if (!private_nh.getParam("angles", anglesFile_))
00071 {
00072
00073 std::string pkgPath = ros::package::getPath("velodyne_common");
00074 anglesFile_ = pkgPath + "/etc/angles.config";
00075 }
00076
00077 ROS_INFO_STREAM("correction angles: " << anglesFile_);
00078
00079 return 0;
00080 }
00081
00083 void Data::processScan(const velodyne_msgs::VelodyneScan::ConstPtr &scanMsg)
00084 {
00085 rawScan_ = scanMsg;
00086
00087 if (uninitialized_)
00088 return;
00089
00090
00091 for (unsigned i = 0; i < rawScan_->packets.size(); ++i)
00092 {
00093 if (!ros::ok())
00094 break;
00095 processPacket(&rawScan_->packets[i], rawScan_->header.frame_id);
00096 }
00097 }
00098
00100 int Data::setup(void)
00101 {
00102
00103 ofp_ = NULL;
00104 if (ofile_ != "")
00105 {
00106 if (ofile_ == "-")
00107 {
00108 ROS_INFO("output to stdout");
00109 ofp_ = stdout;
00110 }
00111 else
00112 {
00113 ROS_INFO("output file: %s", ofile_.c_str());
00114 ofp_ = fopen(ofile_.c_str(), "w");
00115 if (ofp_ == NULL)
00116 {
00117 int rc = errno;
00118 ROS_ERROR("failed to open \"%s\" (%s)",
00119 ofile_.c_str(), strerror(rc));
00120 return rc;
00121 }
00122 }
00123 }
00124
00125
00126 std::ifstream config(anglesFile_.c_str());
00127 if (!config)
00128 {
00129 std::cerr << "Failure opening Velodyne angles correction file: "
00130 << anglesFile_ << std::endl;
00131 return -1;
00132 }
00133
00134 int index = 0;
00135 float rotational = 0;
00136 float vertical = 0;
00137 int enabled = 0;
00138 float offset1=0;
00139 float offset2=0;
00140 float offset3=0;
00141
00142 correction_angles * angles = 0;
00143
00144 char buffer[256];
00145 while(config.getline(buffer, sizeof(buffer)))
00146 {
00147 if (buffer[0] == '#') continue;
00148 else if (strcmp(buffer, "upper") == 0)
00149 continue;
00150 else if(strcmp(buffer, "lower") == 0)
00151 continue;
00152 else if(sscanf(buffer,"%d %f %f %f %f %f %d", &index, &rotational,
00153 &vertical, &offset1, &offset2, &offset3, &enabled) == 7)
00154 {
00155 int ind=index;
00156 if (index < 32)
00157 angles=&lower_[0];
00158 else
00159 {
00160 angles=&upper_[0];
00161 ind=index-32;
00162 }
00163 angles[ind].rotational = angles::from_degrees(rotational);
00164 angles[ind].vertical = angles::from_degrees(vertical);
00165 angles[ind].offset1 = offset1;
00166 angles[ind].offset2 = offset2;
00167 angles[ind].offset3 = offset3;
00168 angles[ind].enabled = enabled;
00169
00170
00171 #ifdef DEBUG_ANGLES
00172 ROS_DEBUG(stderr, "%d %.2f %.6f %.f %.f %.2f %d",
00173 index, rotational, vertical,
00174 angles[ind].offset1,
00175 angles[ind].offset2,
00176 angles[ind].offset3,
00177 angles[ind].enabled);
00178 #endif
00179 }
00180 }
00181
00182 config.close();
00183 uninitialized_ = false;
00184 return 0;
00185 }
00186
00187 }