Class: ROS::Node
Overview
main interface of rosruby.
Constant Summary
- @@shutdown_hook =
for node shutdown hook
[]
Constants included from Name
Instance Attribute Summary (collapse)
-
- (String) host
readonly
hostname of this node.
-
- (String) master_uri
readonly
URI of master.
-
- (String) node_name
readonly
name of this node (caller_id).
Instance Method Summary (collapse)
-
- (Publisher) advertise(topic_name, topic_type, options = {})
start publishing the topic.
-
- (ServiceServer) advertise_service(service_name, service_type, &callback)
start service server.
-
- (Boolean) delete_param(key)
delete the parameter for 'key'.
-
- (String, ...) get_param(key, default = nil)
get the param for key.
-
- (Array) get_param_names
get all parameters.
-
- (Array) get_published_topics
get all topics by this node.
-
- (Boolean) has_param(key)
check if the parameter server has the param for 'key'.
-
- (Node) initialize(node_name, options = {})
constructor
initialization of ROS node get env, parse args, and start slave xmlrpc servers.
-
- (Node) logdebug(message)
outputs log message for DEBUG.
-
- (Node) logerror(message)
(also: #logerr)
outputs log message for ERROR.
-
- (Node) logfatal(message)
outputs log message for FATAL.
-
- (Node) loginfo(message)
outputs log message for INFO (INFORMATION).
-
- (Node) logwarn(message)
outputs log message for WARN (WARING).
-
- (Boolean) ok?
Is this node running? Please use for 'while loop' and so on..
-
- (String) resolve_name(name)
resolve the name by this node's remapping rule.
-
- (ServiceClient) service(service_name, service_type)
create service client.
-
- (Boolean) set_param(key, value)
set parameter for 'key'.
-
- (Node) shutdown
unregister to master and shutdown all connections.
-
- (String) slave_uri
get node URI.
-
- (Object) spin
spin forever.
-
- (Object) spin_once
spin once.
-
- (Subscriber) subscribe(topic_name, topic_type, &callback)
start to subscribe a topic.
-
- (ParameterSubscriber) subscribe_parameter(param, &callback)
subscribe to the parameter.
-
- (Boolean) wait_for_service(service_name, timeout_sec = nil)
wait until start the service.
Methods included from Name
#anonymous_name, #canonicalize_name, #expand_local_name, #resolve_name_with_call_id
Constructor Details
- (Node) initialize(node_name, options = {})
initialization of ROS node get env, parse args, and start slave xmlrpc servers.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ros/node.rb', line 64 def initialize(node_name, ={}) @remappings = {} # @host is rewrited by ARGS[ROS_IP] or ARGS[ROS_HOSTNAME] @host = Socket.gethostname get_env if [:anonymous] node_name = anonymous_name(node_name) end @node_name = resolve_name(node_name) @remappings = parse_args(ARGV) if not @master_uri raise 'ROS_MASTER_URI is nos set. please check environment variables' end @manager = GraphManager.new(@node_name, @master_uri, @host) @parameter = ParameterManager.new(@master_uri, @node_name, @remappings) if not @manager.check_master_connection puts "Unable to immediately register with master node [#{@master_uri}]: master may not be running yet. Will keep trying." while not @manager.check_master_connection sleep(1) end end if not [:nologger] @logger = ::ROS::Log.new(self) end # use sim time ROS::Time.initialize_with_sim_or_wall(self) # because xmlrpc server use signal trap, after serve, it have to trap sig trap_signals ObjectSpace.define_finalizer(self, proc {|id| self.shutdown}) end |
Instance Attribute Details
- (String) host (readonly)
hostname of this node.
119 120 121 |
# File 'lib/ros/node.rb', line 119 def host @host end |
- (String) master_uri (readonly)
URI of master
109 110 111 |
# File 'lib/ros/node.rb', line 109 def master_uri @master_uri end |
- (String) node_name (readonly)
name of this node (caller_id).
123 124 125 |
# File 'lib/ros/node.rb', line 123 def node_name @node_name end |
Instance Method Details
- (Publisher) advertise(topic_name, topic_type, options = {})
start publishing the topic.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ros/node.rb', line 195 def advertise(topic_name, topic_type, ={}) if [:no_resolve] name = topic_name else name = resolve_name(topic_name) end publisher = Publisher.new(@node_name, name, topic_type, [:latched], @manager.host) @manager.add_publisher(publisher) trap_signals publisher end |
- (ServiceServer) advertise_service(service_name, service_type, &callback)
start service server.
218 219 220 221 222 223 224 225 226 227 |
# File 'lib/ros/node.rb', line 218 def advertise_service(service_name, service_type, &callback) server = ::ROS::ServiceServer.new(@node_name, resolve_name(service_name), service_type, callback, @manager.host) @manager.add_service_server(server) trap_signals server end |
- (Boolean) delete_param(key)
delete the parameter for 'key'
173 174 175 |
# File 'lib/ros/node.rb', line 173 def delete_param(key) @parameter.delete_param((@node_name, key)) end |
- (String, ...) get_param(key, default = nil)
get the param for key. You can set default value. That is uesed when the key is not set yet.
141 142 143 144 145 146 147 148 149 |
# File 'lib/ros/node.rb', line 141 def get_param(key, default=nil) key = (@node_name, key) param = @parameter.get_param(key) if param param else default end end |
- (Array) get_param_names
get all parameters.
156 157 158 |
# File 'lib/ros/node.rb', line 156 def get_param_names @parameter.get_param_names end |
- (Array) get_published_topics
get all topics by this node.
369 370 371 372 373 |
# File 'lib/ros/node.rb', line 369 def get_published_topics @manager.publishers.map do |pub| pub.topic_name end end |
- (Boolean) has_param(key)
check if the parameter server has the param for 'key'.
164 165 166 |
# File 'lib/ros/node.rb', line 164 def has_param(key) @parameter.has_param((@node_name, key)) end |
- (Node) logdebug(message)
outputs log message for DEBUG
324 325 326 327 328 |
# File 'lib/ros/node.rb', line 324 def logdebug() file, line, function = caller[0].split(':') @logger.log('DEBUG', , file, function, line.to_i) self end |
- (Node) logerror(message) Also known as: logerr
outputs log message for ERROR.
346 347 348 349 350 |
# File 'lib/ros/node.rb', line 346 def logerror() file, line, function = caller[0].split(':') @logger.log('ERROR', , file, function, line.to_i) self end |
- (Node) logfatal(message)
outputs log message for FATAL.
359 360 361 362 363 |
# File 'lib/ros/node.rb', line 359 def logfatal() file, line, function = caller[0].split(':') @logger.log('FATAL', , file, function, line.to_i) self end |
- (Node) loginfo(message)
outputs log message for INFO (INFORMATION).
314 315 316 317 318 |
# File 'lib/ros/node.rb', line 314 def loginfo() file, line, function = caller[0].split(':') @logger.log('INFO', , file, function, line.to_i) self end |
- (Node) logwarn(message)
outputs log message for WARN (WARING).
335 336 337 338 339 |
# File 'lib/ros/node.rb', line 335 def logwarn() file, line, function = caller[0].split(':') @logger.log('WARN', , file, function, line.to_i) self end |
- (Boolean) ok?
Is this node running? Please use for 'while loop' and so on..
103 104 105 |
# File 'lib/ros/node.rb', line 103 def ok? @manager.is_ok? end |
- (String) resolve_name(name)
resolve the name by this node's remapping rule.
130 131 132 |
# File 'lib/ros/node.rb', line 130 def resolve_name(name) resolve_name_with_call_id(@node_name, @ns, name, @remappings) end |
- (ServiceClient) service(service_name, service_type)
create service client.
243 244 245 246 247 248 |
# File 'lib/ros/node.rb', line 243 def service(service_name, service_type) ROS::ServiceClient.new(@master_uri, @node_name, resolve_name(service_name), service_type) end |
- (Boolean) set_param(key, value)
set parameter for 'key'.
182 183 184 |
# File 'lib/ros/node.rb', line 182 def set_param(key, value) @parameter.set_param((@node_name, key), value) end |
- (Node) shutdown
unregister to master and shutdown all connections.
298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/ros/node.rb', line 298 def shutdown if ok? begin @manager.shutdown rescue => p puts 'ignoring errors while shutdown' end end self end |
- (String) slave_uri
get node URI
113 114 115 |
# File 'lib/ros/node.rb', line 113 def slave_uri @manager.get_uri end |
- (Object) spin
spin forever.
288 289 290 291 292 293 |
# File 'lib/ros/node.rb', line 288 def spin while ok? spin_once sleep(0.01) end end |
- (Object) spin_once
spin once. This invoke subscription/service_server callbacks
281 282 283 |
# File 'lib/ros/node.rb', line 281 def spin_once @manager.spin_once end |
- (Subscriber) subscribe(topic_name, topic_type, &callback)
start to subscribe a topic.
256 257 258 259 260 261 262 263 264 |
# File 'lib/ros/node.rb', line 256 def subscribe(topic_name, topic_type, &callback) sub = Subscriber.new(@node_name, resolve_name(topic_name), topic_type, callback) @manager.add_subscriber(sub) trap_signals sub end |
- (ParameterSubscriber) subscribe_parameter(param, &callback)
subscribe to the parameter.
272 273 274 275 276 |
# File 'lib/ros/node.rb', line 272 def subscribe_parameter(param, &callback) sub = ParameterSubscriber.new(param, callback) @manager.add_parameter_subscriber(sub) sub end |
- (Boolean) wait_for_service(service_name, timeout_sec = nil)
wait until start the service.
234 235 236 |
# File 'lib/ros/node.rb', line 234 def wait_for_service(service_name, timeout_sec=nil) @manager.wait_for_service(service_name, timeout_sec) end |