Package concert_orchestra :: Module implementation
[frames] | no frames]

Source Code for Module concert_orchestra.implementation

  1  #!/usr/bin/env python 
  2  # 
  3  # License: BSD 
  4  #   https://raw.github.com/robotics-in-concert/rocon_concert/hydro-devel/concert_orchestra/LICENSE 
  5  # 
  6  ############################################################################## 
  7  # Imports 
  8  ############################################################################## 
  9   
 10  import rospy 
 11  import re 
 12  import concert_msgs.msg as concert_msgs 
 13  import pydot 
 14   
 15  # local imports 
 16  from node import Node 
 17   
 18  ############################################################################## 
 19  # Classes 
 20  ############################################################################## 
 21   
 22   
23 -class Implementation:
24 ''' 25 If a solution implementation is being loaded, this stores the data. 26 '''
27 - def __init__(self):
28 # This will need some modification if we go to multiple solutions on file. 29 self._name = rospy.get_param("~name", "Implementation 42") 30 self.nodes = [] 31 for param in rospy.get_param("~nodes", []): 32 self.nodes.append(Node(param)) 33 self._topics = rospy.get_param("~topics", []) 34 self._actions = rospy.get_param("~actions", []) 35 self._edges = rospy.get_param("~edges", []) 36 self._dot_graph = rospy.get_param("~dot_graph", "") 37 self._implementation_publisher = rospy.Publisher("implementation", concert_msgs.Implementation, latch=True) 38 self.publish() 39 rospy.loginfo("Orchestration : initialised the implementation server.")
40
41 - def publish(self):
42 self._implementation_publisher.publish(self.to_msg())
43
44 - def to_msg(self):
45 ''' 46 Might be easier just serving up the whole implementation file and saving that 47 in a string here. 48 ''' 49 implementation = concert_msgs.Implementation() 50 implementation.name = self._name 51 for node in self.nodes: 52 implementation.link_graph.nodes.append(concert_msgs.LinkNode(node.id, node.tuple, node.min, node.max, node.force_name_matching)) 53 for topic in self._topics: 54 implementation.link_graph.topics.append(concert_msgs.LinkConnection(topic['id'], topic['type'])) 55 for action in self._actions: 56 implementation.link_graph.actions.append(concert_msgs.LinkConnection(action['id'], action['type'])) 57 for edge in self._edges: 58 implementation.link_graph.edges.append(concert_msgs.LinkEdge(edge['start'], edge['finish'], edge['remap_from'], edge['remap_to'])) 59 implementation.dot_graph = self._dot_graph 60 return implementation
61
62 - def rebuild(self, node_client_pairs):
63 ''' 64 If the node name and client name don't match, rebuild 65 66 @param node_client_pairs : list of node id-client name pairs 67 ''' 68 for pair in node_client_pairs: 69 node_id = pair[0] 70 client_name = pair[1] 71 if node_id != client_name: 72 for node in self.nodes: 73 if node.id == node_id: 74 node.id = client_name 75 for topic in self._topics: 76 if re.search(node_id, topic['id']): 77 topic['id'] = topic['id'].replace(node_id, client_name) 78 for action in self._actions: 79 if re.search(node_id, action['id']) is not None: 80 action['id'] = action['id'].replace(node_id, client_name) 81 for edge in self._edges: 82 if edge['start'] == node_id: 83 edge['start'] = client_name 84 if edge['finish'] == node_id: 85 edge['finish'] = client_name 86 if re.search(node_id, edge['remap_from']): 87 edge['remap_from'] = edge['remap_from'].replace(node_id, client_name) 88 if re.search(node_id, edge['remap_to']): 89 edge['remap_to'] = edge['remap_to'].replace(node_id, client_name)
90
91 - def to_dot(self):
92 graph = pydot.Dot(graph_type='graph')
93 # for node in self.nodes: 94 # n = pydot.Node(node.id, style="filled", fillcolor="red") 95 # graph.add_node(n) 96 # self.nodes = rospy.get_param("~nodes", []) 97 # self._topics = rospy.get_param("~topics", []) 98 # self._actions = rospy.get_param("~actions", []) 99 # self._edges = rospy.get_param("~edges", []) 100 # self._dot_graph = rospy.get_param("~dot_graph", "") 101 # self._implementation_publisher = rospy.Publisher("implementation", concert_msgs.Implementation, latch=True) 102 # self.publish() 103 104 105 # def rebuild_graveyard(self, node_client_pairs): 106 # ''' 107 # If the node name and client name don't match, rebuild 108 # 109 # @param node_client_pairs : list of node id-client name pairs 110 # ''' 111 # for pair in node_client_pairs: 112 # node_id = pair[0] 113 # client_name = pair[1] 114 # rospy.logwarn("Debug: node id...........%s" % node_id) 115 # rospy.logwarn("Debug: client name...........%s" % client_name) 116 # if node_id != client_name: 117 # for node in self.nodes: 118 # if node.id == node_id: 119 # node.id = client_name 120 # for topic in self._topics: 121 # if re.search(node_id, topic['id']): 122 # topic['id'] = topic['id'].replace(node_id, client_name) 123 # for action in self._actions: 124 # if re.search(node_id, action['id']) is not None: 125 # action['id'] = action['id'].replace(node_id, client_name) 126 # for edge in self._edges: 127 # if edge['start'] == node_id: 128 # edge['start'] = client_name 129 # if edge['finish'] == node_id: 130 # edge['finish'] = client_name 131 # if re.search(node_id, edge['remap_from']): 132 # edge['remap_from'] = edge['remap_from'].replace(node_id, client_name) 133 # if re.search(node_id, edge['remap_to']): 134 # edge['remap_to'] = edge['remap_to'].replace(node_id, client_name) 135