Halo, this is Ppeua. Usually, I mainly update C language, C++, data structure algorithm... Follow me if you are interested! You will not be disappointed.
Introduction to parameter server communication and ros common tool commands
![insert image description here](https://img-blog.csdnimg.cn/3c9de86f742b45f2b76d3817661785bf.jpeg)
0. Parameter server concept
Compared with the previous communication models, the parameter server is the simplest. In the previous models, ROSMASTER acted as a bridge to connect the two together.
In the parameter server: ROSMASTER has become a container for storing messages , allowing users to complete additions, deletions, checks, and modifications .
Its design is only to store simple non-binary data. If high-performance operations are required, other communication methods are recommended.
Parameter types that can be stored in the container :
- 32-bit integers
- booleans
- strings
- doubles
- iso8601 dates
- lists
- base64-encoded binary data
- dictionary
1. The parameter server adds/modifies parameters:
- initialize node
- Use the set_param function to add/modify
set_param is somewhat similar to hash: if there is no such value in the parameter server, it will be increased, and if it is, it will be modified to the latest value
import rospy
rospy.init_node("param")
#设置整形
rospy.set_param("p_int",10)
#设置浮点型
rospy.set_param("p_double",3.14)
#设置bool值
rospy.set_param("p_bool",True)
#设置string
rospy.set_param("p_string","hello python")
#设置List
rospy.set_param("p_list",["hello","haha","xixi"])
#设置字典
rospy.set_param("p_dict",{
"name":"hulu","age":8})
2. The parameter server looks for parameters
Commonly used are the following functions:
- get_param(key,value)
returns the corresponding value when the key exists, and returns the default value if
it
does not exist The role of fast tables in system memoryradius2=rospy.get_param_cached("radius_p",0.5) radius=rospy.get_param("radius_p",0.5)
- get_param_names()
gets all the parameter names in the current parameter list and returnsnames=rospy.get_param_names() for name in names: print(name)
- has_param(key)
determines whether there is a parameter in the parameter list and
returns a Bool valueflag1=rospy.has_param("radius_p") if flag1: print("存在") else : print("不存在")
- search_param(key)
to find if there is this message, if not, return None, if there is, return this keykey=rospy.search_param("radius_p") print(key)
3. The parameter server deletes the parameter:
- delete_param(key)
delete the specified key
It is relatively simple and will not demonstrate the usage, and there will be a practical project involving
4. Common commands
The topic communication and service communication used in the previous configuration will be used.
Use these commands to dynamically view the relationship between nodes and message carriers when the robot is running :
- rosnode : node
- rostopic : topic
- rosservice : service
- rosmsg : msg message
- rossrv : srv message
- rosparam : Operational parameter server
4.1 rosnode
Let's first start the sub and pub nodes of the previously configured custom msg . For specific configurations, please refer to the topic communication case of this article.
rosrun lesson2 demo02_pub.py
rosrun lesson2 demo02_sub.py
Use rosnode directly to view the parameter list
-
rosnode ping tests the connection status to the node
rosnode ping /person_pub
Here /pub_person is the node that sends the message, just a demonstration
-
rosnode list lists active nodes
rosnode list
Use this command to view the currently active nodes
-
rosnode info print node information
ronode info /person_pub ronode info /person_sub
The information of the sending and receiving nodes is printed here, including the following :
- node name
- use topics
- receiver/sender
Reasonable use can make it easier to clarify the relationship between nodes
- rosnode machine lists the nodes on the specified device
- rosnode kill kills a node
Killed the subscription noderosnode kill /sub_person
- rosnode cleanup clears unconnectable nodes.
Sometimes after ctrl+c, some nodes will be unavailable, but they are still in the list. At this time, you can use this command to refresh them
4.2 rostopic
First start the two nodes used above
and directly enter rostopic in the terminal to view all available commands
-
rostopic list shows all topics currently in use
rostopic list
For example, the topic used here is /che
-
rostopic echo acts as the receiver and can print topic information on the screen
rostopic echo topic
For example, here you can verify whether the information of the publisher is correct
-
The two functions of rostopic info/type are the same, displaying the message type of topic communication, where info contains the type type
rostopic info topic
For example, the Person msg message type is used here
-
rostopic find finds topics using a message type
rostopic find lesson2/Person
For example, what is the topic of finding the message type of lesson2/Person here?
-
rostopic pub publishes a message to a topic
rostopic pub topic
For example, publish information to the subscription node here
4.3 rosmsg
rosmsg is a command-line tool used to display information about ROS message types. It is
also the same as above. You can directly enter rosmsg and the available commands will be displayed.
-
rosmsg list lists all message types
-
rosmsg show / info lists the specific types contained in the current message type
rosmsg show msg
-
rosmsg package lists all messages under a package
rosmsg package pack
List all message types in turtlesim
-
rosmsg packages lists the packages that contain a message
rosmsg package pack
List all packages containing the turtlesim/Pose message type
4.4 rosservice
To query related service information,
we first start the previously configured custom srv server and client nodes. For specific configuration, please refer to this article
rosrun lesson3_srv demo01_client.py
rosrun lesson3_srv demo01_server.py
You can also see the parameter list by typing rosservice in the terminal
-
rosservice list lists the list of parameter services
-
rosservice call calls the service
here to call /sum2 tab to complete and pass in two parametersrosservice call /sum2
-
rosservice args to view the specific parameters of the srv message
rosservice args /sum2
The rest of the usage is the same as above
4.5 rossrv
Similar to rosmsg, it also checks the specific type of srv
4.6 rosparam
Let's start the turtle first for verification
rosrun turtlesim turtlesim_node
-
rosparam list lists the parameter list
-
rosparam set sets specific parameter values
rosparam set 参数类型
-
rosparam get get the specific parameter value
-
rosparam delete delete parameters
-
rosparam load loads parameters to disk
-
rosparam dump loads parameters from disk