class Orocos::ROS::NodeGraph
A representation of the overall ROS node graph. This is used as it is a lot cheaper to query the ROS master directly using getSystemState than calling getPublishers / getSubscribers on each individual slaves
Attributes
Hash<String,Array(Set<String>,Set<String>)> mapping from a node name to the set of input topics and output topics. The set of known node names is nodes.keys
Set<Array(String,String)> The set of known topics, as pairs of
- topic_names, topic_msg_name
Public Class Methods
# File lib/orocos/ros/name_service.rb, line 7 def self.from_system_state(state, topics) graph = new graph.initialize_from_system_state(state, topics) graph end
# File lib/orocos/ros/name_service.rb, line 21 def initialize @topic_types = Hash.new @node_graph = Hash.new end
Public Instance Methods
Returns true if the given name is a known name for a node
# File lib/orocos/ros/name_service.rb, line 88 def has_node?(name) node_graph.has_key?(name) end
Returns true if the given name is a known name for a topic
# File lib/orocos/ros/name_service.rb, line 78 def has_topic?(name) topic_types.has_key?(name) end
# File lib/orocos/ros/name_service.rb, line 26 def initialize_from_system_state(state, topics) @topic_types = Hash[*topics.flatten] state[0].each do |topic_name, publishers| publishers.each do |node_name| node_graph[node_name] ||= [Set.new, Set.new] node_graph[node_name][1] << topic_name end end state[1].each do |topic_name, subscribers| subscribers.each do |node_name| node_graph[node_name] ||= [Set.new, Set.new] node_graph[node_name][0] << topic_name end end state[2].each do |service_name, providers| providers.each do |node_name| node_graph[node_name] ||= [Set.new, Set.new] end end end
Returns the set of topic names that are subscribed by the given node
# File lib/orocos/ros/name_service.rb, line 58 def input_topics_for(node_name) if !node_graph[node_name] raise ArgumentError, "#{node_name} is not a known node" end node_graph[node_name][0] || Set.new end
Returns the set of known node names
# File lib/orocos/ros/name_service.rb, line 83 def nodes node_graph.keys end
Returns the set of topic names that are published by the given node
# File lib/orocos/ros/name_service.rb, line 49 def output_topics_for(node_name) if !node_graph[node_name] raise ArgumentError, "#{node_name} is not a known node" end node_graph[node_name][1] || Set.new end
Returns the message type name for this topic
@return nil if the topic name is not known to us
# File lib/orocos/ros/name_service.rb, line 73 def topic_message_type(topic_name) topic_types[topic_name] end
Returns the set of known topic names
# File lib/orocos/ros/name_service.rb, line 66 def topics topic_types.keys end