bag2txt.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 ***************************************************************************************************/
27 
28 #include <unistd.h>
29 
30 #include <iostream>
31 #include <string>
32 #include <vector>
33 #include <map>
34 #include <fstream>
35 
36 #include <ros/ros.h>
37 
38 #include <tf/transform_listener.h>
39 
40 #include <visualization_msgs/Marker.h>
41 #include <visualization_msgs/MarkerArray.h>
42 
43 #include <haptic_force/Force.h>
44 #include <pressure_cells/Cop.h>
45 #include <phantom_control/State.h>
46 #include <humanoid_control/Humanoid.h>
47 #include <pressure_cells/SenVal.h>
48 
49 using namespace std;
50 using namespace ros;
51 
53 {
54  public:
55 
57  n_("~")
58  {
59  arduino_1_values_report_name_ = ros::names::remap("arduino_1_values_report");
60  arduino_2_values_report_name_ = ros::names::remap("arduino_2_values_report");
61 
62  cop_left_right_report_name_ = ros::names::remap("cop_left_right_report");
63  cop_left_report_name_ = ros::names::remap("cop_left_report");
64  cop_right_report_name_ = ros::names::remap("cop_right_report");
65 
66  force_report_name_ = ros::names::remap("force_report_name_");
67  humanoid_state_report_name_ = ros::names::remap("humanoid_state_report");
68  phantom_state_report_name_ = ros::names::remap("phantom_state_report");
69 
70  remove(arduino_1_values_report_name_.c_str());
71  remove(arduino_2_values_report_name_.c_str());
72 
73  remove(cop_left_right_report_name_.c_str());
74  remove(cop_left_report_name_.c_str());
75  remove(cop_right_report_name_.c_str());
76 
77  remove(force_report_name_.c_str());
78  remove(humanoid_state_report_name_.c_str());
79  remove(phantom_state_report_name_.c_str());
80 
81  arduino_1_handler_ = n_.subscribe<pressure_cells::SenVal> ("/arduino_1_values",1000,boost::bind(&Conversion::ArduinoHandler,this,_1,arduino_1_values_report_name_));
82  arduino_2_handler_ = n_.subscribe<pressure_cells::SenVal> ("/arduino_2_values",1000,boost::bind(&Conversion::ArduinoHandler,this,_1,arduino_2_values_report_name_));
83 
84  cop_left_right_handler_ = n_.subscribe<pressure_cells::Cop> ("/cop_left_right",1000,boost::bind(&Conversion::COPHandler,this,_1,cop_left_right_report_name_));
85  cop_left_handler_ = n_.subscribe<pressure_cells::Cop> ("/cop_left",1000,boost::bind(&Conversion::COPHandler,this,_1,cop_left_report_name_));
86  cop_right_handler_ = n_.subscribe<pressure_cells::Cop> ("/cop_right",1000,boost::bind(&Conversion::COPHandler,this,_1,cop_right_report_name_));
87 
88  force_report_handler_ = n_.subscribe ("/force",1000, &Conversion::ForceHandler, this);
89 
90  humanoid_state_handler_ = n_.subscribe("/humanoid_state",1000, &Conversion::HumanoidHandler, this);
91 
92  phantom_state_handler_ = n_.subscribe ("/phantom_state",1000, &Conversion::PhantomHandler, this);
93  }
94 
96  {
97 
98  }
99 
100  void ArduinoHandler(const pressure_cells::SenVal::ConstPtr& ard_values, string report_name)
101  {
102  ofstream report_ard;
103  report_ard.open(report_name.c_str(),ios::app);
104 
105  boost::format fm("%.6f");// %.13f %.13f %.13f %.13f");
106  fm % ard_values->header.stamp.toSec();// % ard_values.sen1 % ard_values.sen2 % ard_values.sen3 % ard_values.sen4;
107 
108  report_ard<<ard_values->header.seq<<" "<<fm.str()<<" "<< ard_values->sen1<<" "<< ard_values->sen2 <<" "<< ard_values->sen3 <<" "<<ard_values->sen4<<endl;
109 
110  report_ard.close();
111  }
112 
113  void COPHandler(const pressure_cells::Cop::ConstPtr& cop_values, string report_name)
114  {
115  ofstream report_cop;
116  report_cop.open(report_name.c_str(),ios::app);
117 
118  boost::format fm("%.6f");
119  fm % cop_values->header.stamp.toSec() ;
120 
121  report_cop<<cop_values->header.seq<<" "<<fm.str()<<" "<< cop_values->copx <<" "<<cop_values->copy<<endl;
122 
123  report_cop.close();
124  }
125 
126  void ForceHandler(const haptic_force::ForcePtr& force_values)
127  {
128  ofstream report_force;
129  report_force.open(force_report_name_.c_str(),ios::app);
130 
131  boost::format fm("%.6f");
132  fm % force_values->header.stamp.toSec();
133 
134  report_force<<force_values->header.seq<<" "<<fm.str()<<" "<< force_values->force[0]<<" "<< force_values->force[1]<<" "<< force_values->force[2]<<endl;
135 
136  report_force.close();
137 
138  }
139 
140  void HumanoidHandler(const humanoid_control::HumanoidPtr& humanoid_values)
141  {
142  ofstream report_humanoid;
143  report_humanoid.open(humanoid_state_report_name_.c_str(),ios::app);
144 
145  boost::format fm("%.6f");
146  fm % humanoid_values->header.stamp.toSec();
147 
148  report_humanoid<<humanoid_values->header.seq<<" "<<fm.str();
149 
150  for (int i = 0; i < 12; i++)
151  {
152  report_humanoid<<" "<<humanoid_values->speed_wanted[i];
153  }
154  for (int i = 0; i < 12; i++)
155  {
156  report_humanoid<<" "<<humanoid_values->joint_now[i];
157  }
158  for (int i = 0; i < 12; i++)
159  {
160  report_humanoid<<" "<<humanoid_values->joint_wanted[i];
161  }
162 
163  report_humanoid<<endl;
164 
165  report_humanoid.close();
166 
167  }
168 
169  void PhantomHandler(const phantom_control::StatePtr& phantom_values)
170  {
171  ofstream report_phantom;
172  report_phantom.open(phantom_state_report_name_.c_str(),ios::app);
173 
174  boost::format fm("%.6f");
175  fm % phantom_values->header.stamp.toSec();
176 
177  report_phantom<<phantom_values->header.seq<<" "<<fm.str();
178 
179  for (int i = 0; i < 3; i++)
180  {
181  report_phantom<<" "<<phantom_values->position[i];
182  }
183  for (int i = 0; i < 3; i++)
184  {
185  report_phantom<<" "<<phantom_values->rot[i];
186  }
187  for (int i = 0; i < 3; i++)
188  {
189  report_phantom<<" "<<phantom_values->joints[i];
190  }
191  for (int i = 0; i < 3; i++)
192  {
193  report_phantom<<" "<<phantom_values->force[i];
194  }
195  for (int i = 0; i < 2; i++)
196  {
197  report_phantom<<" "<<phantom_values->buttons[i];
198  }
199 
200  report_phantom<<" "<<phantom_values->home;
201 
202  for (int i = 0; i < 3; i++)
203  {
204  report_phantom<<" "<<phantom_values->home_pos[i];
205  }
206 
207  report_phantom<<endl;
208 
209  report_phantom.close();
210 
211  }
212 
215 
219 
223 
224  ros::Subscriber arduino_1_handler_;
225  ros::Subscriber arduino_2_handler_;
226 
227  ros::Subscriber cop_left_right_handler_;
228  ros::Subscriber cop_left_handler_;
229  ros::Subscriber cop_right_handler_;
230 
231  ros::Subscriber force_report_handler_;
232  ros::Subscriber humanoid_state_handler_;
233  ros::Subscriber phantom_state_handler_;
234 
235  ros::NodeHandle n_;
236 };
237 
238 int main(int argc,char**argv)
239 {
240  ros::init(argc, argv, "bag2txt");
241 
242  Conversion convert;
243 
244  cout<<"spining ..."<<endl;
245  ros::spin();
246 
247  return 0;
248 }
string cop_left_right_report_name_
Definition: bag2txt.cpp:216
ros::NodeHandle n_
Definition: bag2txt.cpp:235
ros::Subscriber cop_right_handler_
Definition: bag2txt.cpp:229
string force_report_name_
Definition: bag2txt.cpp:220
string phantom_state_report_name_
Definition: bag2txt.cpp:222
void HumanoidHandler(const humanoid_control::HumanoidPtr &humanoid_values)
Definition: bag2txt.cpp:140
ros::Subscriber phantom_state_handler_
Definition: bag2txt.cpp:233
void ForceHandler(const haptic_force::ForcePtr &force_values)
Definition: bag2txt.cpp:126
string humanoid_state_report_name_
Definition: bag2txt.cpp:221
string cop_right_report_name_
Definition: bag2txt.cpp:218
ros::Subscriber force_report_handler_
Definition: bag2txt.cpp:231
ros::Subscriber arduino_1_handler_
Definition: bag2txt.cpp:224
void ArduinoHandler(const pressure_cells::SenVal::ConstPtr &ard_values, string report_name)
Definition: bag2txt.cpp:100
ros::Subscriber humanoid_state_handler_
Definition: bag2txt.cpp:232
void COPHandler(const pressure_cells::Cop::ConstPtr &cop_values, string report_name)
Definition: bag2txt.cpp:113
Conversion()
Definition: bag2txt.cpp:56
~Conversion()
Definition: bag2txt.cpp:95
string arduino_2_values_report_name_
Definition: bag2txt.cpp:214
void PhantomHandler(const phantom_control::StatePtr &phantom_values)
Definition: bag2txt.cpp:169
ros::Subscriber arduino_2_handler_
Definition: bag2txt.cpp:225
ros::Subscriber cop_left_handler_
Definition: bag2txt.cpp:228
string arduino_1_values_report_name_
Definition: bag2txt.cpp:213
int main(int argc, char **argv)
Definition: bag2txt.cpp:238
string cop_left_report_name_
Definition: bag2txt.cpp:217
ros::Subscriber cop_left_right_handler_
Definition: bag2txt.cpp:227


humanoid_control
Author(s): Emilio Estrelinha, César Sousa
autogenerated on Mon Mar 2 2015 01:31:42