Go to the documentation of this file.00001 #include "get_board_information_alg_node.h"
00002
00003
00004 GetBoardInformationAlgNode::GetBoardInformationAlgNode(void) :
00005 algorithm_base::IriBaseAlgorithm<GetBoardInformationAlgorithm>(),
00006 EventInfoReady("Info ready"),
00007 EventServiceWaiting("Service Waiting")
00008 {
00009
00010
00011
00012
00013 this->believe_status_publisher_ = this->public_node_handle_.advertise<sensor_msgs::Image>("believe_status", 1);
00014 this->pointcloud_out_publisher_ = this->public_node_handle_.advertise<sensor_msgs::PointCloud2>("pointcloud_out", 1);
00015
00016
00017 this->unreachable_position_subscriber_ = this->public_node_handle_.subscribe("unreachable_position", 10, &GetBoardInformationAlgNode::unreachable_position_callback, this);
00018 this->plane_coefficients_subscriber_ = this->public_node_handle_.subscribe("plane_coefficients", 1, &GetBoardInformationAlgNode::plane_coefficients_callback, this);
00019 this->pointcloud_in_subscriber_ = this->public_node_handle_.subscribe("pointcloud_in", 0, &GetBoardInformationAlgNode::pointcloud_in_callback, this);
00020 this->image_in_subscriber_ = this->public_node_handle_.subscribe("image_in", 1, &GetBoardInformationAlgNode::image_in_callback, this);
00021
00022
00023 this->get_board_info_server_ = this->public_node_handle_.advertiseService("get_board_info_srv", &GetBoardInformationAlgNode::get_board_infoCallback, this);
00024
00025
00026
00027
00028
00029
00030
00031
00032 is_service_waiting = false;
00033 waiting_for_pointcloud = false;
00034 waiting_for_image = false;
00035 waiting_for_coefficients = false;
00036
00037
00038 cv_bridge::CvImage cvbridge_aux;
00039 cvbridge_aux.encoding = sensor_msgs::image_encodings::BGR8;
00040 cvbridge_aux.image = cv::Mat::zeros(cv::Size(640,480), CV_8UC3);
00041 cvbridge_aux.header.stamp = ros::Time::now();
00042 last_image = *cvbridge_aux.toImageMsg();
00043 }
00044
00045 GetBoardInformationAlgNode::~GetBoardInformationAlgNode(void)
00046 {
00047
00048 }
00049
00050 void GetBoardInformationAlgNode::mainNodeThread(void)
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 waiting_for_pointcloud = true;
00065 waiting_for_image = true;
00066 waiting_for_coefficients = true;
00067
00068
00069
00070 while (waiting_for_image || waiting_for_coefficients) {
00071 try {
00072 EventInfoReady.wait(5000000);
00073 }catch(CEventTimeoutException& e){
00074
00075 ROS_ERROR_STREAM("get_board_info -> main_thread: timed out!");
00076 ROS_INFO_STREAM("Got pointcloud: " << not waiting_for_pointcloud);
00077 ROS_INFO_STREAM("Got image:" << not waiting_for_image);
00078 ROS_INFO_STREAM("Got coefficients: " << not waiting_for_coefficients);
00079
00080
00081 waiting_for_pointcloud = true;
00082 waiting_for_image = true;
00083 waiting_for_coefficients = true;
00084 }catch(CException& e){
00085
00086 ROS_ERROR("get_board_info -> main_thread: Exception found waiting");
00087 return;
00088 }
00089 }
00090
00091 this->alg_.lock();
00092 last_pointcloud = current_pointcloud;
00093
00094 last_image = current_image;
00095 last_plane_coeffs = current_plane_coeffs;
00096 this->alg_.unlock();
00097
00098
00099 this->Image_msg_ = this->alg_.getCurrentBelieveColors();
00100
00101 if(this->believe_status_publisher_.getNumSubscribers())
00102 this->believe_status_publisher_.publish(this->Image_msg_);
00103
00104 if (is_service_waiting) {
00105 is_service_waiting = false;
00106 EventServiceWaiting.set();
00107 }
00108 }
00109
00110
00111 void GetBoardInformationAlgNode::unreachable_position_callback(const estirabot_msgs::ImagePoint::ConstPtr& msg)
00112 {
00113 ROS_DEBUG("GetBoardInformationAlgNode::unreachable_position_callback: New Message Received");
00114
00115
00116
00117
00118
00119
00120
00121 alg_.updateUnreachableZones(msg);
00122
00123
00124
00125
00126 }
00127 void GetBoardInformationAlgNode::plane_coefficients_callback(const pcl_msgs::ModelCoefficients::ConstPtr& msg)
00128 {
00129 ROS_DEBUG("GetBoardInformationAlgNode::plane_coefficients_callback: New Message Received");
00130
00131
00132
00133
00134
00135
00136 current_plane_coeffs = *msg;
00137 waiting_for_coefficients = false;
00138 EventInfoReady.set();
00139
00140
00141
00142
00143 }
00144 void GetBoardInformationAlgNode::pointcloud_in_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
00145 {
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 if (waiting_for_pointcloud) {
00158 ROS_DEBUG("GetBoardInformationAlgNode::pointcloud_in_callback: Pointcloud available");
00159 current_pointcloud = *msg;
00160
00161 this->pointcloud_out_publisher_.publish(*msg);
00162 waiting_for_pointcloud = false;
00163 }
00164
00165
00166
00167
00168 }
00169 void GetBoardInformationAlgNode::image_in_callback(const sensor_msgs::Image::ConstPtr& msg)
00170 {
00171 ROS_DEBUG("GetBoardInformationAlgNode::image_in_callback: New Message Received");
00172
00173
00174
00175
00176
00177
00178 current_image = *msg;
00179 this->alg_.updateCurrentBelieve(msg);
00180 waiting_for_image = false;
00181
00182
00183
00184 EventInfoReady.set();
00185
00186 }
00187
00188
00189 bool GetBoardInformationAlgNode::get_board_infoCallback(iri_clean_board::BoardInfo::Request &req, iri_clean_board::BoardInfo::Response &res)
00190 {
00191 ROS_DEBUG("GetBoardInformationAlgNode::get_board_infoCallback: New Request Received!");
00192
00193 this->get_board_info_mutex_.enter();
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 this->alg_.lock();
00210 res.pointcloud = last_pointcloud;
00211 res.segmented_image = this->alg_.joinImageAndBelieve(last_image);
00212 res.plane_coefficients = last_plane_coeffs.values;
00213 this->alg_.unlock();
00214
00215 this->get_board_info_mutex_.exit();
00216
00217 return true;
00218 }
00219
00220
00221
00222
00223
00224
00225 void GetBoardInformationAlgNode::node_config_update(Config &config, uint32_t level)
00226 {
00227 this->alg_.lock();
00228
00229 this->alg_.unlock();
00230 }
00231
00232 void GetBoardInformationAlgNode::addNodeDiagnostics(void)
00233 {
00234 }
00235
00236
00237 int main(int argc,char *argv[])
00238 {
00239
00240 return algorithm_base::main<GetBoardInformationAlgNode>(argc, argv, "get_board_information_alg_node");
00241 }