forked from robotology/yarp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyarp_with_ros_parameters.dox
60 lines (48 loc) · 1.52 KB
/
yarp_with_ros_parameters.dox
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (C) 2011 and 2016 Istituto Italiano di Tecnologia, iCub Facility.
* CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
*
*/
/**
* @page yarp_with_ros_parameters Talking to the ROS parameter server
YARP has no special support for the ROS parameter server, but can
communicate with it via its [network API](http://wiki.ros.org/ROS/Parameter%20Server%20API). Here is a command-line example:
\verbatim
yarp rpc /ros
>>setParam /demo foo 15
Response: 1 "parameter /foo set" 0
>>getParam /demo foo
Target disappeared, reconnecting...
Response: 1 "Parameter [/foo]" 15
\endverbatim
From code, you could use a Bottle:
\code
Network yarp;
Contact ros = Network::queryName("/ros");
printf("ROS available as %s\n", ros.toURI().c_str());
// set a parameter called "foo" to 15
Bottle cmd, reply;
cmd.addString("setParam");
cmd.addString("/demo");
cmd.addString("foo");
cmd.addInt(15);
Network::write(ros,cmd,reply);
printf("reply to setParam is: %s\n", reply.toString().c_str());
// read "foo" back
cmd.clear();
cmd.addString("getParam");
cmd.addString("/demo");
cmd.addString("foo");
Network::write(ros,cmd,reply);
printf("reply to getParam is: %s\n", reply.toString().c_str());
printf("Stored value is hopefully %d\n", reply.get(2).asInt());
return 0;
\endcode
This should give:
\verbatim
ROS available as xmlrpc://127.0.0.1:11311
reply to setParam is: 1 "parameter /foo set" 0
reply to getParam is: 1 "Parameter [/foo]" 15
Stored value is hopefully 15
\endverbatim
*/