Go to the documentation of this file.00001
00002
00003 import roslib; roslib.load_manifest('srs_decision_making')
00004 import rospy
00005 import actionlib
00006 import smach
00007 import smach_ros
00008 import simplejson as json
00009
00010
00011 import srs_ui_pro.msg as echo_server_msg
00012
00013 from std_msgs.msg import String
00014
00015 def test_client_srs_ui_pro_echo_server(json_input):
00016 client = actionlib.SimpleActionClient('srs_ui_pro/echo_server', echo_server_msg.dm_serverAction)
00017 client.wait_for_server()
00018
00019 goal = echo_server_msg.dm_serverGoal()
00020 goal.json_input = json_input
00021 print "###type of goal is", type(goal)
00022 print "###goal is", goal
00023 print "###goal.json_input is", goal.json_input
00024
00025
00026
00027 server_feedback = echo_server_msg.dm_serverFeedback()
00028 server_result = echo_server_msg.dm_serverResult()
00029 try:
00030 client.send_goal(goal, result_callback, None, feedback_callback)
00031 except rospy.ServiceException, e:
00032 print "Service did not process request: %s"%str(e)
00033
00034 rospy.spin()
00035
00036
00037 def feedback_callback(server_feedback):
00038 if server_feedback is not None:
00039 rospy.loginfo ("server_feedback.json_feedback is: %s",server_feedback.json_feedback)
00040 else:
00041 print "### no feedback from echo server..."
00042
00043 def result_callback(state, server_result):
00044 if server_result is not None:
00045 rospy.loginfo ("state is: %s",state)
00046 rospy.loginfo ("server_result.json_result is: %s",server_result.json_result)
00047
00048 server_json_result = server_result.json_result
00049 json_decoded = json.loads(server_json_result)
00050 result = json_decoded['result']
00051
00052 if result == "succeeded":
00053 print 'result is completed'
00054 elif result == "failed":
00055 return "result is failed"
00056 else:
00057 return "result is give_up"
00058 else:
00059 print "### no feedback from echo server..."
00060
00061 if __name__ == '__main__':
00062 try:
00063 global current_task_info
00064 rospy.init_node('srs_ui_pro_echo_server_client')
00065
00066 json_input = "{\"exception_id\":33, \"tasks\":[{\"time_schedule\":1263798000000,\"task\":\"move\",\"destination\":{\"pose2d_string\":\"[0 1 3.14]\"}}, {\"time_schedule\":2222222222,\"task\":\"move\",\"destination\":{\"pose2d_string\":\"[0 1 3.14]\"}}], \"additional_information\":\" ****balabla The robot needs the user to assist in completing the task of moving to [0 1 3.14]\"}"
00067
00068 test_client_srs_ui_pro_echo_server(json_input)
00069
00070
00071
00072
00073
00074 except rospy.ROSInterruptException:
00075 print "error before completion"