Class: Orocos::ROS::NodeGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/ros/name_service.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNodeGraph

Returns a new instance of NodeGraph



21
22
23
24
# File 'lib/orocos/ros/name_service.rb', line 21

def initialize
    @topic_types = Hash.new
    @node_graph = Hash.new
end

Instance Attribute Details

#node_graphObject (readonly)

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



19
20
21
# File 'lib/orocos/ros/name_service.rb', line 19

def node_graph
  @node_graph
end

#topic_typesObject (readonly)

Set<Array(String,String)> The set of known topics, as pairs of

topic_names, topic_msg_name


15
16
17
# File 'lib/orocos/ros/name_service.rb', line 15

def topic_types
  @topic_types
end

Class Method Details

.from_system_state(state, topics) ⇒ Object



7
8
9
10
11
# 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

Instance Method Details

#has_node?(name) ⇒ Boolean

Returns true if the given name is a known name for a node

Returns:

  • (Boolean)


88
89
90
# File 'lib/orocos/ros/name_service.rb', line 88

def has_node?(name)
    node_graph.has_key?(name)
end

#has_topic?(name) ⇒ Boolean

Returns true if the given name is a known name for a topic

Returns:

  • (Boolean)


78
79
80
# File 'lib/orocos/ros/name_service.rb', line 78

def has_topic?(name)
    topic_types.has_key?(name)
end

#initialize_from_system_state(state, topics) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

#input_topics_for(node_name) ⇒ Object

Returns the set of topic names that are subscribed by the given node



58
59
60
61
62
63
# 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

#nodesObject

Returns the set of known node names



83
84
85
# File 'lib/orocos/ros/name_service.rb', line 83

def nodes
    node_graph.keys
end

#output_topics_for(node_name) ⇒ Object

Returns the set of topic names that are published by the given node



49
50
51
52
53
54
# 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

#topic_message_type(topic_name) ⇒ Object

Returns the message type name for this topic

Returns:

  • nil if the topic name is not known to us



73
74
75
# File 'lib/orocos/ros/name_service.rb', line 73

def topic_message_type(topic_name)
    topic_types[topic_name]
end

#topicsObject

Returns the set of known topic names



66
67
68
# File 'lib/orocos/ros/name_service.rb', line 66

def topics
    topic_types.keys
end