00001
00002
00003 import roslib; roslib.load_manifest('articulation_structure')
00004 import rospy
00005 import sys
00006 from visualization_msgs.msg import Marker, MarkerArray
00007 from geometry_msgs.msg import Vector3, Point, Pose, PoseArray
00008 from std_msgs.msg import ColorRGBA
00009 from sensor_msgs.msg import ChannelFloat32,CameraInfo,CompressedImage
00010 from articulation_msgs.msg import *
00011 from articulation_msgs.srv import *
00012 from articulation_models.track_utils import *
00013 import logging
00014 import getopt
00015 import colorsys
00016 import numpy
00017 import copy
00018 import rosbag
00019
00020 def main():
00021 rospy.init_node('articulation_eval')
00022
00023 info_pub = rospy.Publisher('/camera/camera_info',CameraInfo)
00024 image_pub = rospy.Publisher('/camera/image_raw/compressed',CompressedImage)
00025 posearray_pub = rospy.Publisher('/camera/pose_array',PoseArray)
00026 model_pub = rospy.Publisher('/model', ModelMsg)
00027 track_pub = rospy.Publisher('/track', TrackMsg)
00028
00029 fit_models = rospy.ServiceProxy('fit_models', ArticulatedObjectSrv)
00030 get_spanning_tree = rospy.ServiceProxy('get_spanning_tree', ArticulatedObjectSrv)
00031 get_fast_graph = rospy.ServiceProxy('get_fast_graph', ArticulatedObjectSrv)
00032 get_graph = rospy.ServiceProxy('get_graph', ArticulatedObjectSrv)
00033 visualize_graph = rospy.ServiceProxy('visualize_graph', ArticulatedObjectSrv)
00034
00035
00036 for (topic,object,t) in rosbag.Bag("eval.bag").read_messages():
00037 print t
00038
00039
00040 for p in object.parts:
00041 print "publishing part %d"%p.id
00042 track_pub.publish(p)
00043
00044
00045
00046 parts = len(object.parts)
00047 request = ArticulatedObjectSrvRequest()
00048 request.object = object
00049
00050
00051 response = fit_models(request)
00052 print '\n'.join(
00053 ['(%s:%d,%d) bic=%f pos_err=%f rot_err=%f \n%s'%(
00054 model.name[0:2],
00055 model.id/parts,
00056 model.id%parts,
00057 get_param(model,'bic'),
00058 get_param(model,'avg_error_position'),
00059 get_param(model,'avg_error_orientation'),
00060 "\n".join([" %s = %f"%(p.name,p.value) for p in model.params if p.name[0:3]=="rot"])
00061 ) for model in response.object.models])
00062
00063 for m in response.object.models:
00064 if m.name=="rotational":
00065 model_pub.publish(m)
00066
00067 request.object = copy.deepcopy(response.object)
00068 response = visualize_graph(request)
00069
00070 sys.exit()
00071
00072 if mode=="fastgraph":
00073 response = get_fast_graph(request)
00074 elif mode=="graph":
00075 response = get_graph(request)
00076 elif mode=="spanningtree":
00077 response = get_spanning_tree(request)
00078
00079 request.object = copy.deepcopy(response.object)
00080 response = visualize_graph(request)
00081
00082 rospy.loginfo('received articulation model: '+(' '.join(
00083 ['(%s:%d,%d)'%(model.name[0:2],model.id/parts,model.id%parts) for model in response.object.models])))
00084
00085 print '\n'.join(
00086 ['(%s:%d,%d) bic=%f pos_err=%f rot_err=%f'%(
00087 model.name[0:2],
00088 model.id/parts,
00089 model.id%parts,
00090 get_param(model,'bic'),
00091 get_param(model,'avg_error_position'),
00092 get_param(model,'avg_error_orientation')
00093 ) for model in response.object.models])
00094 print "dofs=%d, nominal dofs=%d, bic=%f pos_err=%f rot_err=%f"%(
00095 get_param(response.object,'dof'),
00096 get_param(response.object,'dof.nominal'),
00097 get_param(response.object,'bic'),
00098 get_param(response.object,'avg_error_position'),
00099 get_param(response.object,'avg_error_orientation')
00100 )
00101
00102
00103
00104
00105 last_timestamp = timestamps[ downsampled[-1] ]
00106 info_pub.publish( bag[last_timestamp]['/camera/camera_info'] )
00107 image_pub.publish( bag[last_timestamp]['/camera/image_raw/compressed'] )
00108 posearray_pub.publish( bag[last_timestamp]['/camera/pose_array'] )
00109
00110
00111
00112
00113
00114
00115 rospy.sleep(5)
00116
00117 if __name__ == '__main__':
00118 main()
00119