Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 #include <ros/ros.h>
00038 #include <visualization_msgs/Marker.h>
00039 #include <std_msgs/ColorRGBA.h>
00040 #include <lse_sensor_msgs/Nostril.h>
00041 #include <lse_sensor_msgs/TPA.h>
00042 
00043 #define NODE_VERSION 0.2
00044 
00045 #define PIXEL_TO_M 20.0
00046 
00047 
00049 bool verbose = true;
00050 
00051 
00053 double hsvS = 1.0, hsvV = 1.0;
00054 int hueMax = 200, hueMin = 0;
00055 
00057 
00058 lse_sensor_msgs::Nostril myNostril, myNostril_0, myNostril_1;
00059 
00060 
00061 void noseCallback(const lse_sensor_msgs::NostrilConstPtr& msg)
00062 {
00063         myNostril.sensor_model = msg->sensor_model;
00064         if(myNostril.sensor_model.compare("Figaro 2620"))
00065         {
00066                 myNostril_0.sensor_model = msg->sensor_model;
00067                 myNostril_0.reading = msg->reading;
00068         }
00069         else if(myNostril.sensor_model.compare("Figaro 2600"))
00070         {
00071                 myNostril_1.sensor_model = msg->sensor_model;
00072                 myNostril_1.reading = msg->reading;
00073         }
00074 
00075         
00076 
00077 }
00078 
00079 
00086 std::string char2string(char *in)
00087 {
00088     std::string str(in);
00089     return str;
00090 }
00091 
00092 
00093 
00103 std_msgs::ColorRGBA hsv_2_rgb(float H, float S, float V)
00104 {
00105         float R, G, B;
00106         double hf;
00107         int    i;
00108         double f;
00109         double pv;
00110         double qv;
00111         double tv;
00112         
00113         std_msgs::ColorRGBA rgbColor;
00114         
00115         
00116         
00117         if( V == 0 )
00118         {
00119                 R = 0;
00120                 G = 0;
00121                 B = 0;
00122         }
00123         else if( S == 0 )
00124         {
00125                 R = V;
00126                 G = V;
00127                 B = V;
00128         }
00129         else
00130         {
00131                 hf = H / 60.0;
00132                 i  = (int) floor( hf );
00133                 f  = hf - i;
00134                 pv  = V * ( 1 - S );
00135                 qv  = V * ( 1 - S * f );
00136                 tv  = V * ( 1 - S * ( 1 - f ) );
00137                 
00138                 switch( i )
00139                 {
00140                         
00141                         case 0:
00142                                 R = V;
00143                                 G = tv;
00144                                 B = pv;
00145                                 break;
00146                         
00147                         
00148                         case 1:
00149                                 R = qv;
00150                                 G = V;
00151                                 B = pv;
00152                                 break;
00153                         case 2:
00154                                 R = pv;
00155                                 G = V;
00156                                 B = tv;
00157                                 break;
00158                         
00159                         case 3:
00160                                 R = pv;
00161                                 G = qv;
00162                                 B = V;
00163                                 break;
00164                         case 4:
00165                                 R = tv;
00166                                 G = pv;
00167                                 B = V;
00168                                 break;
00169                         
00170                         case 5:
00171                           R = V;
00172                           G = pv;
00173                           B = qv;
00174                           break;
00175                         
00176                         case 6:
00177                                 R = V;
00178                                 G = tv;
00179                                 B = pv;
00180                                 break;
00181                         case -1:
00182                                 R = V;
00183                                 G = pv;
00184                                 B = qv;
00185                                 break;
00186                         default:
00187                                 
00188                                 ROS_ERROR("Value error in Pixel conversion...,");
00189                                 break;
00190                 }
00191         }
00192         
00193         rgbColor.r = R;
00194         rgbColor.g = G;
00195         rgbColor.b = B;
00196         
00197         return rgbColor;
00198 }
00199 
00200 
00209 void makeColorBar(visualization_msgs::Marker *ptrMarker, int val)
00210 {
00211         std_msgs::ColorRGBA col;
00212         int step;
00213         int N_STEPS = 10;
00214         float v;
00215         int idx = 0;
00216         int deltaHue;
00217         
00218         deltaHue = hueMax - hueMin;
00219 
00220         step = deltaHue / N_STEPS;
00221         
00222         val = (val <= 100) ? val : 100;
00223         
00224         v = (val/100.0) * deltaHue;
00225         
00226         
00227         ptrMarker->points.clear();
00228         ptrMarker->colors.clear();
00229         
00230         
00231         for (int j = deltaHue; j > (deltaHue - v);j = j - step)
00232         {
00233                 col = hsv_2_rgb(j, hsvS, hsvV);
00234                 ptrMarker->colors.push_back(col);
00235                 idx++;
00236         }
00237         
00238         for (int i = 0; i < idx;i++)
00239         {
00240                 geometry_msgs::Point p;
00241                 p.x = 0.0;
00242                 p.y = -0.3;
00243                 p.z = (0.2 + (i*0.15));
00244                 
00245                 
00246                 ptrMarker->points.push_back(p);
00247         }
00248         
00249 }
00250 
00251 
00252 void configColorBar(ros::NodeHandle *pn, visualization_msgs::Marker *ptrMarker)
00253 {
00254         
00255         
00256         pn->param("scale/x", ptrMarker->scale.x, 0.15);
00257         pn->param("scale/y", ptrMarker->scale.x, 0.15);
00258         pn->param("scale/z", ptrMarker->scale.x, 0.15);
00259 
00260         
00261         pn->param("hsv_s", hsvS, 1.0);
00262         pn->param("hsv_v", hsvV, 1.0);
00263 
00264         
00265         pn->param("hue_max", hueMax, 200);
00266         pn->param("hue_min", hueMin, 0);
00267 }
00268 
00269 
00270 int main( int argc, char** argv )
00271 {
00272         ros::init(argc, argv, "odor_bar");
00273         ros::NodeHandle n("~");
00274         ROS_INFO("odor_bar for ROS %.2f", NODE_VERSION);
00275 
00276         ros::Subscriber nose_sub = n.subscribe("nose", 2, noseCallback);
00277 
00278         ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("odor_bars", 10);
00279 
00280         float chem_val = 0;
00281         char currValue[5];
00282         
00283 
00284         ros::Rate r(1);
00285 
00286         while (ros::ok())
00287         {
00288                 visualization_msgs::Marker points, text;
00289                 points.header.frame_id = text.header.frame_id = "/base_link";
00290                 points.header.stamp = text.header.stamp = ros::Time::now();
00291                 points.ns = text.ns = "odor_bar";
00292                 text.lifetime = ros::Duration();
00293                 points.action = text.action = visualization_msgs::Marker::ADD;
00294                 points.pose.orientation.w = text.pose.orientation.w = 1.0;
00295 
00296 
00297                 points.id = 0;
00298                 text.id = 1;
00299 
00300 
00301                 points.type = visualization_msgs::Marker::CUBE_LIST;
00302                 text.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00303 
00304 
00305                 
00306                 points.scale.x = 0.15;
00307                 points.scale.y = 0.15;
00308                 points.scale.z = 0.15;
00309 
00310                 
00311                 text.scale.z = 0.1;
00312 
00313 
00314 
00315                 
00316                 points.color.g = 1.0f;
00317                 points.color.a = 1.0;
00318 
00319                 
00320                 text.color.r = 1.0;
00321                 text.color.a = 1.0;
00322 
00323 
00324                 geometry_msgs::Point p;
00325                 p.x = 0;
00326                 p.y = 0.1;
00327                 p.z = 0.5;
00328                 text.points.push_back(p);
00329 
00330 
00331                 chem_val = myNostril_0.reading;
00332                 
00333                 chem_val = (100.0/3000.0) * chem_val;
00334                 
00335                 makeColorBar(&points, (int)(chem_val)); 
00336 
00337                 sprintf(currValue,"%d%%", (int)chem_val);
00338                 
00339                 text.text.clear();
00340                 text.text = currValue;
00341                 marker_pub.publish(text);
00342 
00343                 marker_pub.publish(points);
00344 
00345    
00346                 ros::spinOnce();
00347                 r.sleep();
00348         }
00349 
00350         ROS_INFO("That's enough!!!");
00351 }
00352 
00353 
00354 
00355 
00356