Class: ROS::MasterProxy

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

Overview

ROS Master Proxy

access to ROS Master. But there are not documented API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(caller_id, master_uri, slave_uri) ⇒ MasterProxy

Returns a new instance of MasterProxy.

Parameters:

  • caller_id (String)

    caller_id of this node

  • master_uri (String)

    URI of ROS Master

  • slave_uri (String)

    slave URI of this node



28
29
30
31
32
33
# File 'lib/ros/master_proxy.rb', line 28

def initialize(caller_id, master_uri, slave_uri)
  @caller_id = caller_id
  @master_uri = master_uri
  @slave_uri = slave_uri
  @proxy = XMLRPC::Client.new2(@master_uri).proxy
end

Instance Attribute Details

#caller_idString

caller id of this node

Returns:

  • (String)


254
255
256
# File 'lib/ros/master_proxy.rb', line 254

def caller_id
  @caller_id
end

#master_uriString

Master URI

Returns:

  • (String)


237
238
239
# File 'lib/ros/master_proxy.rb', line 237

def master_uri
  @master_uri
end

#slave_uriString

Slave URI

Returns:

  • (String)


250
251
252
# File 'lib/ros/master_proxy.rb', line 250

def slave_uri
  @slave_uri
end

Instance Method Details

#get_published_topics(subgraph = '') ⇒ Array

get the all published topics

Parameters:

  • subgraph (String) (defaults to: '')

    namespace for check

Returns:

  • (Array)

    topic names.

Raises:



191
192
193
194
195
196
197
198
# File 'lib/ros/master_proxy.rb', line 191

def get_published_topics(subgraph='')
  code, message, topics = @proxy.getPublishedTopics(@caller_id, subgraph)
  if code == 1
    return topics
  elsif
    raise message
  end
end

#get_system_stateArray

get system state

Returns:

  • (Array)

    state



202
203
204
205
206
207
208
209
# File 'lib/ros/master_proxy.rb', line 202

def get_system_state
  code, message, state = @proxy.getSystemState(@caller_id)
  if code == 1
    return state
  else
    raise message
  end
end

#get_uriString

get the master URI

Returns:

  • (String)

    uri

Raises:



214
215
216
217
218
219
220
221
# File 'lib/ros/master_proxy.rb', line 214

def get_uri
  code, message, uri = @proxy.getUri(@caller_id)
  if code == 1
    return uri
  else
    raise message
  end
end

#lookup_node(node_name) ⇒ String?

lookup a node by name.

Parameters:

  • node_name (String)

Returns:

  • (String, nil)

    URI of the node if it is found. nil not found.



178
179
180
181
182
183
184
185
# File 'lib/ros/master_proxy.rb', line 178

def lookup_node(node_name)
  code, message, uri = @proxy.lookupNode(@caller_id, node_name)
  if code == 1
    uri
  else
    nil
  end
end

#lookup_service(service) ⇒ String?

look up a service by name

Parameters:

  • service (String)

    name of service

Returns:

  • (String, nil)

    URI of service if found, nil not found.



226
227
228
229
230
231
232
233
# File 'lib/ros/master_proxy.rb', line 226

def lookup_service(service)
  code, message, uri = @proxy.lookupService(@caller_id, service)
  if code == 1
    uri
  else
    false
  end
end

#register_publisher(topic, topic_type) ⇒ Array

register a publisher

Parameters:

  • topic (String)

    topic name of topic

  • topic_type (String)

    type of topic

Returns:

  • (Array)

    URI of current subscribers

Raises:

  • RuntimeError



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ros/master_proxy.rb', line 114

def register_publisher(topic, topic_type)
  code, message, uris = @proxy.registerPublisher(@caller_id,
                                                 topic,
                                                 topic_type,
                                                 @slave_uri)
  if code == 1
    uris
  else
    raise message
  end
end

#register_service(service, service_api) ⇒ Boolean

register a service

Parameters:

  • service (String)

    name of service

  • service_api (String)

    service api uri

Returns:

  • (Boolean)

    true success

Raises:

  • RuntimeError



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ros/master_proxy.rb', line 40

def register_service(service, service_api)
  code, message, val = @proxy.registerService(@caller_id,
                                              service,
                                              service_api,
                                              @slave_uri)
  if code == 1
    return true
  else
    raise message
  end
end

#register_subscriber(topic, topic_type) ⇒ Array

register a subscriber

Parameters:

  • topic (String)

    topic name

  • topic_type (String)

    topic type

Returns:

  • (Array)

    URI of current publishers

Raises:

  • (RuntimeError)

    if error



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ros/master_proxy.rb', line 76

def register_subscriber(topic, topic_type)
  code, message,val = @proxy.registerSubscriber(@caller_id,
                                                topic,
                                                topic_type,
                                                @slave_uri)
  if code == 1
    val
  elsif code == 0
    puts message
    val
  else
    raise message
  end
end

#subscribe_param(key) ⇒ Boolean

this method is not described in the wiki. subscribe to the parameter key.

Parameters:

  • key (String)

    name of parameter

Returns:

  • (Boolean)

    true

Raises:

  • (RuntimeError)

    if fail



151
152
153
154
155
156
157
158
# File 'lib/ros/master_proxy.rb', line 151

def subscribe_param(key)
  code, message, uri = @proxy.subscribeParam(@caller_id, @slave_uri, key)
  if code == 1
    return true
  else
    raise message
  end
end

#unregister_publisher(topic) ⇒ Boolean

unregister a publisher

Parameters:

  • topic (String)

    name of topic

Returns:

  • (Boolean)

    true

Raises:

  • RuntimeError



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ros/master_proxy.rb', line 130

def unregister_publisher(topic)
  code, message, val = @proxy.unregisterPublisher(@caller_id,
                                                  topic,
                                                  @slave_uri)
  if code == 1
    return val
  elsif code == 0
    puts message
    return true
  else
    raise message
  end
  return false
end

#unregister_service(service, service_api) ⇒ Boolean

unregister a service

Parameters:

  • service (String)

    name of service

  • service_api (String)

    service api uri

Returns:

  • (Boolean)

    true success

Raises:

  • RuntimeError



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ros/master_proxy.rb', line 57

def unregister_service(service, service_api)
  code, message, val = @proxy.unregisterService(@caller_id,
                                                service,
                                                service_api)
  if code == 1
    return true
  elsif code == 0
    puts message
    return true
  else
    raise message
  end
end

#unregister_subscriber(topic) ⇒ Boolean

unregister a subscriber

Parameters:

  • topic (String)

    name of topic to unregister

Returns:

  • (Boolean)

    true

Raises:

  • RuntimeError



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ros/master_proxy.rb', line 95

def unregister_subscriber(topic)
  code, message,val = @proxy.unregisterSubscriber(@caller_id,
                                                  topic,
                                                  @slave_uri)
  if code == 1
    return true
  elsif code == 0
    puts message
    return true
  else
    raise message
  end
end

#unsubscribe_param(key) ⇒ Boolean

unsubscribe to the parameter key. this method is not described in the wiki.

Parameters:

  • key (String)

    name of parameter key

Returns:

  • (Boolean)

    true

Raises:

  • (RuntimeError)

    if failt



166
167
168
169
170
171
172
173
# File 'lib/ros/master_proxy.rb', line 166

def unsubscribe_param(key)
  code, message, uri = @proxy.unsubscribeParam(@caller_id, @slave_uri, key)
  if code == 1
    return true
  else
    raise message
  end
end