accel_capt.py
Go to the documentation of this file.
00001 #! /usr/bin/python
00002 
00003 import roslib; roslib.load_manifest('kelsey_sandbox')
00004 import rospy
00005 import roslib.message
00006 import rosbag
00007 import sys
00008 import rosservice
00009 from pr2_msgs.msg import AccelerometerState
00010 import scipy.io
00011 
00012 class AccelSaver:
00013     def __init__(self):
00014         self.data = []
00015         self.first = True
00016 
00017     def proc_acc(self, msg):
00018         if len(msg.samples) > 0:
00019             if self.first:
00020                 self.beg_time = msg.header.stamp.to_sec()
00021                 self.first = False
00022             sum_x, sum_y, sum_z = 0, 0, 0
00023             for sample in msg.samples:
00024                 sum_x += sample.x
00025                 sum_y += sample.y
00026                 sum_z += sample.z
00027             self.data.append((msg.header.stamp.to_sec() - self.beg_time, sum_x / len(msg.samples), sum_y / len(msg.samples), sum_z / len(msg.samples)))
00028 def main():
00029     rospy.init_node('accel_save')
00030     asave = AccelSaver()
00031     rospy.Subscriber('/accelerometer/l_gripper_motor', AccelerometerState, asave.proc_acc)
00032     print "Starting:"
00033     rospy.spin()
00034     mat_data = {}
00035     mat_data['accel'] = asave.data
00036     scipy.io.savemat('accel_data.mat', mat_data)
00037 
00038 if __name__ == "__main__":
00039     main()
00040 


kelsey_sandbox
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:52:03