Class: ROS::ParameterManager

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

Overview

ROS parameter sever inteface. API document is here ros.org/wiki/ROS/Parameter%20Server%20API

Instance Method Summary collapse

Constructor Details

#initialize(master_uri, caller_id, remappings) ⇒ ParameterManager

Returns a new instance of ParameterManager.

Parameters:

  • master_uri (String)

    URI of ROS Master (parameter server)

  • caller_id (String)

    caller_id of this node

  • remappings (Array)

    remapps to use for local remappings



23
24
25
26
27
28
# File 'lib/ros/parameter_manager.rb', line 23

def initialize(master_uri, caller_id, remappings)
  @caller_id = caller_id
  @master_uri = master_uri
  @remappings = remappings
  @server = XMLRPC::Client.new2(@master_uri)
end

Instance Method Details

#delete_param(key) ⇒ Boolean

delete parameter ‘key’

Parameters:

  • key (String)

    key for remove

Returns:

  • (Boolean)

    return true if success, false if it is not exist



69
70
71
72
73
74
75
76
77
# File 'lib/ros/parameter_manager.rb', line 69

def delete_param(key)
  code, message, value = @server.call("deleteParam", @caller_id, key)
  case code
  when 1
    return true
  else
    return false
  end
end

#get_param(key) ⇒ String

get parameter named ‘key’

Parameters:

  • key (String)

    name of parameter

Returns:

  • (String)

    parameter value



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ros/parameter_manager.rb', line 34

def get_param(key)
  if @remappings[key]
    return @remappings[key]
  end
  code, message, value = @server.call("getParam", @caller_id, key)
  case code
  when 1
    return value
  else
    return nil
  end
end

#get_param_namesArray

get the all keys of parameters

Returns:

  • (Array)

    all keys



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

def get_param_names
  code, message, value = @server.call("getParamNames", @caller_id)
  case code
  when 1
    return value
  when -1
    raise message
  else
    return false
  end
end

#has_param(key) ⇒ String, ...

check if the master has the key

Parameters:

  • key (String)

    key for check

Returns:

  • (String, Integer, Float, Boolean)

    value of key



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ros/parameter_manager.rb', line 99

def has_param(key)
  code, message, value = @server.call("hasParam", @caller_id, key)
  case code
  when 1
    return value
  when -1
    raise message
  else
    return false
  end
end

#search_param(key) ⇒ Array

search the all namespace for key

Parameters:

  • key (String)

    key for search

Returns:

  • (Array)

    values



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ros/parameter_manager.rb', line 83

def search_param(key)
  code, message, value = @server.call("searchParam", @caller_id, key)
  case code
  when 1
    return value
  when -1
    raise message
  else
    return false
  end
end

#set_param(key, value) ⇒ Boolean

set parameter for ‘key’

Parameters:

  • key (String)

    key of parameter

  • value (String, Integer, Float, Boolean)

    value of parameter

Returns:

  • (Boolean)

    true if succeed

Raises:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ros/parameter_manager.rb', line 53

def set_param(key, value)
  code, message, value = @server.call("setParam", @caller_id, key, value)
  case code
  when 1
    return true
  when -1
    raise message
  else
    return false
  end
end