error_icp_mp.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 #  -------------------------------------------
00005 #  node: error_icp_mp.py
00006 #  author: Marti Morta (mmorta@iri.upc.edu)
00007 #  date: 20 Nov 2013
00008 #  -------------------------------------------
00009 #   Calculates icp and mid point statistics
00010 #   Subscribers
00011 #     scan: LaserScan
00012 
00013 import roslib
00014 roslib.load_manifest('iri_segway_rmp400_odom')
00015 import os
00016 import sys
00017 import rospy
00018 import math
00019 import numpy
00020 import time
00021 from copy import deepcopy
00022 from geometry_msgs.msg import Twist,Pose
00023 from sensor_msgs.msg import LaserScan
00024 from iri_laser_icp.srv import GetRelativePose
00025 
00026 
00027 last_scan = LaserScan()
00028 lst_d_icp = []
00029 lst_d_mp  = []
00030 
00031 
00032 def callback_laser(data):
00033   global last_scan,lst_d_icp,lst_d_mp
00034   current_scan = data;
00035   prev_L = Pose()
00036   if last_scan.header.seq > 0:
00037     [icp,mp] = icp_client(last_scan,current_scan,prev_L)
00038     lst_d_icp.append(icp)
00039     lst_d_mp.append(mp)
00040   last_scan = deepcopy(current_scan)
00041 
00042 
00043 def icp_client(ref,sens,d):
00044   rospy.wait_for_service('iri_laser_icp/get_relative_pose',10)
00045   try:
00046       get_rpose = rospy.ServiceProxy('iri_laser_icp/get_relative_pose', GetRelativePose)
00047       rel_pose = get_rpose(ref,sens,d).pose_rel.pose.pose
00048       d_icp = math.sqrt(rel_pose.position.x**2+rel_pose.position.y**2)
00049       d_mp  = ref.ranges[int(len(ref.ranges)/2)] - sens.ranges[int(len(sens.ranges)/2)]
00050       return [d_icp,d_mp]
00051   except rospy.ServiceException, e:
00052       print CR_+"Service call failed: %s"%e+_EC
00053 
00054 
00055 def get_vector_statistics(name,v):
00056   return str("  "+name+": "+str("%.5f"%numpy.mean(v,dtype=numpy.float64))+" "+str("%.5f"%numpy.std(v,dtype=numpy.float64))+" "+\
00057   str("%.5f"%numpy.std(v, dtype=numpy.float64)**2)+" "+str("%.5f"%numpy.amin(v))+" "+str("%.5f"%numpy.amax(v))+" "+str(len(v)))
00058 
00059 def sayonara():
00060   global lst_d_icp,lst_d_mp,nom
00061   f_name    = "icp_mp_stats_"+nom+"_"+str(int(time.time()))+".txt"
00062   output    = open(f_name, 'w')
00063   print_icp = get_vector_statistics("ICP",lst_d_icp)
00064   print_mp  = get_vector_statistics(" MP",lst_d_mp)
00065   output.write("Experiment: "+nom+"\n")
00066   output.write("Date:       "+str(time.asctime(time.localtime(time.time())))+"\n") 
00067   output.write("Results: \n") 
00068   output.write("        Mean   StdDev  Cov     min     max     samples\n")
00069   output.write(print_icp)  
00070   output.write("\n")
00071   output.write(print_mp)  
00072   output.write("\n")
00073   output.write(" -----------------------------------------------------------------------------------------------\n")
00074   output.write("\n")
00075   print ""
00076   print "Experiment: "+nom
00077   print "Date:       "+str(time.asctime(time.localtime(time.time())))
00078   print "Results:"
00079   print "        Mean   StdDev  Cov     min     max     samples"
00080   print  print_icp  
00081   print  print_mp 
00082   print " -----------------------------------------------------------------------------------------------"
00083   print ""
00084   output.close()
00085   print "  Sayonara"
00086 
00087 
00088 if __name__ == '__main__':
00089   rospy.init_node('error_icp_mp')
00090   print " > ICP & MP Error estimator <"
00091   r = rospy.Rate(20)
00092   rospy.Subscriber('/teo/sensors/front_laser', LaserScan, callback_laser)
00093   rospy.on_shutdown(sayonara)
00094   print "  Fetching data Yo"
00095   global nom
00096   nom="test"
00097   if len(sys.argv)>1:
00098     nom=sys.argv[1]
00099   rospy.spin()
00100 
00101 


teo_apps
Author(s): Marti
autogenerated on Fri Dec 6 2013 22:19:45