Class: ROS::Node
Overview
main interface of rosruby.
Constant Summary collapse
- @@shutdown_hook =
for node shutdown hook
[]
Constants included from Name
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
hostname of this node.
-
#master_uri ⇒ String
readonly
URI of master.
-
#node_name ⇒ String
readonly
name of this node (caller_id).
Instance Method Summary collapse
-
#advertise(topic_name, topic_type, options = {}) ⇒ Publisher
start publishing the topic.
-
#advertise_service(service_name, service_type, &callback) ⇒ ServiceServer
start service server.
-
#delete_param(key) ⇒ Boolean
delete the parameter for ‘key’.
-
#get_param(key, default = nil) ⇒ String, ...
get the param for key.
-
#get_param_names ⇒ Array
get all parameters.
-
#get_published_topics ⇒ Array
get all topics by this node.
-
#has_param(key) ⇒ Boolean
check if the parameter server has the param for ‘key’.
-
#initialize(node_name, options = {}) ⇒ Node
constructor
initialization of ROS node get env, parse args, and start slave xmlrpc servers.
-
#logdebug(message) ⇒ Node
outputs log message for DEBUG.
-
#logerror(message) ⇒ Node
(also: #logerr)
outputs log message for ERROR.
-
#logfatal(message) ⇒ Node
outputs log message for FATAL.
-
#loginfo(message) ⇒ Node
outputs log message for INFO (INFORMATION).
-
#logwarn(message) ⇒ Node
outputs log message for WARN (WARING).
-
#ok? ⇒ Boolean
Is this node running? Please use for ‘while loop’ and so on..
-
#resolve_name(name) ⇒ String
resolve the name by this node’s remapping rule.
-
#service(service_name, service_type) ⇒ ServiceClient
create service client.
-
#set_param(key, value) ⇒ Boolean
set parameter for ‘key’.
-
#shutdown ⇒ Node
unregister to master and shutdown all connections.
-
#spin ⇒ Object
spin forever.
-
#spin_once ⇒ Object
spin once.
-
#subscribe(topic_name, topic_type, &callback) ⇒ Subscriber
start to subscribe a topic.
-
#subscribe_parameter(param, &callback) ⇒ ParameterSubscriber
subscribe to the parameter.
-
#wait_for_service(service_name, timeout_sec = nil) ⇒ Boolean
wait until start the service.
Methods included from Name
#anonymous_name, #canonicalize_name, #expand_local_name, #resolve_name_with_call_id
Constructor Details
#initialize(node_name, options = {}) ⇒ Node
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 |
# 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 [:nologger] @logger = ::ROS::Log.new(self) end # 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
#host ⇒ String (readonly)
hostname of this node.
102 103 104 |
# File 'lib/ros/node.rb', line 102 def host @host end |
#master_uri ⇒ String (readonly)
URI of master
98 99 100 |
# File 'lib/ros/node.rb', line 98 def master_uri @master_uri end |
#node_name ⇒ String (readonly)
name of this node (caller_id).
106 107 108 |
# File 'lib/ros/node.rb', line 106 def node_name @node_name end |
Instance Method Details
#advertise(topic_name, topic_type, options = {}) ⇒ Publisher
start publishing the topic.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ros/node.rb', line 178 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 |
#advertise_service(service_name, service_type, &callback) ⇒ ServiceServer
start service server.
201 202 203 204 205 206 207 208 209 |
# File 'lib/ros/node.rb', line 201 def advertise_service(service_name, service_type, &callback) server = ::ROS::ServiceServer.new(@node_name, resolve_name(service_name), service_type, callback) @manager.add_service_server(server) trap_signals server end |
#delete_param(key) ⇒ Boolean
delete the parameter for ‘key’
156 157 158 |
# File 'lib/ros/node.rb', line 156 def delete_param(key) @parameter.delete_param((@node_name, key)) end |
#get_param(key, default = nil) ⇒ String, ...
get the param for key. You can set default value. That is uesed when the key is not set yet.
124 125 126 127 128 129 130 131 132 |
# File 'lib/ros/node.rb', line 124 def get_param(key, default=nil) key = (@node_name, key) param = @parameter.get_param(key) if param param else default end end |
#get_param_names ⇒ Array
get all parameters.
139 140 141 |
# File 'lib/ros/node.rb', line 139 def get_param_names @parameter.get_param_names end |
#get_published_topics ⇒ Array
get all topics by this node.
351 352 353 354 355 |
# File 'lib/ros/node.rb', line 351 def get_published_topics @manager.publishers.map do |pub| pub.topic_name end end |
#has_param(key) ⇒ Boolean
check if the parameter server has the param for ‘key’.
147 148 149 |
# File 'lib/ros/node.rb', line 147 def has_param(key) @parameter.has_param((@node_name, key)) end |
#logdebug(message) ⇒ Node
outputs log message for DEBUG
306 307 308 309 310 |
# File 'lib/ros/node.rb', line 306 def logdebug() file, line, function = caller[0].split(':') @logger.log('DEBUG', , file, function, line.to_i) self end |
#logerror(message) ⇒ Node Also known as: logerr
outputs log message for ERROR.
328 329 330 331 332 |
# File 'lib/ros/node.rb', line 328 def logerror() file, line, function = caller[0].split(':') @logger.log('ERROR', , file, function, line.to_i) self end |
#logfatal(message) ⇒ Node
outputs log message for FATAL.
341 342 343 344 345 |
# File 'lib/ros/node.rb', line 341 def logfatal() file, line, function = caller[0].split(':') @logger.log('FATAL', , file, function, line.to_i) self end |
#loginfo(message) ⇒ Node
outputs log message for INFO (INFORMATION).
296 297 298 299 300 |
# File 'lib/ros/node.rb', line 296 def loginfo() file, line, function = caller[0].split(':') @logger.log('INFO', , file, function, line.to_i) self end |
#logwarn(message) ⇒ Node
outputs log message for WARN (WARING).
317 318 319 320 321 |
# File 'lib/ros/node.rb', line 317 def logwarn() file, line, function = caller[0].split(':') @logger.log('WARN', , file, function, line.to_i) self end |
#ok? ⇒ Boolean
Is this node running? Please use for ‘while loop’ and so on..
92 93 94 |
# File 'lib/ros/node.rb', line 92 def ok? @manager.is_ok? end |
#resolve_name(name) ⇒ String
resolve the name by this node’s remapping rule.
113 114 115 |
# File 'lib/ros/node.rb', line 113 def resolve_name(name) resolve_name_with_call_id(@node_name, @ns, name, @remappings) end |
#service(service_name, service_type) ⇒ ServiceClient
create service client.
225 226 227 228 229 230 |
# File 'lib/ros/node.rb', line 225 def service(service_name, service_type) ROS::ServiceClient.new(@master_uri, @node_name, resolve_name(service_name), service_type) end |
#set_param(key, value) ⇒ Boolean
set parameter for ‘key’.
165 166 167 |
# File 'lib/ros/node.rb', line 165 def set_param(key, value) @parameter.set_param((@node_name, key), value) end |
#shutdown ⇒ Node
unregister to master and shutdown all connections.
280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ros/node.rb', line 280 def shutdown if ok? begin @manager.shutdown rescue => p puts 'ignoring errors while shutdown' end end self end |
#spin ⇒ Object
spin forever.
270 271 272 273 274 275 |
# File 'lib/ros/node.rb', line 270 def spin while ok? spin_once sleep(0.01) end end |
#spin_once ⇒ Object
spin once. This invoke subscription/service_server callbacks
263 264 265 |
# File 'lib/ros/node.rb', line 263 def spin_once @manager.spin_once end |
#subscribe(topic_name, topic_type, &callback) ⇒ Subscriber
start to subscribe a topic.
238 239 240 241 242 243 244 245 246 |
# File 'lib/ros/node.rb', line 238 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 |
#subscribe_parameter(param, &callback) ⇒ ParameterSubscriber
subscribe to the parameter.
254 255 256 257 258 |
# File 'lib/ros/node.rb', line 254 def subscribe_parameter(param, &callback) sub = ParameterSubscriber.new(param, callback) @manager.add_parameter_subscriber(sub) sub end |
#wait_for_service(service_name, timeout_sec = nil) ⇒ Boolean
wait until start the service.
216 217 218 |
# File 'lib/ros/node.rb', line 216 def wait_for_service(service_name, timeout_sec=nil) @manager.wait_for_service(service_name, timeout_sec) end |