colision_time.cpp
Go to the documentation of this file.
00001 /**************************************************************************************************
00002  Software License Agreement (BSD License)
00003 
00004  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
00005  All rights reserved.
00006 
00007  Redistribution and use in source and binary forms, with or without modification, are permitted
00008  provided that the following conditions are met:
00009 
00010   *Redistributions of source code must retain the above copyright notice, this list of
00011    conditions and the following disclaimer.
00012   *Redistributions in binary form must reproduce the above copyright notice, this list of
00013    conditions and the following disclaimer in the documentation and/or other materials provided
00014    with the distribution.
00015   *Neither the name of the University of Aveiro nor the names of its contributors may be used to
00016    endorse or promote products derived from this software without specific prior written permission.
00017  
00018  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
00019  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00020  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00021  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00024  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00025  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 ***************************************************************************************************/
00027 
00028 
00029 
00035 #include <driver_monitoring/class_colision_time.h>
00036 
00037 
00038 
00039 visualization_msgs::Marker mark_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster, std::string ns ,int id, float r, float g, float b);
00040 
00041 visualization_msgs::Marker mark_side_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster, std::string ns ,int id, float r, float g, float b);
00042 
00043 visualization_msgs::Marker generic_text(float x, float y, float z , float r, float g, float b, float scale, std::string txt, std::string frm_id, std::string ns);
00044 
00045 
00046 ros::Publisher points_pub;
00047 // front_zone of the car
00048 ros::Publisher marker_fronts_publisher;
00049 ros::Publisher marker_front_text_publisher;
00050 //ros::Publisher marker_generic_text_publisher;
00051 
00052 //side zone of the car
00053 ros::Publisher marker_side_publisher;
00054 ros::Publisher marker_side_text_publisher;
00055 ros::Publisher marker_side_text_blink_publisher;
00056 ros::Publisher marker_generic_text_blink_left_publisher;                        
00057 // class_colision_time colision;
00058 //ros::Publisher marker_front_grid_publisher;
00059 
00060 
00061 tf::TransformListener *listener_center_bumper_ptr;
00062 class_colision_time::TYPE_msg_mtt obstacle_zone_front; 
00063 class_colision_time::TYPE_msg_mtt obstacle_left; 
00064 class_colision_time::TYPE_msg_partial partial_msg;
00065 class_colision_time::TYPE_msg_velocity velocity_msg;
00066 class_colision_time::TYPE_msg_plc plc_msg;
00067 class_colision_time::TYPE_msg_bags colision_time;
00068 
00069 
00077 int cria_txt(int x)
00078 {
00079    FILE *fp;
00080    string nane_file;
00081   
00082    nane_file.append("../");
00083    nane_file.append(colision_time.name_file);  
00084    nane_file.erase(nane_file.end()-4, nane_file.end());
00085    nane_file.append(".txt");  
00086    cout<< "msg_save:"<< colision_time.name_file<<endl;
00087    fp = fopen(nane_file.c_str(),"a+"); //tenta ler o ficheiro já existente
00088 
00089     /* Verificar se a abertura foi feita com sucesso */
00090 
00091         if (fp==NULL) //Não consegue abir o ficheiro
00092         {
00093                 
00094                 cout<<"cannot open file: " << nane_file.c_str() <<endl;
00095                    // return 1;
00096         }
00097                 if (x==1){
00098                         fprintf(fp,"%s \t %s \t %f \t %f \t %f \n", colision_time.name_file.c_str(), colision_time.sit_type_1.c_str(),colision_time.sit_begin_1, colision_time.duration_1,  colision_time.sit_end_1);
00099                         cout<<"cria txt 1"<<endl; 
00100                 }
00101                 if (x==2){
00102                         fprintf(fp,"%s \t %s \t %f \t %f \t %f \n", colision_time.name_file.c_str(), colision_time.sit_type_2.c_str(),colision_time.sit_begin_2, colision_time.duration_2,  colision_time.sit_end_2);
00103                         cout<<"cria txt 2"<<endl; 
00104                 }
00105                 if (x==3){
00106                         fprintf(fp,"%s \t %s \t %f \t %f \t %f \n", colision_time.name_file.c_str(), colision_time.sit_type_3.c_str(),colision_time.sit_begin_3, colision_time.duration_3, colision_time.sit_end_3);
00107                         cout<<"cria txt 3"<<endl; 
00108                 }
00109                 if (x==4){
00110                         fprintf(fp,"%s \t %s \t %f \t %f \t %f \n", colision_time.name_file.c_str(), colision_time.sit_type_4.c_str(),colision_time.sit_begin_4, colision_time.duration_4,  colision_time.sit_end_4);
00111                         cout<<"cria txt 4"<<endl; 
00112                 }
00113                 
00114 //      cout <<"antes de sair."<<endl;
00115      fclose(fp);
00116 
00117   return 0;
00118 };
00119 
00120 
00126 void initialization_variables(void)
00127 {
00128         colision_time.internal_1=0;
00129         colision_time.internal_2=0;
00130         colision_time.internal_3=0;
00131         colision_time.internal_4=0;
00132 }
00133 
00139 void begin_situation(void)
00140 {
00141         //cout<<"entrou no begin_situation "<<endl; 
00142         //cout<<"internal_1: "<< colision_time.internal_1<<" sit_1: "<< colision_time.sit_1<<endl; 
00143         //cout<< "data do ficheiro bag"<<colision_time.bag_time<<endl;
00144 //                      verifica se ainda está em situação de perigo numero 1-> Objecto detectado na parte lateral do carro
00145 
00146         if(colision_time.sit_1==1 && colision_time.internal_1==0) //só entra aqui umavez, pois a segunda o valor internal é 1, logo faz else
00147                 {
00148                         //sacar o tempo da primeira vez que é apanhado a situação tempo inicial
00149                         colision_time.lst_obj_sit_1=ros::Time::now().toSec(); // colision_time.bag_time;
00150                         colision_time.sit_begin_1=ros::Time::now().toSec();
00151                         colision_time.internal_1=1;
00152                 }
00153         if (colision_time.sit_1==1 && colision_time.internal_1==1) //para todas as vezes que seja chamado a verificar a data
00154                 {colision_time.lst_obj_sit_1=ros::Time::now().toSec(); }
00155 
00156         if(ros::Time::now().toSec()-colision_time.lst_obj_sit_1<1 )  //se o tempo que passou for menor que 300 milisegundos assumimos que tem objecto durente esse tempo, para evitar ruido no ficheiro a gravar.
00157                 {
00158                         colision_time.sit_1=1;
00159                         //variavel interna que só é usada uma vez
00160                 }else 
00161                 {
00162                         if(colision_time.sit_1==0 && colision_time.internal_1==1)
00163                         {
00164                                 colision_time.sit_type_1="object detected--> vehicle behind the car";
00165                                 //colision_time.sit_begin=colision_time.lst_obj_sit_1; // inicio da situação
00166                                 colision_time.duration_1=colision_time.bag_time-colision_time.sit_begin_1; //duração da situação
00167                                 colision_time.sit_end_1=colision_time.bag_time; // final da situação
00168                                 
00169                                 //colision_time.sit_1=0;
00170                                 colision_time.internal_1=0;
00171                                 cria_txt(1);
00172                                 
00173                         }
00174                 }
00175 
00176 
00177         if(colision_time.sit_2==1 && colision_time.internal_2==0) //só entra aqui umavez, pois a segunda o valor internal é 1, logo faz else
00178                 {
00179                         //sacar o tempo da primeira vez que é apanhado a situação tempo inicial
00180                         colision_time.lst_obj_sit_2=ros::Time::now().toSec(); // colision_time.bag_time;
00181                         colision_time.sit_begin_2=ros::Time::now().toSec();
00182                         colision_time.internal_2=1;
00183                 }
00184         if (colision_time.sit_2==1 && colision_time.internal_2==1) //para todas as vezes que seja chamado a verificar a data
00185                 {colision_time.lst_obj_sit_2=ros::Time::now().toSec(); }
00186 
00187         if(ros::Time::now().toSec()-colision_time.lst_obj_sit_2<1 )  //se o tempo que passou for menor que 300 milisegundos assumimos que tem objecto durente esse tempo, para evitar ruido no ficheiro a gravar.
00188                 {
00189                         colision_time.sit_2=1;
00190                         //variavel interna que só é usada uma vez
00191                 }else 
00192                 {
00193                         if(colision_time.sit_2==0 && colision_time.internal_2==1)
00194                         {
00195                                 colision_time.sit_type_2="object detected--> Colision Risk";
00196                                 //colision_time.sit_begin=colision_time.lst_obj_sit_1; // inicio da situação
00197                                 colision_time.duration_2=colision_time.bag_time-colision_time.sit_begin_2; //duração da situação
00198                                 colision_time.sit_end_2=colision_time.bag_time; // final da situação
00199                                 
00200                                 //colision_time.sit_1=0;
00201                                 colision_time.internal_2=0;
00202                                 cria_txt(2);
00203                                 cout<<"cria txt 2"<<endl; 
00204                         }
00205                 }
00206 
00207 if(colision_time.sit_3==1 && colision_time.internal_3==0) //só entra aqui umavez, pois a segunda o valor internal é 1, logo faz else
00208                 {
00209                         //sacar o tempo da primeira vez que é apanhado a situação tempo inicial
00210                         colision_time.lst_obj_sit_3=ros::Time::now().toSec(); // colision_time.bag_time;
00211                         colision_time.sit_begin_3=ros::Time::now().toSec();
00212                         colision_time.internal_3=1;
00213                 }
00214         if (colision_time.sit_3==1 && colision_time.internal_3==1) //para todas as vezes que seja chamado a verificar a data
00215                 {colision_time.lst_obj_sit_3=ros::Time::now().toSec(); }
00216 
00217         if(ros::Time::now().toSec()-colision_time.lst_obj_sit_3<1 )  //se o tempo que passou for menor que 300 milisegundos assumimos que tem objecto durente esse tempo, para evitar ruido no ficheiro a gravar.
00218                 {
00219                         colision_time.sit_3=1;
00220                         //variavel interna que só é usada uma vez
00221                 }else 
00222                 {
00223                         if(colision_time.sit_3==0 && colision_time.internal_3==1)
00224                         {
00225                                 colision_time.sit_type_3="object detected--> Forgot to blink left!";
00226                                 //colision_time.sit_begin=colision_time.lst_obj_sit_1; // inicio da situação
00227                                 colision_time.duration_3=colision_time.bag_time-colision_time.sit_begin_3; //duração da situação
00228                                 colision_time.sit_end_3=colision_time.bag_time; // final da situação
00229                                 
00230                                 //colision_time.sit_1=0;
00231                                 colision_time.internal_3=0;
00232                                 cria_txt(3);
00233                                 cout<<"cria txt 3"<<endl; 
00234                         }
00235                 }
00236 
00237 if(colision_time.sit_4==1 && colision_time.internal_4==0) //só entra aqui umavez, pois a segunda o valor internal é 1, logo faz else
00238                 {
00239                         //sacar o tempo da primeira vez que é apanhado a situação tempo inicial
00240                         colision_time.lst_obj_sit_4=ros::Time::now().toSec(); // colision_time.bag_time;
00241                         colision_time.sit_begin_4=ros::Time::now().toSec();
00242                         colision_time.internal_4=1;
00243                 }
00244         if (colision_time.sit_4==1 && colision_time.internal_4==1) //para todas as vezes que seja chamado a verificar a data
00245                 {colision_time.lst_obj_sit_4=ros::Time::now().toSec(); }
00246 
00247         if(ros::Time::now().toSec()-colision_time.lst_obj_sit_4<1 )  //se o tempo que passou for menor que 300 milisegundos assumimos que tem objecto durente esse tempo, para evitar ruido no ficheiro a gravar.
00248                 {
00249                         colision_time.sit_4=1;
00250                         //variavel interna que só é usada uma vez
00251                 }else 
00252                 {
00253                         if(colision_time.sit_4==0 && colision_time.internal_4==1)
00254                         {
00255                                 colision_time.sit_type_4="object detected--> Forgot to blink right";
00256                                 //colision_time.sit_begin=colision_time.lst_obj_sit_1; // inicio da situação
00257                                 colision_time.duration_4=colision_time.bag_time-colision_time.sit_begin_4; //duração da situação
00258                                 colision_time.sit_end_4=colision_time.bag_time; // final da situação
00259                                 
00260                                 //colision_time.sit_1=0;
00261                                 colision_time.internal_4=0;
00262                                 cria_txt(4);
00263                                 cout<<"cria txt 4 "<<endl; 
00264                         }
00265                 }
00266 
00267 };
00268 
00269 
00275 // void topic_callback_partial(atlascar_base::AtlascarPartialStatus AtlascarPartialStatus_msg)
00276 //              {
00277 //                              partial_msg.lights_high=AtlascarPartialStatus_msg.lights_high; 
00278 //                              partial_msg.lights_medium=AtlascarPartialStatus_msg.lights_medium; 
00279 //                              partial_msg.ignition=AtlascarPartialStatus_msg.ignition; 
00280 //                              partial_msg.lights_left=AtlascarPartialStatus_msg.lights_left; 
00281 //                              partial_msg.lights_right=AtlascarPartialStatus_msg.lights_right; 
00282 //                              partial_msg.danger_lights=AtlascarPartialStatus_msg.danger_lights; 
00283 //                              partial_msg.horn=AtlascarPartialStatus_msg.horn; 
00284 //                              partial_msg.throttle=AtlascarPartialStatus_msg.throttle; 
00285 //                              partial_msg.brake=AtlascarPartialStatus_msg.brake; 
00286 //                              partial_msg.clutch=AtlascarPartialStatus_msg.clutch;
00287 //              };
00288 //      
00289 
00295 // void topic_callback_velocity(atlascar_base::AtlascarVelocityStatus AtlascarVelocityStatus_msg)
00296 //              {
00297 //                              velocity_msg.counting=AtlascarVelocityStatus_msg.counting;
00298 //                              velocity_msg.pulses_sec=AtlascarVelocityStatus_msg.pulses_sec;
00299 //                              velocity_msg.revolutions_sec=AtlascarVelocityStatus_msg.revolutions_sec;
00300 //                              velocity_msg.velocity=AtlascarVelocityStatus_msg.velocity;
00301 //              };
00307 // void topic_callback_plc_status(atlascar_base::AtlascarStatus AtlascarStatus_msg)
00308 //              {
00309 //                              plc_msg.steering_wheel=AtlascarStatus_msg.steering_wheel;
00310 //                              plc_msg.rpm=AtlascarStatus_msg.rpm;
00311 //                              cout<<plc_msg <<endl;
00312 //              };
00313                         
00319 void topic_callback_rosout_cool(rosgraph_msgs::Log rosout_msg)
00320                 {
00321                         
00322                         if (rosout_msg.msg[0]=='O' && rosout_msg.msg[1]=='p'&& rosout_msg.msg[2]=='e'&& rosout_msg.msg[6]=='g')
00323                         {
00324                                 char name_file[1024];
00325                                 sscanf(rosout_msg.msg.c_str(),"%*s %s",name_file); 
00326                                 colision_time.name_file= name_file;
00327                                 
00328                                 //cout<< "msg_txt:"<<name_file <<endl;
00329                                 //cria_txt();
00330                         }
00331                 };
00332 
00333                 
00344 void topic_callback(const mtt::TargetListPC::Ptr& msg)
00345 {
00346         colision_time.bag_time=ros::Time::now().toSec();
00347         colision_time.sit_1=0;
00348         colision_time.sit_2=0;
00349         colision_time.sit_3=0;
00350         colision_time.sit_4=0;
00351         
00352         
00353         //cout<<colision_time.bag_time<<" isto foi a data" <<endl;
00354         
00355         PointCloud<PointXYZ> velocity;
00356         PointCloud<PointXYZ> velocity_1;
00357         PointCloud<PointXYZ> position_1; 
00358         PointCloud<PointXYZ> position;
00359   
00360     pcl::PCLPointCloud2 pcl_pc;
00361     pcl_conversions::toPCL(msg->velocity, pcl_pc);
00362     pcl::fromPCLPointCloud2(pcl_pc, velocity_1);
00363     
00364     pcl_conversions::toPCL(msg->position, pcl_pc);
00365     pcl::fromPCLPointCloud2(pcl_pc, position_1);
00366     
00367 //      fromROSMsg(msg->velocity,velocity_1);
00368 //      fromROSMsg(msg->position,position_1);
00369         
00370         tf::StampedTransform transform;
00371     try
00372       {
00373                 listener_center_bumper_ptr->lookupTransform("/atc/vehicle/center_bumper", msg->header.frame_id, ros::Time(0), transform);
00374       }
00375     catch (tf::TransformException ex)
00376       {
00377                 ROS_ERROR("%s",ex.what());
00378       }
00379                 
00380                         pcl_ros::transformPointCloud (position_1,position,transform); 
00381                         pcl_ros::transformPointCloud (velocity_1,velocity,transform);
00382                         position.header.frame_id="/atc/vehicle/center_bumper";
00383                         velocity.header.frame_id="/atc/vehicle/center_bumper";
00384                         
00385                         PointCloud<PointXYZ>::Ptr front_zone (new PointCloud<PointXYZ> ());
00386                         front_zone->header.frame_id="/atc/vehicle/center_bumper";
00387                         
00388                         
00389                         PointCloud<PointXYZ>::Ptr left_zone (new PointCloud<PointXYZ> ());
00390                         left_zone->header.frame_id="/atc/vehicle/center_bumper";
00391         
00392         
00393         PointXYZ point;
00394         //PointXYZ point_side_left;
00395         for (int i=0; i<(int)position.size(); ++i)
00396         {
00397           point=position.points[i];
00398               //Front of the car!!
00399           if (point.x>0 && point.x<40 && point.y>-1 && point.y<1)
00400               {
00401                 front_zone->points.push_back(point);
00402                 obstacle_zone_front.id=msg->id[i];
00403                 obstacle_zone_front.x=point.x;
00404                 obstacle_zone_front.y=point.y;
00405                 obstacle_zone_front.z=point.z;
00406                 obstacle_zone_front.v_x=velocity[i].x;
00407                 obstacle_zone_front.v_y=velocity[i].y;
00408                 obstacle_zone_front.v_z=velocity[i].z;
00409               }  
00410 
00411           if (point.x>-40 && point.x<-0.5 && point.y>1.2 && point.y<3.5)
00412               {
00413                 left_zone->points.push_back(point);
00414                 obstacle_left.id=msg->id[i];
00415                 obstacle_left.x=point.x;
00416                 obstacle_left.y=point.y;
00417                 obstacle_left.z=point.z;
00418                 obstacle_left.v_x=velocity[i].x;
00419                 obstacle_left.v_y=velocity[i].y;
00420                 obstacle_left.v_z=velocity[i].z;
00421               }  
00422           
00423                 }
00424 
00425       sensor_msgs::PointCloud2 ptc_front;
00426       toROSMsg(*front_zone,ptc_front);
00427       ptc_front.header.frame_id="/atc/vehicle/center_bumper";
00428       points_pub.publish(ptc_front);
00429       
00430       
00431       sensor_msgs::PointCloud2 ptc_side;
00432       toROSMsg(*left_zone,ptc_side);
00433       ptc_side.header.frame_id="/atc/vehicle/center_bumper";
00434       points_pub.publish(ptc_side);
00435       
00436       
00437       
00441       
00442       //reference of points with a cube
00443       visualization_msgs::Marker marker_front=mark_cluster(front_zone, "front_cube" ,0, 0, 0, 1);
00444       marker_fronts_publisher.publish(marker_front);
00445 
00446       //cout <<obstacle_zone_front <<endl;
00447       //condição para entrar na situação de risco!!
00448       float velocity_car_front;
00449       float time_car_front;
00450       velocity_car_front=obstacle_zone_front.v_x+velocity_msg.velocity;
00451       time_car_front=obstacle_zone_front.x/obstacle_zone_front.v_x;
00452       
00453       cout<<"V Atlascar ->"<< velocity_msg.velocity<<endl;
00454       cout<<"V objecto->"<< obstacle_zone_front.v_x<< endl;
00455       cout<<"V total ->"<< velocity_car_front <<endl;
00456       cout<<"eime total ->"<<time_car_front <<endl;
00457       
00458           if(time_car_front>-4 && time_car_front< 0)//obstacle_zone_front.x < 10 && obstacle_zone_front.v_x < -2)
00459               {
00460                 colision_time.sit_2=1;
00461                 string msg_text="Colision Risk!!";
00462                 visualization_msgs::Marker marker_front_text_front=generic_text( obstacle_zone_front.x , obstacle_zone_front.y, obstacle_zone_front.z , 1, 0, 0, 1, msg_text , "/atc/vehicle/center_bumper", "front_warning");
00463                         
00464                 marker_front_text_publisher.publish(marker_front_text_front);    
00465                       
00466                   //inserir condição para caso entre aqui, contar o tempo que aqui passou, 
00467                   //terá um intervalo superior a 0,2segundos, para verificar que ainda tem alguma.
00468                 
00469               }
00470       //tratamento de dados, tentar visualizar a velocidade em x do ponto.
00471      
00472       
00476        
00477       
00478       //reference of points with a cube
00479       visualization_msgs::Marker marker_side=mark_side_cluster(left_zone, "side_cube" ,0, 0, 0, 1);
00480       marker_side_publisher.publish(marker_side);
00481       
00482       
00486       //reference to text and id of the point more 
00487 
00488       //cout<<"nuvem de pontos esquerda"<<left_zone->points.size()<<endl;
00489       long int exist_points_side=left_zone->points.size();
00490       if(exist_points_side>0)
00491           {
00492                 colision_time.sit_1=1;
00493                 
00494             string msg_text_side="OBJECT DETECTED";
00495             visualization_msgs::Marker marker_side_text =generic_text( 0 , obstacle_left.y, 2 , 0, 0, 0.487, 1, msg_text_side ,"/atc/vehicle/center_bumper","cannot_pass");
00496         
00497             marker_side_text_publisher.publish(marker_side_text);           
00498           }/*else{colision_time.sit_1=0;}*/
00499           
00503       
00504           if( partial_msg.lights_left==0 &&  plc_msg.steering_wheel<(-0.315)  ) //falta inserir se existe alguem a frente do carro!!
00505         {
00506           colision_time.sit_3=1;
00507           string msg_blink_side="Forgot to blink left!";
00508             
00509           visualization_msgs::Marker marker_side_text_left_blink= generic_text( 3 , 6, 2 , 0, 0, 1, 1, msg_blink_side ,"/atc/vehicle/center_bumper","Blink_left");
00510           
00511           marker_generic_text_blink_left_publisher.publish(marker_side_text_left_blink);
00512           //marker_side_text_blink_publisher.publish(marker_side_text_blink);
00513         }
00514          
00518       
00519          //long int exist_points_front=front_zone->points.size();
00520          if(  partial_msg.lights_right==0 && plc_msg.steering_wheel>(-0.275) && plc_msg.steering_wheel!=0 ) //falta inserir se existe alguem a frente do carro!!
00521         {
00522           colision_time.sit_4=1;
00523           string msg_blink_side="Forgot to blink right!";
00524             
00525           visualization_msgs::Marker marker_side_text_right_blink= generic_text(3 , -6, 2 , 0, 0, 1, 1, msg_blink_side ,"/atc/vehicle/center_bumper","Blink_right");
00526           
00527           marker_side_text_blink_publisher.publish(marker_side_text_right_blink);
00528         }
00529         
00530         begin_situation();
00531  
00532 //  plc_msg={0};
00533 // obstacle_zone_front={0};
00534         obstacle_zone_front.v_x =0;
00535 };
00536 
00537 
00538                 
00544 int main (int argc, char **argv)
00545 {
00546   ROS_INFO("Starting colision time node.");
00547   
00548   ros::init(argc,argv,"colision_time"); 
00549   ros::NodeHandle n;
00550   
00551   initialization_variables();
00552   
00553   //class_colision_time cenas_fixes;
00554   
00555   tf::TransformListener listener_center_bumper;   // atc/vehicle/center_bumper
00556   listener_center_bumper_ptr=&listener_center_bumper;
00557   
00558   //   Subscribe mtt message
00559   ros::Subscriber sub = n.subscribe("/mtt/trck/targets", 1, topic_callback);
00560 //   ros::Subscriber sub_status_plc = n.subscribe("/atc/base/status/plc", 1, topic_callback_plc_status);
00561 //   ros::Subscriber sub_partial_status = n.subscribe("/partial_status", 1, topic_callback_partial);
00562 //   ros::Subscriber sub_velocity_status = n.subscribe("/velocity_status", 1, topic_callback_velocity);
00563   ros::Subscriber sub_rosout =n.subscribe("/rosout_agg", 1, topic_callback_rosout_cool);
00564   
00565   
00566   ROS_ERROR("AtlascarPartialStatus and AtlascarVelocityStatus no longer avaliable, please correct!!");
00567 //   ros::Subscriber sub_status_plc = n.subscribe("/vhc/plc/status", 1, topic_callback_plc_status);
00568 //   ros::Subscriber sub_partial_status = n.subscribe("/vhc/driver/status", 1, topic_callback_partial);
00569 //   ros::Subscriber sub_velocity_status = n.subscribe("/vhc/velocity/status", 1, topic_callback_velocity);
00570   
00571   
00572   
00573   //  Publicador de pontos dentro da região
00574   points_pub = n.advertise<sensor_msgs::PointCloud2>("/atc/monitoring/danger_zone", 1);
00575  
00576 //   cubo frontal
00577   marker_fronts_publisher= n.advertise<visualization_msgs::Marker>("/prcp/front_mrk", 1000);
00578     
00579   //cubo lateral
00580   marker_side_publisher= n.advertise<visualization_msgs::Marker>("/prcp/side_mrk", 1000);
00581   
00582   //colision Risk
00583   marker_front_text_publisher= n.advertise<visualization_msgs::Marker>("/prcp/front_text_mrk", 1000);
00584   
00585   //objecto detectado zona na lateral
00586   marker_side_text_publisher= n.advertise<visualization_msgs::Marker>("/prcp/side_text_mrk", 1000);
00587 
00588   
00589   //lado direito
00590   marker_side_text_blink_publisher= n.advertise<visualization_msgs::Marker>("/prcp/side_text_blink_right_mrk", 1000);
00591   
00592   //lado esquerdo
00593   marker_generic_text_blink_left_publisher= n.advertise<visualization_msgs::Marker>("/prcp/side_text_blink_left_mrk", 1000);
00594   
00595   
00596  
00597   ros::spin();
00598   
00599   return 1;
00600 }
00601 
00602 
00603                 
00618 visualization_msgs::Marker generic_text(float x, float y, float z , float r,
00619 float g, float b, float scale, std::string txt, std::string frm_id, std::string
00620 ns)
00621 {
00622   uint32_t shape = visualization_msgs::Marker::TEXT_VIEW_FACING;
00623   visualization_msgs::Marker marker_front;
00624   
00625   marker_front.header.frame_id = frm_id;
00626   marker_front.header.stamp = ros::Time::now();
00627   
00628   
00629   marker_front.ns = ns;
00630   marker_front.id = 0;
00631   marker_front.type = shape;
00632   marker_front.action = visualization_msgs::Marker::ADD;
00633   
00634   marker_front.pose.position.x = x;
00635   marker_front.pose.position.y = y;
00636   marker_front.pose.position.z = z;
00637   marker_front.scale.z = scale;
00638   
00639    
00640   //message to send in the msg.
00641   
00642   marker_front.text=txt;
00643  
00644   marker_front.color.r = r;
00645   marker_front.color.g = g;
00646   marker_front.color.b = b;
00647   marker_front.color.a = 0.8;
00648   
00649   marker_front.lifetime = ros::Duration(0.4);
00650   return marker_front;
00651 }
00652 
00653 
00654 
00655 
00656 
00657 
00668 visualization_msgs::Marker mark_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster, std::string ns ,int id, float r, float g, float b)
00669 {
00670   Eigen::Vector4f centroid;
00671   Eigen::Vector4f min;
00672   Eigen::Vector4f max;
00673   
00674   pcl::compute3DCentroid (*cloud_cluster, centroid);
00675   pcl::getMinMax3D (*cloud_cluster, min, max);
00676   
00677   uint32_t shape = visualization_msgs::Marker::CUBE;
00678   visualization_msgs::Marker marker_front;
00679   marker_front.header.frame_id = cloud_cluster->header.frame_id;
00680   marker_front.header.stamp = ros::Time::now();
00681   
00682   marker_front.ns = ns;
00683   marker_front.id = id;
00684   marker_front.type = shape;
00685   marker_front.action = visualization_msgs::Marker::ADD;
00686   
00687   
00688   //market's position is in the minimum x cordinate of the point
00689   marker_front.pose.position.x = min[0];
00690   marker_front.pose.position.y = centroid[1];
00691   marker_front.pose.position.z = centroid[2];
00692   marker_front.pose.orientation.x = 0.0;
00693   marker_front.pose.orientation.y = 0.0;
00694   marker_front.pose.orientation.z = 0.0;
00695   marker_front.pose.orientation.w = 1.0;
00696   
00697   marker_front.scale.x = 1;//(max[0]-min[0]);
00698   marker_front.scale.y = 1;//(max[1]-min[1]);
00699   marker_front.scale.z = 1;//(max[2]-min[2]);
00700 
00701   marker_front.color.r = r;
00702   marker_front.color.g = g;
00703   marker_front.color.b = b;
00704   marker_front.color.a = 0.5;
00705   
00706 //   marker_front.lifetime = ros::Duration();
00707     marker_front.lifetime = ros::Duration(0.3);
00708   return marker_front;
00709 }
00710 
00711 
00712 
00713 
00714 
00725 visualization_msgs::Marker mark_side_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster, std::string ns ,int id, float r, float g, float b)
00726 {
00727   Eigen::Vector4f centroid;
00728   Eigen::Vector4f min;
00729   Eigen::Vector4f max;
00730   
00731   pcl::compute3DCentroid (*cloud_cluster, centroid);
00732   pcl::getMinMax3D (*cloud_cluster, min, max);
00733   
00734   uint32_t shape = visualization_msgs::Marker::CUBE;
00735   visualization_msgs::Marker marker_side;
00736   marker_side.header.frame_id = cloud_cluster->header.frame_id;
00737   marker_side.header.stamp = ros::Time::now();
00738   
00739   marker_side.ns = ns;
00740   marker_side.id = id;
00741   marker_side.type = shape;
00742   marker_side.action = visualization_msgs::Marker::ADD;
00743   
00744   
00745   //market's position is in the minimum x cordinate of the point
00746   marker_side.pose.position.x = max[0];
00747   marker_side.pose.position.y = centroid[1];
00748   marker_side.pose.position.z = centroid[2];
00749   marker_side.pose.orientation.x = 0.0;
00750   marker_side.pose.orientation.y = 0.0;
00751   marker_side.pose.orientation.z = 0.0;
00752   marker_side.pose.orientation.w = 1.0;
00753   
00754   marker_side.scale.x = 1;//(max[0]-min[0]);
00755   marker_side.scale.y = 1;//(max[1]-min[1]);
00756   marker_side.scale.z = 1;//(max[2]-min[2]);
00757 
00758   marker_side.color.r = r;
00759   marker_side.color.g = g;
00760   marker_side.color.b = b;
00761   marker_side.color.a = 1;
00762   
00763 //   marker_front.lifetime = ros::Duration();
00764     marker_side.lifetime = ros::Duration(0.3);
00765   return marker_side;
00766 }
00767 


driver_monitoring
Author(s): Andre Oliveira
autogenerated on Thu Nov 20 2014 11:35:23