record_data.cpp
Go to the documentation of this file.
1 
14 #include <sys/stat.h>
15 
16 using namespace std;
17 
18 string dir_path;
20 
21 int simulator_state(4);
22 double simulationTime (0);
23 
24 
25 template <typename T> string NumberToString ( T Number )
26 {
27  ostringstream ss;
28  ss << setprecision(1) << Number;
29  return ss.str();
30 }
31 
32 
33 void simulationState(const vrep_common::VrepInfo& msg)
34 {
35  if (simulator_state == 5 && msg.simulatorState.data == 4) /* Simulation stopped. */
36  ros::shutdown();
37 
38  simulator_state = msg.simulatorState.data;
39  simulationTime = msg.simulationTime.data;
40 
41  cout << "Simulations time [s]: " << simulationTime << endl;
42  cout << "--------------------------------------" << endl;
43 }
44 
45 
46 void recordCOP(const geometry_msgs::PointStamped& msg)
47 {
48  /*string location ("/home/phua3-lar/Experiments/Results/");
49  string path = location + date_time + '_' + "recorded_cop" + ".csv";*/
50  string path = dir_path + "recorded_cop" + ".csv";
51 
52  ofstream recorded_cop(path.c_str(), ios::app);
53 
54  if (recorded_cop.is_open())
55  {
56  recorded_cop << msg.header.stamp.sec << "," << msg.point.x << "," << msg.point.y << "," << msg.point.z << "\n";
57  recorded_cop.close();
58  }
59  else
60  cout << "Unable to open file." << endl;
61 }
62 
63 
64 void recordCOP_filtered(const geometry_msgs::PointStamped& msg)
65 {
66  string path = dir_path + "recorded_cop_filtered" + ".csv";
67 
68  ofstream recorded_cop_filtered(path.c_str(), ios::app);
69 
70  if (recorded_cop_filtered.is_open())
71  {
72  recorded_cop_filtered << msg.header.stamp.sec << "," << msg.point.x << "," << msg.point.y << "," << msg.point.z << "\n";
73  recorded_cop_filtered.close();
74  }
75  else
76  cout << "Unable to open file." << endl;
77 }
78 
79 
80 void recordPHUA(const geometry_msgs::PoseStamped& msg)
81 {
82  string path = dir_path + "recorded_phua" + ".csv";
83 
84  ofstream recorded_phua(path.c_str(), ios::app);
85 
86  if (recorded_phua.is_open())
87  {
88  recorded_phua << msg.header.stamp.sec << "," << msg.pose.position.x << "," << msg.pose.position.y << "," << msg.pose.position.z - 0.075 << "\n";
89  recorded_phua.close();
90  }
91  else
92  cout << "Unable to open file." << endl;
93 }
94 
95 
96 void recordPHUA_theoretical(const geometry_msgs::PointStamped& msg)
97 {
98  string path = dir_path + "recorded_phua_theoretical" + ".csv";
99 
100  ofstream recorded_phua_theoretical(path.c_str(), ios::app);
101 
102  if (recorded_phua_theoretical.is_open())
103  {
104  recorded_phua_theoretical << msg.header.stamp.sec << "," << -msg.point.x << "," << -msg.point.y << "," << -msg.point.z << "\n";
105  recorded_phua_theoretical.close();
106  }
107  else
108  cout << "Unable to open file." << endl;
109 }
110 
111 
112 void recordReaction(const geometry_msgs::Vector3Stamped& msg)
113 {
114  string path = dir_path + "recorded_reaction" + ".csv";
115 
116  ofstream recorded_reaction(path.c_str(), ios::app);
117 
118  if (recorded_reaction.is_open())
119  {
120  recorded_reaction << msg.header.stamp.sec << "," << msg.vector.x << "," << msg.vector.y << "," << msg.vector.z << "\n";
121  recorded_reaction.close();
122  }
123  else
124  cout << "Unable to open file." << endl;
125 }
126 
127 
128 void recordForce_stab(const geometry_msgs::Vector3Stamped& msg)
129 {
130  string path = dir_path + "recorded_force_stab" + ".csv";
131 
132  ofstream recorded_force_stab(path.c_str(), ios::app);
133 
134  if (recorded_force_stab.is_open())
135  {
136  recorded_force_stab << msg.header.stamp.sec << "," << msg.vector.x << "," << msg.vector.y << "," << msg.vector.z << "\n";
137  recorded_force_stab.close();
138  }
139  else
140  cout << "Unable to open file." << endl;
141 }
142 
143 
144 void recordForce_instab(const geometry_msgs::Vector3Stamped& msg)
145 {
146  string path = dir_path + "recorded_force_instab" + ".csv";
147 
148  ofstream recorded_force_instab(path.c_str(), ios::app);
149 
150  if (recorded_force_instab.is_open())
151  {
152  recorded_force_instab << msg.header.stamp.sec << "," << msg.vector.x << "," << msg.vector.y << "," << msg.vector.z << "\n";
153  recorded_force_instab.close();
154  }
155  else
156  cout << "Unable to open file." << endl;
157 }
158 
159 
160 void recordForce(const geometry_msgs::Vector3Stamped& msg)
161 {
162  string path = dir_path + "recorded_force" + ".csv";
163 
164  ofstream recorded_force(path.c_str(), ios::app);
165 
166  if (recorded_force.is_open())
167  {
168  recorded_force << msg.header.stamp.sec << "," << msg.vector.x << "," << msg.vector.y << "," << msg.vector.z << "\n";
169  recorded_force.close();
170  }
171  else
172  cout << "Unable to open file." << endl;
173 }
174 
175 
176 void recordForce_filtered(const geometry_msgs::Vector3Stamped& msg)
177 {
178  string path = dir_path + "recorded_force_filtered" + ".csv";
179 
180  ofstream recorded_force_filtered(path.c_str(), ios::app);
181 
182  if (recorded_force_filtered.is_open())
183  {
184  recorded_force_filtered << msg.header.stamp.sec << "," << msg.vector.x << "," << msg.vector.y << "," << msg.vector.z << "\n";
185  recorded_force_filtered.close();
186  }
187  else
188  cout << "Unable to open file." << endl;
189 }
190 
191 
192 void recordState(const sensor_msgs::JointState& msg)
193 {
194  string path_t = dir_path + "recorded_joints_torque" + ".csv";
195  string path_p = dir_path + "recorded_joints_position" + ".csv";
196  string path_v = dir_path + "recorded_joints_velocity" + ".csv";
197 
198  ofstream recorded_joints_torque(path_t.c_str(), ios::app);
199  ofstream recorded_joints_position(path_p.c_str(), ios::app);
200  ofstream recorded_joints_velocity(path_v.c_str(), ios::app);
201 
202  if (recorded_joints_torque.is_open())
203  {
204  recorded_joints_torque << msg.header.stamp.sec << "," << msg.effort[0] << "," << msg.effort[1] << "," << msg.effort[2] << "," << msg.effort[3] << "," << msg.effort[4] << "," << msg.effort[5] << "," << msg.effort[7] << "," << msg.effort[8] << "," << msg.effort[9] << "," << msg.effort[10] << "," << msg.effort[11] << "," << msg.effort[12] << "\n";
205  recorded_joints_torque.close();
206  }
207  else
208  cout << "Unable to open file." << endl;
209 
210 
211  if (recorded_joints_position.is_open())
212  {
213  recorded_joints_position << msg.header.stamp.sec << "," << msg.position[0] << "," << msg.position[1] << "," << msg.position[2] << "," << msg.position[3] << "," << msg.position[4] << "," << msg.position[5] << "," << msg.position[7] << "," << msg.position[8] << "," << msg.position[9] << "," << msg.position[10] << "," << msg.position[11] << "," << msg.position[12] << "\n";
214  recorded_joints_position.close();
215  }
216  else
217  cout << "Unable to open file." << endl;
218 
219 
220  if (recorded_joints_velocity.is_open())
221  {
222  recorded_joints_velocity << msg.header.stamp.sec << "," << msg.velocity[0] << "," << msg.velocity[1] << "," << msg.velocity[2] << "," << msg.velocity[3] << "," << msg.velocity[4] << "," << msg.velocity[5] << "," << msg.velocity[7] << "," << msg.velocity[8] << "," << msg.velocity[9] << "," << msg.velocity[10] << "," << msg.velocity[11] << "," << msg.velocity[12] << "\n";
223  recorded_joints_velocity.close();
224  }
225  else
226  cout << "Unable to open file." << endl;
227 
228 }
229 
230 
231 void recordBOS(const geometry_msgs::PolygonStamped& msg)
232 {
233  string path = dir_path + "recorded_bos" + ".csv";
234 
235  ofstream recorded_bos(path.c_str(), ios::app);
236 
237  if (recorded_bos.is_open())
238  {
239  recorded_bos << msg.header.stamp.sec << ",";
240 
241  for (uint i=0; i<msg.polygon.points.size()-1; i++)
242  {
243  recorded_bos << msg.polygon.points[i].x << "," << msg.polygon.points[i].y << ",";
244  }
245 
246  recorded_bos << msg.polygon.points[msg.polygon.points.size()-1].x << "," << msg.polygon.points[msg.polygon.points.size()-1].y << "\n";
247 
248  recorded_bos.close();
249  }
250  else
251  cout << "Unable to open file." << endl;
252 }
253 
254 
255 void recordIMU(const vrep_common::ImuData& msg)
256 {
257  string path = dir_path + "recorded_imu_data" + ".csv";
258 
259  ofstream recorded_imu_data(path.c_str(), ios::app);
260 
261  if (recorded_imu_data.is_open())
262  {
263  recorded_imu_data << msg.unitData[0].header.stamp.sec << ",";
264 
265  for (uint i=0; i<msg.unitData.size()-1; i++)
266  {
267  recorded_imu_data << msg.unitData[i].angular_velocity.x << "," << msg.unitData[i].angular_velocity.y << "," << msg.unitData[i].angular_velocity.z << "," << msg.unitData[i].linear_acceleration.x << "," << msg.unitData[i].linear_acceleration.y << "," << msg.unitData[i].linear_acceleration.z << ",";
268  }
269 
270  recorded_imu_data << msg.unitData[msg.unitData.size()-1].angular_velocity.x << "," << msg.unitData[msg.unitData.size()-1].angular_velocity.y << "," << msg.unitData[msg.unitData.size()-1].angular_velocity.z << "," << msg.unitData[msg.unitData.size()-1].linear_acceleration.x << "," << msg.unitData[msg.unitData.size()-1].linear_acceleration.y << "," << msg.unitData[msg.unitData.size()-1].linear_acceleration.z << "\n";
271 
272  recorded_imu_data.close();
273  }
274  else
275  cout << "Unable to open file." << endl;
276 }
277 
278 
279 void recordPlatform_left(const geometry_msgs::PoseStamped& msg)
280 {
281  string path = dir_path + "recorded_platform_left" + ".csv";
282 
283  ofstream recorded_platform_left(path.c_str(), ios::app);
284 
285  if (recorded_platform_left.is_open())
286  {
287  recorded_platform_left << msg.header.stamp.sec << "," << msg.pose.position.x << "," << msg.pose.position.y << "," << msg.pose.position.z << "," << msg.pose.orientation.x << "," << msg.pose.orientation.y << "," << msg.pose.orientation.z << "," << msg.pose.orientation.w << "\n";
288  recorded_platform_left.close();
289  }
290  else
291  cout << "Unable to open file." << endl;
292 }
293 
294 
295 void recordPlatform_right(const geometry_msgs::PoseStamped& msg)
296 {
297  string path = dir_path + "recorded_platform_right" + ".csv";
298 
299  ofstream recorded_platform_right(path.c_str(), ios::app);
300 
301  if (recorded_platform_right.is_open())
302  {
303  recorded_platform_right << msg.header.stamp.sec << "," << msg.pose.position.x << "," << msg.pose.position.y << "," << msg.pose.position.z << "," << msg.pose.orientation.x << "," << msg.pose.orientation.y << "," << msg.pose.orientation.z << "," << msg.pose.orientation.w << "\n";
304  recorded_platform_right.close();
305  }
306  else
307  cout << "Unable to open file." << endl;
308 }
309 
310 
311 int main(int argc, char **argv)
312 {
313  time_t rawtime;
314  time (&rawtime);
315 
316  struct tm * timeinfo;
317  timeinfo = localtime (&rawtime);
318 
319  char date_time[16];
320 
321  strftime(date_time, sizeof(date_time), "%Y%m%d_%H%M%S", timeinfo);
322 
323  ros::init(argc, argv, "record_data");
324  ros::NodeHandle nh;
325 
326  if (!ros::param::get("plane", plane))
327  ROS_ERROR("Failed to read symbols on parameter server");
328  else if (!ros::param::get("amplitude", amplitude))
329  ROS_ERROR("Failed to read symbols on parameter server");
330  else if (!ros::param::get("frequency", frequency))
331  ROS_ERROR("Failed to read symbols on parameter server");
332  else if (!ros::param::get("user", user))
333  ROS_ERROR("Failed to read symbols on parameter server");
334 
335  string dir_location ("/home/phua3-lar/Experiments/Results_");
336  dir_path = dir_location + date_time + '_' + plane + "_amp" + amplitude + "_freq" + frequency + "_user" + user + '/';
337  mkdir(dir_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
338 
339  ros::Subscriber simulation_state_sub = nh.subscribe("/vrep/info", 1000, simulationState);
340  ros::Subscriber phua_position_sub = nh.subscribe("/phua_position", 1000, recordPHUA);
341  ros::Subscriber joints_state_sub = nh.subscribe("/phua_joints_state", 1000, recordState);
342  ros::Subscriber cop_global_position_sub = nh.subscribe("/cop_global_position", 1000, recordCOP);
343  ros::Subscriber support_base_position_sub = nh.subscribe("/support_base_position", 1000, recordBOS);
344  /* ros::Subscriber cop_global_filtered_sub = nh.subscribe("/cop_global_filtered", 1000, recordCOP_filtered); */
345  ros::Subscriber phua_theoretical_position_sub = nh.subscribe("/command_pelvis_position_stamped", 1000, recordPHUA_theoretical);
346  ros::Subscriber feedback_force_stability_sub = nh.subscribe("/feedback_force_stability", 1000, recordForce_stab);
347  ros::Subscriber feedback_force_instability_sub = nh.subscribe("/feedback_force_instability", 1000, recordForce_instab);
348  ros::Subscriber feedback_force_sub = nh.subscribe("/feedback_force", 1000, recordForce);
349  ros::Subscriber feedback_force_filtered_sub = nh.subscribe("/feedback_force_filtered", 1000, recordForce_filtered);
350  ros::Subscriber reaction_force_sub = nh.subscribe("/reaction_force", 1000, recordReaction);
351  ros::Subscriber imu_network_data_sub = nh.subscribe("/imu_network_data", 1000, recordIMU);
352  ros::Subscriber left_platform_sub = nh.subscribe("/vrep/command_left_platform", 1000, recordPlatform_left);
353  ros::Subscriber right_platform_sub = nh.subscribe("/vrep/command_right_platform", 1000, recordPlatform_right);
354 
355  ros::spin();
356 
357  return 0;
358 }
string amplitude
Definition: record_data.cpp:19
ros::Subscriber simulation_state_sub
void recordBOS(const geometry_msgs::PolygonStamped &msg)
void recordCOP(const geometry_msgs::PointStamped &msg)
Definition: record_data.cpp:46
string plane
Definition: record_data.cpp:19
void recordIMU(const vrep_common::ImuData &msg)
int simulator_state(4)
void simulationState(const vrep_common::VrepInfo &msg)
Definition: record_data.cpp:33
void recordReaction(const geometry_msgs::Vector3Stamped &msg)
void recordForce(const geometry_msgs::Vector3Stamped &msg)
void recordState(const sensor_msgs::JointState &msg)
string dir_path
Definition: record_data.cpp:18
ros::Subscriber feedback_force_filtered_sub
string NumberToString(T Number)
Definition: record_data.cpp:25
void recordPHUA_theoretical(const geometry_msgs::PointStamped &msg)
Definition: record_data.cpp:96
void recordPHUA(const geometry_msgs::PoseStamped &msg)
Definition: record_data.cpp:80
int main(int argc, char **argv)
void recordForce_stab(const geometry_msgs::Vector3Stamped &msg)
void recordPlatform_left(const geometry_msgs::PoseStamped &msg)
void recordForce_instab(const geometry_msgs::Vector3Stamped &msg)
void recordCOP_filtered(const geometry_msgs::PointStamped &msg)
Definition: record_data.cpp:64
double simulationTime(0)
void recordForce_filtered(const geometry_msgs::Vector3Stamped &msg)
string frequency
Definition: record_data.cpp:19
void recordPlatform_right(const geometry_msgs::PoseStamped &msg)
string user
Definition: record_data.cpp:19


humanoid_simulation
Author(s): João Barros
autogenerated on Mon Mar 2 2015 01:31:43