00001 #ifndef _MOFA_BRIDGE_H_ 00002 #define _MOFA_BRIDGE_H_ 00003 00004 #include "termios.h" 00005 00006 #include <fstream> 00007 #include <sstream> 00008 #include <iomanip> 00009 #include <set> 00010 00011 #include "cv.h" 00012 #include "highgui.h" 00013 00014 #include "ros/ros.h" 00015 #include "ros/callback_queue.h" 00016 00017 #include "tf/tf.h" 00018 00019 // [PCL_ROS] 00020 #include "pcl_ros/point_cloud.h" 00021 #include "pcl/point_types.h" 00022 #include "pcl/ros/register_point_struct.h" 00023 00024 //pcl::toROSMsg 00025 #include <pcl/io/pcd_io.h> 00026 00027 00028 // [publisher subscriber headers] 00029 #include "sensor_msgs/PointCloud2.h" 00030 #include "sensor_msgs/Image.h" 00031 #include "geometry_msgs/PoseStamped.h" 00032 #include "iri_wam_common_msgs/obs_request.h" 00033 00034 //vanila socket 00035 #include "socket.h" 00036 #include "socketclient.h" 00037 #include "mutex.h" 00038 #include "thread.h" 00039 #include "eventexceptions.h" 00040 #include <arpa/inet.h> 00041 00042 #define ERROR_POS 0 00043 #define RX_ID_POS 1 00044 #define MAXCONN 5 00045 #define BUFFERSIZE 512 00046 #define DATASIZE 512 00047 00048 #define PUBLISHIMAGEno "defined" 00049 #ifdef PUBLISHIMAGE 00050 #include <image_transport/image_transport.h> 00051 #include <cv_bridge/cv_bridge.h> 00052 #endif 00053 00054 typedef union { 00055 struct /*anonymous*/ 00056 { 00057 unsigned char Blue; 00058 unsigned char Green; 00059 unsigned char Red; 00060 unsigned char Alpha; 00061 }; 00062 float float_value; 00063 long long_value; 00064 } RGBValue; 00065 00066 class MofaBridge { 00067 public: 00068 MofaBridge(); 00069 //TODO close socket 00070 void open(); 00071 private: 00072 00073 //vanila socket 00074 bool connected; 00075 std::string serverip; 00076 int port; 00078 CMutex socketmutex; 00079 00081 CSocketClient *csocket; 00082 00084 CEventServer *eventserver; 00085 00087 std::list<std::string> events; 00088 00089 int num_objects; 00090 std::set<int> numobjAset; 00091 std::set<int> numobjBset; 00092 std::set<int> numobjset; 00093 00094 //service activation parameters 00095 bool flag_mpcl2; 00096 00097 int idx; 00098 int nr; 00099 int nc; 00100 sensor_msgs::PointCloud2ConstPtr* msg_; 00101 pcl::PointCloud<pcl::PointXYZRGB> pcl_xyzrgb; 00102 float* xi; // image x coordinates of pcl2 00103 float* yi; // image y coordinates of pcl2 00104 float* zi; // image z coordinates of pcl2 00105 float* ci; // image color coordinates of pcl2 00106 00107 float* ai; // amplitude image array pointer 00108 00109 std::ofstream matlab_xyzrgb; 00110 std::ifstream matlab_xyzrgb_in; 00111 00112 // ROS Handlers 00113 ros::NodeHandle nh; 00114 00115 // ROS Publishers 00116 ros::Publisher labeled_pcl2_publisher; 00117 00118 #ifdef PUBLISHIMAGE 00119 image_transport::Publisher image_pub_; 00120 cv_bridge::CvImage cv_image; 00121 image_transport::ImageTransport imgtransport_; 00122 #endif 00123 00124 // ROS Subscribers 00125 ros::Subscriber pcl2_sub; 00126 00127 // ROS Services 00128 ros::ServiceServer obs_request; 00129 00130 void pcl2_sub_callback(const sensor_msgs::PointCloud2ConstPtr& msg); 00131 bool obs_request_callback(iri_wam_common_msgs::obs_request::Request &req, iri_wam_common_msgs::obs_request::Response &res); 00132 00133 void reloadRGB(); 00134 }; 00135 #endif