Go to the documentation of this file.00001 import json
00002 import rospy
00003 import std_msgs.msg
00004
00005 from firos.srv import FIROS_Info
00006 from firos.msg import Robot_Event, CB_Event
00007 from include.constants import DEFAULT_QUEUE_SIZE
00008 from include.ros.topicHandler import robotDisconnection, loadMsgHandlers
00009 from include.rcm.rcmutils import getRobotConfig
00010
00011 rcm_listener = None
00012 firos_connect_listener = None
00013 firos_disconnect_listener = None
00014 robot_topics_service = rospy.ServiceProxy('/firos_info', FIROS_Info)
00015 cb_publisher = rospy.Publisher("/firos/cb_event", CB_Event, queue_size=DEFAULT_QUEUE_SIZE)
00016
00017
00018 def getRobotTopics(robot_name):
00019 robot_json = robot_topics_service(robot_name)
00020 parsed = json.loads(robot_json.json_format)
00021 robot_data = getRobotConfig(robot_name, parsed[robot_name]["topics"])
00022 return robot_data
00023
00024
00025 def onRcmEvent(data, args=None):
00026
00027
00028
00029
00030 msg = CB_Event()
00031 msg.entity_name = data.instance_name
00032
00033
00034 if data.instance_status == 0:
00035 robot_data = std_msgs.msg.String()
00036 robot_data.data = data.instance_name
00037 robotDisconnection(robot_data)
00038 msg.entity_status = 0
00039 cb_publisher.publish(msg)
00040
00041
00042 elif data.instance_status == 1:
00043 robot_data = getRobotTopics(data.instance_name)
00044 loadMsgHandlers(robot_data)
00045 msg.entity_status = 1
00046 cb_publisher.publish(msg)
00047
00048
00049 def onDisconnect(data):
00050 sendConnection(data.data, 0)
00051
00052
00053 def onConnect(data):
00054 sendConnection(data.data, 1)
00055
00056
00057 def sendConnection(robot_name, status):
00058 msg = CB_Event()
00059 msg.entity_name = robot_name
00060 msg.entity_status = status
00061 cb_publisher.publish(msg)
00062
00063
00064 def setListeners():
00065 global rcm_listener
00066 global firos_disconnect_listener
00067 global firos_connect_listener
00068 rcm_listener = rospy.Subscriber("/rcm/robot_event", Robot_Event, onRcmEvent, {})
00069 firos_disconnect_listener = rospy.Subscriber("firos/disconnect", std_msgs.msg.String, onDisconnect)
00070 firos_connect_listener = rospy.Subscriber("firos/connect", std_msgs.msg.String, onConnect)
00071
00072
00073 def removeListeners():
00074 global rcm_listener
00075 global firos_disconnect_listener
00076 global firos_connect_listener
00077 global cb_publisher
00078 rcm_listener.unregister()
00079 firos_disconnect_listener.unregister()
00080 firos_connect_listener.unregister()
00081 cb_publisher.unregister()