Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <iostream>
00009 #include <fstream>
00010
00011 #include <ros/ros.h>
00012 #include <auv_msgs/BodyVelocityReq.h>
00013 #include <auv_msgs/NED.h>
00014 #include <auv_msgs/DecimalLatLon.h>
00015 #include <std_msgs/Float32.h>
00016
00017
00018 #include <labust/tools/GeoUtilities.hpp>
00019
00020 namespace labust{
00021 namespace sim{
00022
00023 class publishData{
00024
00025 public:
00026
00027
00028 enum {stamp = 0, u = 1, v = 2, w = 3, vx = -1, vy = -1, r = 4, depth = 6, psi = 5, range = 7, x = 8, y = 9, z = 10 };
00029
00030
00031 publishData():fileName(""),publishRate(0.1), counter(0){
00032
00033 ros::NodeHandle nh, ph("~");
00034 ph.param("filename", fileName, fileName);
00035 ph.param("rate", publishRate, publishRate);
00036
00037
00038
00039 pubVelocityRef = nh.advertise<auv_msgs::BodyVelocityReq>("velocityRef",1);
00040 pubRange = nh.advertise<std_msgs::Float32>("rangeMeas",1);
00041 pubDepth = nh.advertise<std_msgs::Float32>("depth",1);
00042 pubPosition = nh.advertise<auv_msgs::NED>("position",1);
00043 pubHeading = nh.advertise<std_msgs::Float32>("heading",1);
00044
00045
00046
00047 file.open(fileName.c_str(), std::ios::in);
00048
00049 publishLoop();
00050 }
00051
00052 ~publishData(){
00053
00054 }
00055
00056 void publishLoop(){
00057
00058 ros::Rate rate(1/publishRate);
00059
00060 while(ros::ok()){
00061 if(file.is_open()){
00062
00063 std::string line;
00064 std::getline(file,line);
00065 parsedData = split(line,',');
00066
00067 velocityData.twist.linear.x = std::atof(parsedData[u].c_str());
00068 velocityData.twist.linear.y = std::atof(parsedData[v].c_str());
00069 velocityData.twist.linear.z = std::atof(parsedData[w].c_str());
00070 velocityData.twist.angular.z = std::atof(parsedData[r].c_str());
00071
00072
00073
00074 auv_msgs::NED position;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 std_msgs::Float32 rangeData;
00086 rangeData.data = std::atof(parsedData[range].c_str());
00087
00088
00089 std_msgs::Float32 depthData;
00090 depthData.data = std::atof(parsedData[depth].c_str());
00091
00092 std_msgs::Float32 headingData;
00093 headingData.data = atof(parsedData[psi].c_str());
00094
00095
00096 pubVelocityRef.publish(velocityData);
00097 pubDepth.publish(depthData);
00098 pubPosition.publish(position);
00099 pubHeading.publish(headingData);
00100 if(rangeData.data > 0){
00101 pubRange.publish(rangeData);
00102 }
00103
00104 }
00105
00106 ros::spinOnce();
00107 rate.sleep();
00108 }
00109 }
00110
00111 std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
00112 std::stringstream ss(s);
00113 std::string item;
00114 while (std::getline(ss, item, delim)) {
00115 if(!item.empty()){
00116 elems.push_back(item);
00117 }
00118 }
00119 return elems;
00120 }
00121
00122 std::vector<std::string> split(const std::string &s, char delim) {
00123 std::vector<std::string> elems;
00124 split(s, delim, elems);
00125 return elems;
00126 }
00127
00128 std::ifstream file;
00129 std::string fileName;
00130 double publishRate;
00131 std::vector<std::string> parsedData;
00132 auv_msgs::BodyVelocityReq velocityData;
00133 ros::Publisher pubVelocityRef, pubRange, pubDepth, pubPosition, pubHeading;
00134 auv_msgs::DecimalLatLon origin;
00135 int counter;
00136 };
00137 }
00138 }
00139
00140
00141 int main(int argc, char* argv[]){
00142
00143
00144 ros::init(argc,argv,"publish_from_csv");
00145 labust::sim::publishData();
00146 return 0;
00147 }
00148
00149
00150