25 from sensor_msgs.msg
import JointState
26 from std_msgs.msg
import Float64MultiArray
27 from geometry_msgs.msg
import TwistStamped
28 from geometry_msgs.msg
import Twist
29 from nav_msgs.msg
import Odometry
30 from cob_control_msgs.msg
import ObstacleDistances
35 DATE_TIME_FMT =
'%d.%m.%Y %H:%M:%S.%f' 40 __metaclass__ = abc.ABCMeta
42 def __init__(self, file_path, topic_name, data_class):
56 csvfile, delimiter = DEL, quotechar = QUOTE)
61 except IOError
as ioe:
62 rospy.logerr(str(ioe))
70 csvfile, delimiter = DEL, quotechar = QUOTE)
74 self.__class__.__name__ +
': Successfully wrote data into file: ' + self.
file_path_)
76 rospy.logerr(self.__class__.__name__ +
77 ': Could not find any data to write into file: ' + self.
file_path_)
82 raise NotImplementedError
88 super(JointStateDataKraken, self).
__init__(
89 file_path,
'joint_states', JointState)
95 self.
start_ = datetime.datetime.now()
97 header.append(
'time stamp')
98 header.append(
'time delta')
99 for name
in data.name:
100 header.append(name +
'_position')
101 for name
in data.name:
102 header.append(name +
'_velocity')
103 self.data_rows_.append(header)
106 now = datetime.datetime.now()
110 data_row.append(now.strftime(DATE_TIME_FMT))
111 data_row.append(
'%.3f' % delta.total_seconds())
112 data_row.extend(list(data.position))
113 data_row.extend(list(data.velocity))
114 self.data_rows_.append(data_row)
120 super(ObstacleDistanceDataKraken, self).
__init__(
121 file_path,
'obstacle_distance', ObstacleDistances)
128 header.append(
'time stamp')
129 header.append(
'time delta')
130 header.append(
'link_of_interest')
131 header.append(
'obstacle')
132 header.append(
'distance')
133 header.append(
'frame_vector_x')
134 header.append(
'frame_vector_y')
135 header.append(
'frame_vector_z')
136 header.append(
'np_frame_vector_x')
137 header.append(
'np_frame_vector_y')
138 header.append(
'np_frame_vector_z')
139 header.append(
'np_obstacle_vector_x')
140 header.append(
'np_obstacle_vector_y')
141 header.append(
'np_obstacle_vector_z')
142 self.data_rows_.append(header)
145 now = datetime.datetime.now()
147 for elem
in data.distances:
148 data_row = [now.strftime(DATE_TIME_FMT),
'%.3f' % delta.total_seconds()]
149 data_row.append(elem.link_of_interest)
150 data_row.append(elem.obstacle_id)
151 data_row.append(elem.distance)
152 data_row.append(elem.frame_vector.x)
153 data_row.append(elem.frame_vector.y)
154 data_row.append(elem.frame_vector.z)
155 data_row.append(elem.nearest_point_frame_vector.x)
156 data_row.append(elem.nearest_point_frame_vector.y)
157 data_row.append(elem.nearest_point_frame_vector.z)
158 data_row.append(elem.nearest_point_obstacle_vector.x)
159 data_row.append(elem.nearest_point_obstacle_vector.y)
160 data_row.append(elem.nearest_point_obstacle_vector.z)
161 self.data_rows_.append(data_row)
166 def __init__(self, file_path, for_base = False, use_twist_stamped = True):
170 super(TwistDataKraken, self).
__init__(
171 file_path,
'/base/twist_controller/command', Twist)
174 super(TwistDataKraken, self).
__init__(
175 file_path,
'twist_controller/command_twist_stamped', TwistStamped)
177 super(TwistDataKraken, self).
__init__(
178 file_path,
'twist_controller/command_twist', Twist)
183 frame_id = data.header.frame_id +
'_' 184 twist_data = data.twist
193 header.append(frame_id +
'time stamp')
194 header.append(frame_id +
'time delta')
195 header.append(frame_id +
'linear_x')
196 header.append(frame_id +
'linear_y')
197 header.append(frame_id +
'linear_z')
198 header.append(frame_id +
'angular_x')
199 header.append(frame_id +
'angular_y')
200 header.append(frame_id +
'angular_z')
201 self.data_rows_.append(header)
205 now = datetime.datetime.now()
207 data_row.append(now.strftime(DATE_TIME_FMT))
208 data_row.append(
'%.3f' % delta.total_seconds())
209 data_row.append(twist_data.linear.x)
210 data_row.append(twist_data.linear.y)
211 data_row.append(twist_data.linear.z)
212 data_row.append(twist_data.angular.x)
213 data_row.append(twist_data.angular.y)
214 data_row.append(twist_data.angular.z)
215 self.data_rows_.append(data_row)
221 super(JointVelocityDataKraken, self).
__init__(
222 file_path,
'joint_group_velocity_controller/command', Float64MultiArray)
229 header.append(
'time stamp')
230 header.append(
'time delta')
231 for idx, jointvel
in enumerate(data.data):
232 header.append(str(idx + 1))
233 self.data_rows_.append(header)
236 now = datetime.datetime.now()
238 data_row.append(now.strftime(DATE_TIME_FMT))
239 data_row.append(
'%.3f' % delta.total_seconds())
241 for jointvel
in data.data:
242 data_row.append(jointvel)
243 self.data_rows_.append(data_row)
248 def __init__(self, file_path, root_frame, chain_tip_link, tracking_frame):
249 super(FrameTrackingDataKraken, self).
__init__(
250 file_path,
None,
None)
263 csvfile, delimiter = DEL, quotechar = QUOTE)
268 except IOError
as ioe:
269 rospy.logerr(str(ioe))
273 self.timed_transform_.shutdown()
274 self.timed_transform_.join(5.0)
275 return super(FrameTrackingDataKraken, self).
writeAllData()
281 header.append(
'time stamp')
282 header.append(
'time delta')
284 header.append(
'x Trans ' + self.
root_frame_ +
' to ' + frame)
285 header.append(
'y Trans ' + self.
root_frame_ +
' to ' + frame)
286 header.append(
'z Trans ' + self.
root_frame_ +
' to ' + frame)
287 header.append(
'x Quat ' + self.
root_frame_ +
' to ' + frame)
288 header.append(
'y Quat ' + self.
root_frame_ +
' to ' + frame)
289 header.append(
'z Quat ' + self.
root_frame_ +
' to ' + frame)
290 header.append(
'w Quat ' + self.
root_frame_ +
' to ' + frame)
291 header.append(
'roll ' + self.
root_frame_ +
' to ' + frame)
292 header.append(
'pitch ' + self.
root_frame_ +
' to ' + frame)
293 header.append(
'yaw ' + self.
root_frame_ +
' to ' + frame)
294 self.data_rows_.append(header)
297 trans_root_tip, quat_root_tip, rpy_root_tip =
None,
None,
None 301 rpy_root_tip = tf.transformations.euler_from_quaternion(quat_root_tip)
302 except Exception
as e:
303 print(
'Exception chain_tip_link_: ' + str(e))
305 trans_root_track, quat_root_track, rpy_root_track =
None,
None,
None 310 rpy_root_track = tf.transformations.euler_from_quaternion(quat_root_track)
312 except Exception
as e:
313 print(
'Exception tracking_frame_: ' + str(e))
316 if rpy_root_tip
is not None and rpy_root_track
is not None:
319 now = datetime.datetime.now()
321 data_row.append(now.strftime(DATE_TIME_FMT))
322 data_row.append(
'%.3f' % delta.total_seconds())
324 data_row.extend(trans_root_tip)
325 data_row.extend(quat_root_tip)
326 data_row.extend(rpy_root_tip)
328 data_row.extend(trans_root_track)
329 data_row.extend(quat_root_track)
330 data_row.extend(rpy_root_track)
332 self.data_rows_.append(data_row)
338 super(OdometryDataKraken, self).
__init__(
339 file_path,
'/base/odometry_controller/odometry', Odometry)
346 header.append(data.header.frame_id +
'_time stamp')
347 header.append(data.header.frame_id +
'_time delta')
348 header.append(data.header.frame_id +
'_pos_x')
349 header.append(data.header.frame_id +
'_pos_y')
350 header.append(data.header.frame_id +
'_pos_z')
351 header.append(data.header.frame_id +
'_quat_x')
352 header.append(data.header.frame_id +
'_quat_y')
353 header.append(data.header.frame_id +
'_quat_z')
354 header.append(data.header.frame_id +
'_quat_w')
355 header.append(data.header.frame_id +
'_roll')
356 header.append(data.header.frame_id +
'_pitch')
357 header.append(data.header.frame_id +
'_yaw')
358 header.append(data.header.frame_id +
'_twist_linear_x')
359 header.append(data.header.frame_id +
'_twist_linear_y')
360 header.append(data.header.frame_id +
'_twist_linear_z')
361 header.append(data.header.frame_id +
'_twist_angular_x')
362 header.append(data.header.frame_id +
'_twist_angular_y')
363 header.append(data.header.frame_id +
'_twist_angular_z')
364 self.data_rows_.append(header)
368 now = datetime.datetime.now()
370 data_row.append(now.strftime(DATE_TIME_FMT))
371 data_row.append(
'%.3f' % delta.total_seconds())
373 rpy = tf.transformations.euler_from_quaternion((data.pose.pose.orientation.x, data.pose.pose.orientation.y, data.pose.pose.orientation.z, data.pose.pose.orientation.w,))
374 data_row.append(data.pose.pose.position.x)
375 data_row.append(data.pose.pose.position.y)
376 data_row.append(data.pose.pose.position.z)
377 data_row.append(data.pose.pose.orientation.x)
378 data_row.append(data.pose.pose.orientation.y)
379 data_row.append(data.pose.pose.orientation.z)
380 data_row.append(data.pose.pose.orientation.w)
381 data_row.append(rpy[0])
382 data_row.append(rpy[1])
383 data_row.append(rpy[2])
384 data_row.append(data.twist.twist.linear.x)
385 data_row.append(data.twist.twist.linear.y)
386 data_row.append(data.twist.twist.linear.z)
387 data_row.append(data.twist.twist.angular.x)
388 data_row.append(data.twist.twist.angular.y)
389 data_row.append(data.twist.twist.angular.z)
390 self.data_rows_.append(data_row)
def __init__(self, file_path, root_frame, chain_tip_link, tracking_frame)
def __init__(self, file_path, topic_name, data_class)
def __init__(self, file_path)
def __init__(self, file_path)
def __init__(self, file_path, for_base=False, use_twist_stamped=True)
def __init__(self, file_path)
def __init__(self, file_path)