00001 #!/usr/bin/python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2012 \n 00007 # Cardiff University \n\n 00008 # 00009 ################################################################# 00010 # 00011 # \note 00012 # Project name: Multi-Role Shadow Robotic System for Independent Living 00013 # \note 00014 # ROS stack name: srs 00015 # \note 00016 # ROS package name: srs_decision_making_interface 00017 # 00018 # \author 00019 # Author: Renxi Qiu, email: renxi.qiu@gmail.com 00020 # 00021 # \date Date of creation: Jan 2012 00022 # 00023 # \brief 00024 # Interface for SRS decision making 00025 # 00026 ################################################################# 00027 # 00028 # Redistribution and use in source and binary forms, with or without 00029 # modification, are permitted provided that the following conditions are met: 00030 # 00031 # - Redistributions of source code must retain the above copyright 00032 # notice, this list of conditions and the following disclaimer. \n 00033 # 00034 # - Redistributions in binary form must reproduce the above copyright 00035 # notice, this list of conditions and the following disclaimer in the 00036 # documentation and/or other materials provided with the distribution. \n 00037 # 00038 # This program is free software: you can redistribute it and/or modify 00039 # it under the terms of the GNU Lesser General Public License LGPL as 00040 # published by the Free Software Foundation, either version 3 of the 00041 # License, or (at your option) any later version. 00042 # 00043 # This program is distributed in the hope that it will be useful, 00044 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00045 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00046 # GNU Lesser General Public License LGPL for more details. 00047 # 00048 # You should have received a copy of the GNU Lesser General Public 00049 # License LGPL along with this program. 00050 # If not, see <http://www.gnu.org/licenses/>. 00051 # 00052 ################################################################# 00053 00054 import roslib; roslib.load_manifest('srs_decision_making_interface') 00055 00056 from srs_decision_making_interface.srv import srs_dm_ui_interface 00057 from std_msgs.msg import * 00058 import rospy 00059 import actionlib 00060 00061 def srs_decision_making_ui_interface_client(action, parameter, priority, json_parameters): 00062 00063 rospy.wait_for_service('srs_decision_making_ui_interface') 00064 00065 srs_decision_making_action = rospy.ServiceProxy('srs_decision_making_ui_interface', srs_dm_ui_interface) 00066 00067 resp = srs_decision_making_action(action, parameter, priority, json_parameters) 00068 00069 return resp 00070 00071 if __name__ == '__main__': 00072 try: 00073 # Initializes a rospy node so that the SimpleActionClient can 00074 # publish and subscribe over ROS. 00075 rospy.init_node('dm_client_test') 00076 action = 'get' 00077 parameter = 'Milkbox' 00078 priority = '1' 00079 json_parameters = '{"tasks":[{"time_schedule":1263798000000,"task":"get","deliver_destination":{"predefined_pose":"order"},"object":{"object_type":"Milkbox"}}],"initializer":{"device_type":"ui_loc","device_id":"ui_loc_0001"}}' 00080 00081 print (action, parameter, priority, json_parameters ) 00082 result = srs_decision_making_ui_interface_client(action, parameter, priority, json_parameters) 00083 rospy.loginfo('The task has been passed to DM, the allocated task id is: %s',result) 00084 # print ("Result:" result) 00085 except rospy.ROSInterruptException: 00086 print "program interrupted before completion"