recognition.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
35 
36 
37 
39 
41 FILE *fp;
42 
48 int cria_txt(void)
49 {
50 
51  string nane_file;
52 
53  nane_file.append("../");
54  nane_file.append(recognition.name_file);
55  nane_file.erase(nane_file.end()-4, nane_file.end());
56  nane_file.append(".txt");
57 
58  fp = fopen(nane_file.c_str(),"a+"); //tenta ler o ficheiro já existente
59  /* Verificar se a abertura foi feita com sucesso */
60 
61  if (fp==NULL) //Não consegue abir o ficheiro
62  {
63  cout<<"cannot open file: recognition_data.txt" <<endl;
64  return 1;
65  }
66 
67  fprintf(fp,"%s \t %f \t %d \t %d \t %d \t %d \t %d \t %d \t %f \t %f \t %f\n",
68  recognition.name_file.c_str(),
69  recognition.bag_time,
70  partial_msg.ignition,
71  partial_msg.lights_left,
72  partial_msg.lights_right,
73  partial_msg.throttle,
74  partial_msg.brake,
75  partial_msg.clutch,
76  partial_msg.velocity,
77  partial_msg.steering_wheel,
78  partial_msg.rpm);
79 
80 
81 
82  fclose(fp);
83 
84  return 0;
85 };
86 
87 
88 
89 
95 // void topic_callback_partial(atlascar_base::AtlascarPartialStatus AtlascarPartialStatus_msg)
96 // {
97 // partial_msg.lights_high=AtlascarPartialStatus_msg.lights_high;
98 // partial_msg.lights_medium=AtlascarPartialStatus_msg.lights_medium;
99 // partial_msg.ignition=AtlascarPartialStatus_msg.ignition;
100 // partial_msg.lights_left=AtlascarPartialStatus_msg.lights_left;
101 // partial_msg.lights_right=AtlascarPartialStatus_msg.lights_right;
102 // partial_msg.danger_lights=AtlascarPartialStatus_msg.danger_lights;
103 // partial_msg.horn=AtlascarPartialStatus_msg.horn;
104 // partial_msg.throttle=AtlascarPartialStatus_msg.throttle;
105 // partial_msg.brake=AtlascarPartialStatus_msg.brake;
106 // partial_msg.clutch=AtlascarPartialStatus_msg.clutch;
107 // recognition.bag_time=ros::Time::now().toSec();
108 // };
115 // void topic_callback_velocity(atlascar_base::AtlascarVelocityStatus AtlascarVelocityStatus_msg)
116 // {
117 // partial_msg.velocity=AtlascarVelocityStatus_msg.velocity;
118 // //uma vez que é a mensagem que chag mais tarde a ser actualizada achei por bem recolher os dqados na mesma frequencia, isto é 9hz, paso queira confirmar faça rostopic hz /vhc/driver/status
119 //
120 // cria_txt();
121 // };
127 // void topic_callback_plc_status(atlascar_base::AtlascarStatus AtlascarStatus_msg)
128 // {
129 // partial_msg.steering_wheel=AtlascarStatus_msg.steering_wheel;
130 // partial_msg.rpm=AtlascarStatus_msg.rpm;
131 //
132 //
133 // };
134 
135 
141 void topic_callback_rosout(rosgraph_msgs::Log rosout_msg)
142  {
143 
144  if (rosout_msg.msg[0]=='O' && rosout_msg.msg[1]=='p'&& rosout_msg.msg[2]=='e'&& rosout_msg.msg[6]=='g')
145  {
146  char name_file[1024];
147 
148  string names;
149 
150  sscanf(rosout_msg.msg.c_str(),"%*s %s",name_file);
151 
152 
153  recognition.name_file=name_file;
154 
155 
156  }
157  };
158 
165 {
166 
167  fp = fopen("../recognition_data.txt","a+"); //tenta ler o ficheiro já existente
168 
169  fprintf(fp,"%s \t %s \t %s \t %s \t %s \t %s \t %s \t %s \t %s \t %s \t %s\n",
170  "name of file" ,
171  "bag time",
172  "ignition",
173  "lights_left",
174  "lights_right",
175  "throttle",
176  "brake",
177  "clutch",
178  "velocity",
179  "steering_wheel",
180  "rpm");
181  fclose(fp);
182 }
183 
184 
190 int main (int argc, char **argv)
191 {
192  ROS_INFO("Starting recognition_data node.");
193 
195 
196  ros::init(argc,argv,"recognition");
197  ros::NodeHandle n;
198 
199  ROS_ERROR("AtlascarStatus and AtlascarVelocityStatus no longer avaliable, please correct!!");
200 // ros::Subscriber sub = n.subscribe("/mtt/targets", 1, topic_callback);
201 // ros::Subscriber sub_status_plc = n.subscribe("/vhc/plc/status", 1, topic_callback_plc_status);
202 // ros::Subscriber sub_partial_status = n.subscribe("/vhc/driver/status", 1, topic_callback_partial);
203 // ros::Subscriber sub_velocity_status = n.subscribe("/vhc/velocity/status", 1, topic_callback_velocity);
204  ros::Subscriber sub_rosout =n.subscribe("/rosout_agg", 1, topic_callback_rosout);
205 // ros::Subscriber sub_status_plc = n.subscribe("/atc/base/status/plc", 1, topic_callback_plc_status);
206 // ros::Subscriber sub_partial_status = n.subscribe("/partial_status", 1, topic_callback_partial);
207 // ros::Subscriber sub_velocity_status = n.subscribe("/velocity_status", 1, topic_callback_velocity);
208 
209 
210  ros::spin();
211 
212  return 1;
213 }
void create_head_of_file(void)
Function that organizes the variables in the txt file.
to store the variables of driver monitoring arduino
Nodelet that recieves ros msg's from a bag file and then prints to a text file,.
int main(int argc, char **argv)
main of program
class_recognition::TYPE_msg_bags recognition
Definition: recognition.cpp:40
void topic_callback_rosout(rosgraph_msgs::Log rosout_msg)
Callback to save the msg from driver monitoring Arduino.
FILE * fp
Definition: recognition.cpp:41
class_recognition::TYPE_msg_partial partial_msg
Definition: recognition.cpp:38
to store the name of the bag file played
int cria_txt(void)
Create a txt file with the information needed to use in matlab.
Definition: recognition.cpp:48


driver_recognition
Author(s): Andre Oliveira
autogenerated on Mon Mar 2 2015 01:31:38