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

Instance Method Details

#anonymous_name(id) ⇒ String

generate anonymous name using input id. (arange from roslib)

Parameters:

  • id (String)

    base id (String)

Returns:

  • (String)

    return generated id



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

Parameters:

  • name (String)

    input name

Returns:

  • (String)

    canonicalized name



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.

Parameters:

  • caller_id (String)

    caller id for replacing ~

  • name (String)

    param name like ‘~param’

Returns:

  • (String)

    expanded name



45
46
47
48
49
50
51
# File 'lib/ros/name.rb', line 45

def expand_local_name(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

Parameters:

  • caller_id (String)

    caller_id

  • ns (String)

    namespace

  • name (String)

    target name

  • remappings (Array)

    name remappings

Returns:

  • (String)

    resolved name



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(expand_local_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