test_Bridge.cpp
Go to the documentation of this file.
00001 /* +------------------------------------------------------------------------+
00002    |                     Mobile Robot Programming Toolkit (MRPT)            |
00003    |                          http://www.mrpt.org/                          |
00004    |                                                                        |
00005    | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file     |
00006    | See: http://www.mrpt.org/Authors - All rights reserved.                |
00007    | Released under BSD License. See details in http://www.mrpt.org/License |
00008    +------------------------------------------------------------------------+ */
00009 
00010 /*---------------------------------------------------------------
00011         APPLICATION: mrpt_ros bridge
00012         FILE: test_Bridge.cpp
00013         AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
00014   ---------------------------------------------------------------*/
00015 #include "mrpt_bridge/GPS.h"
00016 #include "mrpt_bridge/range.h"
00017 #include "mrpt_bridge/imu.h"
00018 #include "mrpt_bridge/image.h"
00019 #include "mrpt_bridge/stereo_image.h"
00020 
00021 #include "../GPS.cpp"
00022 #include "../range.cpp"
00023 #include "../imu.cpp"
00024 #include "../image.cpp"
00025 #include "../stereo_image.cpp"
00026 
00028 #include <mrpt/obs/CRawlog.h>
00029 #include <mrpt/system/filesystem.h>
00030 
00032 #include <dirent.h>
00033 
00034 
00035 
00036 using namespace sensor_msgs;
00037 using namespace mrpt::obs;
00038 using namespace mrpt::system;
00039 using namespace mrpt::utils;
00040 using namespace mrpt;
00041 using namespace std;
00042 using namespace cv;
00043 
00051 int main(int argc, char **argv)
00052 {
00053     ros::init(argc, argv, "testing_MRPT_bridge");
00054     ros::NodeHandle n;
00055 
00056     ros::Publisher imu_pub          = n.advertise<sensor_msgs::Imu>("imu_publisher", 1000);
00057     ros::Publisher navSatFix_pub    = n.advertise<sensor_msgs::NavSatFix>("navSatFix_publisher", 1000);
00058     ros::Publisher image_pub        = n.advertise<sensor_msgs::Image>("image_publisher", 1000);
00059     ros::Publisher image_pub_left   = n.advertise<sensor_msgs::Image>("left_image_publisher", 1000);
00060     ros::Publisher image_pub_right  = n.advertise<sensor_msgs::Image>("right_image_publisher", 1000);
00061 
00062     int num_ranges  = 10;
00063     ros::Publisher range_pub[num_ranges];
00064     for(int i=0 ; i<num_ranges ; i++)
00065     {
00066         stringstream ss;
00067         ss << "range_publisher" << i;
00068         string topic_name = ss.str();
00069         range_pub[i] = n.advertise<sensor_msgs::Range>(topic_name, 1000);
00070     }
00071     sensor_msgs::Imu        ros_Imu;
00072     sensor_msgs::Range      *ros_Range;
00073     sensor_msgs::NavSatFix  ros_GPS;
00074     sensor_msgs::Image      ros_Image;
00075     sensor_msgs::Image      ros_Image_left;
00076     sensor_msgs::Image      ros_Image_right;
00077 
00078     CObservationGPS     mrpt_GPS;
00079     CObservationIMU     mrpt_IMU;
00080     CObservationRange   mrpt_Range;
00081     CObservationImage   mrpt_Image;
00082     CObservationImage   mrpt_Image_left;
00083     CObservationImage   mrpt_Image_right;
00084 
00085     int i=0;
00086     std_msgs::Header header;
00087     header.frame_id = "map";
00088 
00090     mrpt_Range.maxSensorDistance      = 500;
00091     mrpt_Range.minSensorDistance      = 60;
00092     mrpt_Range.sensorConeApperture    = (float) M_PI/3;
00093     //initializing the measurement of each range value message in MRPT
00094     for(int i=0 ; i<num_ranges ; i++)
00095     {
00096         CObservationRange::TMeasurement measurement;
00097         measurement.sensedDistance = i*1.0;
00098         mrpt_Range.sensedData.push_back(measurement);
00099     }
00101     ros_Range = new sensor_msgs::Range[num_ranges];
00102 
00103 
00105     mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_X)  = 1;
00106     mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_Y)  = 1;
00107     mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_Z)  = 1;
00108     mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_W)  = 1;
00109 
00110     mrpt_IMU.rawMeasurements.at(IMU_X_ACC_GLOBAL) = 1;
00111     mrpt_IMU.rawMeasurements.at(IMU_Y_ACC_GLOBAL) = 1;
00112     mrpt_IMU.rawMeasurements.at(IMU_Z_ACC_GLOBAL) = 1;
00113 
00114     mrpt_IMU.rawMeasurements.at(IMU_X_VEL)   = 1;
00115     mrpt_IMU.rawMeasurements.at(IMU_Y_VEL)   = 1;
00116     mrpt_IMU.rawMeasurements.at(IMU_Z_VEL)   = 1;
00117 
00119     CObservationImage image;
00120     DIR *dir;
00121     dirent *pdir;
00122     vector<string> files;
00123     vector<string> files_fullpath;
00124 
00126     string file_path1 = "/home/raghavender/catkin_ws/src/mrpt_navigation/mrpt_bridge/src/images";
00127 
00128     dir = opendir(file_path1.c_str());
00129     while(pdir = readdir(dir))
00130     {
00131         char *temp_filepath  = pdir->d_name;
00132         files.push_back(pdir->d_name);
00133     }
00134     for(int i=0,j=0 ; i<files.size() ; i++)
00135     {
00136         if(files.at(i).size() > 4) // this removes the . and .. in linux as all files will have size more than 4 .png .jpg etc.
00137         {
00138             files_fullpath.push_back(file_path1 + "/" + files.at(i));
00139             //cout << files_fullpath.at(j) << endl;
00140             j++;
00141         }
00142     } // end of for
00143     sort(files_fullpath.begin(),files_fullpath.end());
00144 
00145 
00146 
00149     CObservationImage image1, image2;
00150     DIR *dir1, *dir2;
00151     dirent *pdir1, *pdir2;
00152     vector<string> files1, files2;
00153     vector<string> files_fullpath1, files_fullpath2;
00154 
00156     string file_path_left = "/home/raghavender/catkin_ws/src/mrpt_navigation/mrpt_bridge/src/stereo_images/left";
00157     string file_path_right = "/home/raghavender/catkin_ws/src/mrpt_navigation/mrpt_bridge/src/stereo_images/right";
00158 
00159     dir1 = opendir(file_path_left.c_str());
00160     while(pdir1 = readdir(dir1))
00161     {
00162         char *temp_filepath  = pdir1->d_name;
00163         files1.push_back(pdir1->d_name);
00164     }
00165     for(int i=0,j=0 ; i<files1.size() ; i++)
00166     {
00167         if(files1.at(i).size() > 4) // this removes the . and .. in linux as all files will have size more than 4 .png .jpg etc.
00168         {
00169             files_fullpath1.push_back(file_path_left + "/" + files1.at(i));
00170             j++;
00171         }
00172     } // end of for
00173     sort(files_fullpath1.begin(),files_fullpath1.end());
00174 
00176     dir2 = opendir(file_path_right.c_str());
00177     while(pdir2 = readdir(dir2))
00178     {
00179         char *temp_filepath  = pdir2->d_name;
00180         files2.push_back(pdir2->d_name);
00181     }
00182     for(int i=0,j=0 ; i<files2.size() ; i++)
00183     {
00184         if(files2.at(i).size() > 4) // this removes the . and .. in linux as all files will have size more than 4 .png .jpg etc.
00185         {
00186             files_fullpath2.push_back(file_path_right + "/" + files2.at(i));
00187             j++;
00188         }
00189     } // end of for
00190     sort(files_fullpath2.begin(),files_fullpath2.end());
00191 
00192     ROS_INFO("Range Message Conversion STARTED..!!");
00193 
00194 
00195     ros::Rate loop_rate(10);
00196     while(ros::ok())
00197     {
00199         header.seq = i;
00200         header.stamp = ros::Time::now();
00201         i++;
00202 
00204         mrpt_Image.image.loadFromFile(files_fullpath.at(i%(files_fullpath.size()-1)));
00205         mrpt_bridge::image::mrpt2ros(mrpt_Image, header, ros_Image);
00206         image_pub.publish(ros_Image);
00207 
00209         mrpt_Image_left.image.loadFromFile(files_fullpath1.at(i%(files_fullpath1.size()-1)));
00210         mrpt_bridge::image::mrpt2ros(mrpt_Image_left, header, ros_Image_left);
00211         image_pub_left.publish(ros_Image_left);
00212 
00213         mrpt_Image_right.image.loadFromFile(files_fullpath2.at(i%(files_fullpath2.size()-1)));
00214         mrpt_bridge::image::mrpt2ros(mrpt_Image_left, header, ros_Image_right);
00215         image_pub_right.publish(ros_Image_right);
00216 
00217 
00219         mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_X)  = i*0.1;
00220         mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_Y)  = i*0.1;
00221         mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_Z)  = i*0.1;
00222         mrpt_IMU.rawMeasurements.at(IMU_ORI_QUAT_W)  = i*-0.1;
00223         mrpt_IMU.rawMeasurements.at(IMU_X_ACC_GLOBAL) = i * 0.1;
00224         mrpt_IMU.rawMeasurements.at(IMU_Y_ACC_GLOBAL) = i*0.1;
00225         mrpt_IMU.rawMeasurements.at(IMU_Z_ACC_GLOBAL) = 9.8+ i*0.003;
00226         mrpt_IMU.rawMeasurements.at(IMU_X_VEL)   = i*0.1 * i*0.2;
00227         mrpt_IMU.rawMeasurements.at(IMU_Y_VEL)   = i*0.1 * i*0.2;
00228         mrpt_IMU.rawMeasurements.at(IMU_Z_VEL)   = 0;
00229         mrpt_bridge::imu::mrpt2ros(mrpt_IMU, header, ros_Imu);
00230         imu_pub.publish(ros_Imu);
00231 
00232 
00234         mrpt::obs::gnss::Message_NMEA_GGA gga;
00235         gga.fields.altitude_meters      = 2;
00236         gga.fields.latitude_degrees     = i*0.001;
00237         gga.fields.longitude_degrees    = i*0.03 + 43;
00238         gga.fields.fix_quality          = 1;
00239         mrpt_GPS.setMsg(gga);
00240         mrpt_bridge::GPS::mrpt2ros(mrpt_GPS, header, ros_GPS);
00241         navSatFix_pub.publish(ros_GPS);
00242 
00243 
00245         mrpt_bridge::range::mrpt2ros(mrpt_Range, header, ros_Range);
00246         ROS_INFO(" published %d",i);
00247         // publishing the ranges over num_ranges umber of topics
00248         for(int i=0 ; i<num_ranges ; i++)
00249             range_pub[i].publish(ros_Range[i]);
00250 
00251         ros::spinOnce();
00252         loop_rate.sleep();
00253     }
00254     return 0;
00255 }
00256 
00257 


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Mon Sep 18 2017 03:12:06