00001
00002 import roslib
00003 roslib.load_manifest('teo_apps')
00004 import os
00005 import sys
00006 import numpy as np
00007 import rospy
00008 import rosbag
00009 import tf
00010 import pprint
00011 import math
00012 import subprocess, yaml
00013 from sensor_msgs.msg import Imu
00014 from iri_segway_rmp_msgs.msg import SegwayRMP400Status
00015 from geometry_msgs.msg import Quaternion
00016 from tf.transformations import euler_from_quaternion
00017
00018
00019 SB_='\033[1m'
00020 CY_='\033[33m'
00021 CLG_='\033[37m'
00022 _EC='\033[0m'
00023
00024
00025 if len(sys.argv) < 2:
00026 print " "
00027 print "Error: Please use 1 argument to know the bag"
00028 print " "
00029 print " get_covariance.py BAG_FILE PRINT_BAG_INFO_BOOL"
00030 else:
00031 elbag = str(sys.argv[1])
00032
00033
00034 imu_r=[]; imu_p=[]; imu_y=[]; imu_vr=[]; imu_vp=[]; imu_vy=[]
00035 seg0_r=[]; seg0_p=[]; seg0_y=[]; seg0_vr=[]; seg0_vp=[]; seg0_vy=[];
00036 seg1_r=[]; seg1_p=[]; seg1_y=[]; seg1_vr=[]; seg1_vp=[]; seg1_vy=[];
00037
00038
00039 bag = rosbag.Bag(elbag)
00040 info_dict = yaml.load(subprocess.Popen(['rosbag', 'info', '--yaml', elbag], stdout=subprocess.PIPE).communicate()[0])
00041
00042 print ""
00043 print CY_+"-------------------------------------------------------------------------------------------------"+_EC
00044 print SB_+" Sensor Statistics"+_EC
00045 print CY_+"-------------------------------------------------------------------------------------------------"+_EC
00046
00047 if len(sys.argv) > 2 and str(sys.argv[2])=='True':
00048 print "\n"+CLG_
00049 pprint.pprint(info_dict)
00050 print _EC
00051 print "\n"+CY_+"-------------------------------------------------------------------------------------------------"+_EC+"\n"
00052
00053
00054 for topic, msg, t in bag.read_messages(topics=['/teo/segway/status', '/teo/sensors/imu']):
00055 if topic=='/teo/segway/status':
00056 seg0_r.append(msg.rmp200[0].roll_angle)
00057 seg0_p.append(msg.rmp200[0].pitch_angle)
00058 seg0_y.append(msg.rmp200[0].yaw_displacement)
00059 seg0_vr.append(msg.rmp200[0].roll_rate)
00060 seg0_vp.append(msg.rmp200[0].pitch_rate)
00061 seg0_vy.append(msg.rmp200[0].yaw_rate)
00062 seg1_r.append(msg.rmp200[1].roll_angle)
00063 seg1_p.append(msg.rmp200[1].pitch_angle)
00064 seg1_y.append(msg.rmp200[1].yaw_displacement)
00065 seg1_vr.append(msg.rmp200[1].roll_rate)
00066 seg1_vp.append(msg.rmp200[1].pitch_rate)
00067 seg1_vy.append(msg.rmp200[1].yaw_rate)
00068 elif topic =='/teo/sensors/imu':
00069 q = [msg.orientation.x, msg.orientation.y, msg.orientation.z, msg.orientation.w]
00070 roll_imu, pitch_imu, yaw_imu = euler_from_quaternion(q)
00071 if roll_imu <0:
00072 roll_imu = math.pi+roll_imu
00073 else:
00074 roll_imu = -math.pi+roll_imu
00075 imu_r.append(roll_imu)
00076 imu_p.append(pitch_imu)
00077 imu_y.append(yaw_imu)
00078 imu_vr.append(msg.angular_velocity.x)
00079 imu_vp.append(msg.angular_velocity.y)
00080 imu_vy.append(msg.angular_velocity.z)
00081
00082
00083 bag.close()
00084
00085 def print_vector_statistics(name,v):
00086 print " "+name+":\t","%.5f"%np.mean(v, dtype=np.float64) ,"\t",\
00087 "%.5f"%np.std(v, dtype=np.float64) ,"\t",\
00088 "%.5f"%np.std(v, dtype=np.float64)**2,"\t",\
00089 "%.5f"%np.amin(v),"\t",\
00090 "%.5f"%np.amax(v),"\t",\
00091 len(v)
00092
00093
00094 print ""
00095 print "Bag: ",elbag.split('/')[-1]
00096 print ""
00097 print " Mean\t Std dev\t Cov\t min\t max\t samples"
00098 print SB_+"IMU:"
00099 print_vector_statistics("r",imu_r)
00100 print_vector_statistics("p",imu_p)
00101 print_vector_statistics("y",imu_y)
00102 print_vector_statistics("vr",imu_vr)
00103 print_vector_statistics("vp",imu_vp)
00104 print_vector_statistics("vy",imu_vy)
00105 print "Segway (Base 0):"
00106 print_vector_statistics("r",seg0_r)
00107 print_vector_statistics("p",seg0_p)
00108 print_vector_statistics("y",seg0_y)
00109 print_vector_statistics("vr",seg0_vr)
00110 print_vector_statistics("vp",seg0_vp)
00111 print_vector_statistics("vy",seg0_vy)
00112 print "Segway (Base 1):"
00113 print_vector_statistics("r",seg1_r)
00114 print_vector_statistics("p",seg1_p)
00115 print_vector_statistics("y",seg1_y)
00116 print_vector_statistics("vr",seg1_vr)
00117 print_vector_statistics("vp",seg1_vp)
00118 print_vector_statistics("vy",seg1_vy)
00119
00120 print "\n"+_EC+CY_+"-------------------------------------------------------------------------------------------------"+_EC
00121