Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import os
00018 import json
00019 import copy
00020 import traceback
00021
00022 from include.logger import Log
00023 from include.ros.rosConfigurator import RosConfigurator
00024
00025
00026 def getRobots(refresh=False, withJson=True):
00027
00028
00029
00030 try:
00031 robots = copy.deepcopy(RosConfigurator.systemTopics(refresh))
00032 if withJson:
00033 robots_json = getRobotsByJson()
00034 for robot_name in robots_json:
00035 robot_name = str(robot_name)
00036 if robot_name not in robots:
00037 robots[robot_name] = {
00038 "topics": {}
00039 }
00040 for topic_name in robots_json[robot_name]["topics"]:
00041 topic = robots_json[robot_name]["topics"][topic_name]
00042
00043 robots[robot_name]["topics"][str(topic_name)] = {
00044 "msg": str(topic["msg"]) if type(topic["msg"]) is str else topic["msg"],
00045 "type": str(topic["type"])
00046 }
00047 return robots
00048
00049 except Exception as e:
00050 traceback.print_exc()
00051 Log("ERROR", e)
00052 return {}
00053
00054
00055 def getRobotsByJson():
00056
00057 try:
00058 current_path = os.path.dirname(os.path.abspath(__file__))
00059 json_path = current_path.replace("scripts/include", "config/robots.json")
00060 return json.load(open(json_path))
00061 except:
00062 return {}