Go to the documentation of this file.00001 #include "dummy_mofa_bridge.h"
00002
00003 DummyMofaBridge::DummyMofaBridge() {
00004
00005 srand((unsigned)time(0));
00006
00007
00008 idx = 0;
00009 this->nc=0;
00010 this->nr=0;
00011
00012
00013 std::string pcl2_sub_name = "/mofa_bridge/input/pcl2/raw";
00014 std::string labeled_pcl2_sub_name = "/mofa_bridge/output/pcl2/segmented";
00015 std::string request_observation_sub_name = "/mofa_bridge/srv/request_observation";
00016
00017
00018 this->pcl2_sub = this->nh.subscribe(pcl2_sub_name, 1, &DummyMofaBridge::pcl2_sub_callback, this);
00019
00020
00021 this->labeled_pcl2_publisher = this->nh.advertise< pcl::PointCloud<pcl::PointXYZRGB> > (labeled_pcl2_sub_name, 5);
00022
00023
00024 this->obs_request = this->nh.advertiseService(request_observation_sub_name, &DummyMofaBridge::obs_request_callback, this);
00025
00026
00027
00028
00029
00030
00031
00032 ROS_INFO("Starting mofaBridge Node");
00033 ROS_INFO("Use [ rosservice call /request_observation ] to store current range image and compute observation");
00034 }
00035
00036 DummyMofaBridge::~DummyMofaBridge(){
00037
00038 }
00039
00040 void DummyMofaBridge::close(){
00041
00042 }
00043
00044 void DummyMofaBridge::open(){
00045
00046 }
00047
00048
00049 void DummyMofaBridge::pcl2_sub_callback(const sensor_msgs::PointCloud2ConstPtr& msg)
00050 {
00051 pcl::fromROSMsg(*msg, this->pcl_xyzrgb);
00052
00053 this->nc=msg->width;
00054 this->nr=msg->height;
00055
00056 }
00057
00058
00059 bool DummyMofaBridge::obs_request_callback(iri_wam_common_msgs::obs_request::Request &req, iri_wam_common_msgs::obs_request::Response &res){
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 res.num_objectsA = rand()%5;
00104 res.num_objectsB = rand()%2;
00105 res.num_objects = res.num_objectsA + res.num_objectsB;
00106 this->labeled_pcl2_publisher.publish(this->pcl_xyzrgb);
00107
00108 return true;
00109 }
00110
00111 void DummyMofaBridge::reloadRGB(){
00112 int x, y, z;
00113 int red_label, green_label, blue_label;
00114 RGBValue color;
00115
00116 std::stringstream matlab_xyzrgb_fn;
00117 matlab_xyzrgb_fn << "last_image_labelled.dat";
00118
00119
00120 matlab_xyzrgb_in.open(matlab_xyzrgb_fn.str().c_str(), std::ios::in);
00121
00122
00123 pcl::PointCloud<pcl::PointXYZRGB>::iterator pt_iter = this->pcl_xyzrgb.begin();
00124 for (int rr = 0; rr < (int)pcl_xyzrgb.height; ++rr) {
00125 for (int cc = 0; cc < (int)pcl_xyzrgb.width; ++cc, ++pt_iter) {
00126 pcl::PointXYZRGB &pt = *pt_iter;
00127
00128 matlab_xyzrgb_in >> x;
00129 matlab_xyzrgb_in >> y;
00130 matlab_xyzrgb_in >> z;
00131
00132 matlab_xyzrgb_in >> red_label;
00133 matlab_xyzrgb_in >> green_label;
00134 matlab_xyzrgb_in >> blue_label;
00135
00136 color.Red = red_label;
00137 color.Green = green_label;
00138 color.Blue = blue_label;
00139 pt.rgb = color.float_value;
00140
00141 }
00142 }
00143
00144
00145 matlab_xyzrgb.close();
00146 std::cout << "Loaded pcl image " << matlab_xyzrgb_fn.str() << std::endl;
00147
00148
00149 }
00150
00151 int main(int argc, char** argv)
00152 {
00153 ros::init(argc, argv, "mofa_bridge");
00154 DummyMofaBridge mofa_bridge;
00155 mofa_bridge.open();
00156 ros::spin();
00157 return 0;
00158 }