model_selection_client.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib; roslib.load_manifest('articulation_tutorials')
00004 import rospy
00005 import numpy
00006 
00007 from articulation_msgs.msg import *
00008 from articulation_msgs.srv import *
00009 from geometry_msgs.msg import Pose, Point, Quaternion
00010 from sensor_msgs.msg import ChannelFloat32
00011 
00012 
00013 PRISMATIC = 0
00014 ROTATIONAL = 1
00015 MODELS={PRISMATIC:'prismatic',ROTATIONAL:'rotational'}
00016 
00017 def sample_track(model = PRISMATIC, n = 100, sigma_position = 0.02):
00018         msg = TrackMsg()
00019         msg.header.stamp = rospy.get_rostime()
00020         msg.header.frame_id = "/"
00021         msg.id = model
00022 
00023         for i in range(0,n):
00024                 q = i / float(n)
00025                 if model == PRISMATIC:
00026                         pose = Pose(Point(q, 0, 0), Quaternion(0, 0, 0, 1))
00027                 elif model == ROTATIONAL:
00028                         pose = Pose(Point(numpy.sin(q), numpy.cos(q) - 1.0, 0), Quaternion(0, 0, 0, 1))
00029                 else:
00030                         raise NameError("unknown model, cannot generate trajectory!")
00031                 pose.position.x += numpy.random.rand()*sigma_position
00032                 pose.position.y += numpy.random.rand()*sigma_position
00033                 pose.position.z += numpy.random.rand()*sigma_position
00034                 msg.pose.append( pose )
00035         return msg
00036 
00037 def main():
00038         rospy.init_node('test_fitting')
00039 
00040         model_select = rospy.ServiceProxy('model_select', TrackModelSrv)
00041         model_pub = rospy.Publisher('model', ModelMsg)
00042         print
00043   
00044         while True:
00045                 for model_type,model_name in MODELS.items():
00046                         request = TrackModelSrvRequest()
00047                         print "generating track of type '%s'" % model_name
00048                         request.model.track = sample_track( model_type )
00049                  
00050                         try:            
00051                                 response = model_select(request)
00052                                 print "selected model: '%s' (n = %d, log LH = %f)" % (
00053                                         response.model.name,
00054                                         len(response.model.track.pose),
00055                                         [entry.value for entry in response.model.params if entry.name=='loglikelihood'][0]
00056                                 )
00057                                 model_pub.publish(response.model)
00058                         except rospy.ServiceException: 
00059                                 print "model selection failed"
00060                                 pass
00061                         if rospy.is_shutdown():
00062                                 exit(0)
00063                         print
00064                         rospy.sleep(0.5)
00065 
00066 
00067 
00068 if __name__ == '__main__':
00069   main()
00070 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


articulation_tutorials
Author(s): Juergen Sturm
autogenerated on Wed Dec 26 2012 15:38:56