Module: ROS::Name
- Included in:
- GraphManager, Master, Node
- Defined in:
- lib/ros/name.rb
Overview
this module provides naming functions.
Constant Summary collapse
- SEP =
name sparation char (‘/’)
'/'
Instance Method Summary collapse
-
#anonymous_name(id) ⇒ String
generate anonymous name using input id.
-
#canonicalize_name(name) ⇒ String
start with ‘/’ and use single ‘/’ for names.
-
#expand_local_name(caller_id, name) ⇒ String
expand ~local_param like names.
-
#resolve_name_with_call_id(caller_id, ns, name, remappings) ⇒ String
expand local, canonicalize, remappings.
Instance Method Details
#anonymous_name(id) ⇒ String
generate anonymous name using input id. (arange from roslib)
58 59 60 61 62 63 |
# File 'lib/ros/name.rb', line 58 def anonymous_name(id) name = "#{id}_#{Socket.gethostname}_#{Process.pid}_#{rand(1000000)}" name = name.gsub('.', '_') name = name.gsub('-', '_') name.gsub(':', '_') end |
#canonicalize_name(name) ⇒ String
start with ‘/’ and use single ‘/’ for names
29 30 31 32 33 34 35 36 37 |
# File 'lib/ros/name.rb', line 29 def canonicalize_name(name) if name == nil or name == SEP return name elsif name[0] == SEP[0] return name.split(/\/+/).join(SEP) else return SEP + name.split(/\/+/).join(SEP) end end |
#expand_local_name(caller_id, name) ⇒ String
expand ~local_param like names.
45 46 47 48 49 50 51 |
# File 'lib/ros/name.rb', line 45 def (caller_id, name) if name[0] == '~'[0] caller_id + SEP + name[1..-1] else name end end |
#resolve_name_with_call_id(caller_id, ns, name, remappings) ⇒ String
expand local, canonicalize, remappings
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ros/name.rb', line 73 def resolve_name_with_call_id(caller_id, ns, name, remappings) name = canonicalize_name((caller_id, name)) if remappings remappings.each_pair do |key, value| if name == canonicalize_name(key) name = value end end end if ns name = ns + SEP + name end return canonicalize_name(name) end |