Size: 5902
Comment:
|
Size: 5597
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 123: | Line 123: |
==== rosparam set ==== | ==== rosparam set and rosparam set ==== |
Line 127: | Line 127: |
rosparam get [param_name] | |
Line 142: | Line 143: |
One more thing you need to know: the Parameter Server is a dictionary of dictionaries. This may be hard to understand, so here's an example of setting three parameters at once: | Now let's look at the values of other parameters on the param server. Let's get the value of the green background channel: |
Line 144: | Line 145: |
$ rosparam set gains '{p: 1, i: 2, d: three}' }}} After the values are set on the parameter server, the values can be retrieved using `rosparam get`: {{{ $ rosparam get gains/d |
$ rosparam get background_g |
Line 151: | Line 148: |
three | 144 |
Line 153: | Line 150: |
The slash `/` lets us access values within `gains` as individual keys. Here's a longer example you can try that shows you some more of the power of [[rosparam]] and the Parameter namespaces. |
We can also use `rosparam get /` to show us the contents of the entire Parameter Server. |
Line 158: | Line 152: |
$ rosparam set hello true $ rosparam set gains '{p: 1.0, i: 2, d: 3.0}' $ rosparam set gains/d three |
|
Line 163: | Line 154: |
Will return something similar to: | |
Line 165: | Line 155: |
gains: {d: three, i: 2, p: 1.0} hello: true |
background_b: 255 background_g: 144 background_r: 255 |
Line 168: | Line 159: |
uris: {'aqy:34566': 'http://aqy:34566/'} run_id: 821e2270-9674-11de-8875-001b21201aa8 |
uris: {'aqy:51932': 'http://aqy:51932/'} run_id: e07ea71e-98df-11de-8875-001b21201aa8 |
Line 172: | Line 163: |
The `rosparam get /` showed us the contents of the entire Parameter Server. You may wish to store this in a file so that you can reload it at another time. This is easy using `rosparam`: | You may wish to store this in a file so that you can reload it at another time. This is easy using `rosparam`: ==== rosparam dump and rosparam load ==== Usage: {{{ rosparam dump [file_name] rosparam load [file_name] [namespace] }}} |
Line 174: | Line 171: |
Here we write all the parameters to the file params.yaml | |
Line 179: | Line 177: |
Line 182: | Line 179: |
$ rosparam get copy/gains | $ rosparam get copy/background_b |
Line 185: | Line 182: |
{d: 3.0, i: 2.0, p: 1.0} | 255 |
Note:This tutorial assumes that you have completed the previous tutorial, understanding ROS topics. |
Understanding ROS Services and Parameters
Description: This tutorial introduces ROS services, and parameters as well as using the rosservice and rosparam commandline tools.
Tutorial Level: BEGINNER
Next Tutorial: Writing a simple publisher and subscriber (python) (c++)
Assuming your turtlesim node is still running from the last tutorial, let's look at what services the turtlesim provides:
Using rosservice
rosservice can easily attach to ROS's client/service framework with services. rosservice has many commands that can be used on topics, as shown below:
Usage:
rosservice list print information about active topics rosservice call call the service with the provided args rosservice type print service type rosservice uri print service ROSRPC uri
rosservice list
$ rosservice list
The list command shows us that the turtlesim node provides five services, reset, clear, set_pen, turtlesim/get_loggers, and turtlesim/set_logger_level:
/turtlesim/get_loggers /turtlesim/set_logger_level /reset /rosout/get_loggers /set_pen /clear /rosout/set_logger_level
Let's look more closely at the reset service using rosservice type:
rosservice type
Usage:
rosservice type [service]
Let's find out what type the clear service is:
$ rosservice type reset
std_srvs/Empty
This service is empty, this means when the service call is made it takes no arguments. Let's call this service using rosservice call:
rosservice call
Usage:
rosservice call [service] [args]
Here we'll call with no arguments because the service is of type empty:
rosservice call reset
This does what we expect, it resets the turtlesim node to it's starting state.
Let's look at the case where the service has arguments, let's look at the srv for set_pen
$ rosservice type set_pen| rossrv show
uint8 r uint8 g uint8 b uint8 width uint8 off ---
This service let's us change the line drawn behind our turtle as it moves, let's change the line color and make our turtle move:
$ rosservice call set_pen 0 255 0 5 0 $ rostopic pub command_velocity turtlesim/Velocity -r 1 -- 90.0 -1.8
Now our turtle should look like this:
Using rosparam
rosparam allows you to store and manipulate data on the ROS Parameter Server. The Parameter Server can store integers, floats, boolean, dictionaries, and lists. rosparam uses the YAML markup language for syntax. In simple cases, YAML looks very natural: 1 is an integer, 1.0 is a float, one is a string, true is a boolean, [1, 2, 3] is a list of integers, and {a: b, c: d} is a dictionary. rosparam has many commands that can be used on topics, as shown below:
Usage:
rosparam set set parameter rosparam get get parameter rosparam load load parameters from file rosparam dump dump parameters to file rosparam delete delete parameter rosparam list list parameter names
Let's look at what parameters are currently on the param server:
rosparam list
$ rosparam list
Here we can see that the turtlesim node has three parameters on the param server for background color:
/background_b /background_g /background_r /roslaunch/uris/aqy:51932 /run_id
Let's change one of the parameter values using rosparam set:
rosparam set and rosparam set
Usage:
rosparam set [param_name] rosparam get [param_name]
Here will change the red channel of the background color:
$ rosparam set background_r 255
This changes the parameter value, now we have to call the clear service for the parameter change to take effect:
$ rosservice call clear
Now our turtlesim look like this:
Now let's look at the values of other parameters on the param server. Let's get the value of the green background channel:
$ rosparam get background_g
144
We can also use rosparam get / to show us the contents of the entire Parameter Server.
$ rosparam get /
background_b: 255 background_g: 144 background_r: 255 roslaunch: uris: {'aqy:51932': 'http://aqy:51932/'} run_id: e07ea71e-98df-11de-8875-001b21201aa8
You may wish to store this in a file so that you can reload it at another time. This is easy using rosparam:
rosparam dump and rosparam load
Usage:
rosparam dump [file_name] rosparam load [file_name] [namespace]
Here we write all the parameters to the file params.yaml
$ rosparam dump params.yaml
You can even load these yaml files into new namespaces, e.g. copy:
$ rosparam load params.yaml copy $ rosparam get copy/background_b
255
Now that you understand how ROS topics, services, and params work, let's look at how to write a simple publisher and subscriber (python) (c++).