[ROS] How to let nodes in ROS get data III -- Introduction to parameter server communication and ros common tool instructions

insert image description here

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.


insert image description here

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.
insert image description here
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 :

  1. 32-bit integers
  2. booleans
  3. strings
  4. doubles
  5. iso8601 dates
  6. lists
  7. base64-encoded binary data
  8. dictionary

1. The parameter server adds/modifies parameters:

  1. initialize node
  2. 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})

insert image description here

2. The parameter server looks for parameters

Commonly used are the following functions:

  1. 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 memory
    radius2=rospy.get_param_cached("radius_p",0.5)
    
    radius=rospy.get_param("radius_p",0.5)
    
  2. get_param_names()
    gets all the parameter names in the current parameter list and returns
    names=rospy.get_param_names()
    
    for name in names:
    
     print(name)
    
  3. has_param(key)
    determines whether there is a parameter in the parameter list and
    returns a Bool value
    flag1=rospy.has_param("radius_p")
    
     if flag1:
    
         print("存在")
    
     else :
    
         print("不存在")
    
  4. search_param(key)
    to find if there is this message, if not, return None, if there is, return this key
    key=rospy.search_param("radius_p")
    
    print(key)
    

3. The parameter server deletes the parameter:

  1. 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

insert image description here

Use rosnode directly to view the parameter list
insert image description here

  1. 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
    insert image description here

  2. rosnode list lists active nodes

    rosnode list
    

    Use this command to view the currently active nodes
    insert image description here

  3. 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 :

    1. node name
    2. use topics
    3. receiver/sender

    Reasonable use can make it easier to clarify the relationship between nodes

insert image description here

  1. rosnode machine lists the nodes on the specified device
  2. rosnode kill kills a node
    rosnode kill /sub_person
    
    Killed the subscription node
  3. 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
insert image description here

  1. rostopic list shows all topics currently in use

    rostopic list
    

    insert image description here

    For example, the topic used here is /che

  2. rostopic echo acts as the receiver and can print topic information on the screen

    rostopic echo topic
    

    insert image description here

    For example, here you can verify whether the information of the publisher is correct

  3. 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

  4. rostopic find finds topics using a message type

    rostopic find lesson2/Person
    

    insert image description here

    For example, what is the topic of finding the message type of lesson2/Person here?

  5. 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.

  1. rosmsg list lists all message types
    insert image description here

  2. rosmsg show / info lists the specific types contained in the current message type

    rosmsg show msg
    

    insert image description here


  3. rosmsg package lists all messages under a package

    rosmsg package pack
    

    insert image description here

    List all message types in turtlesim

  4. rosmsg packages lists the packages that contain a message

    rosmsg package pack
    

    List all packages containing the turtlesim/Pose message type
    insert image description here

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
insert image description here

  1. rosservice list lists the list of parameter services
    insert image description here

  2. rosservice call calls the service
    here to call /sum2 tab to complete and pass in two parameters

    rosservice call /sum2
    

    insert image description here

  3. rosservice args to view the specific parameters of the srv message

    rosservice args /sum2
    

    insert image description here

The rest of the usage is the same as above

4.5 rossrv

Similar to rosmsg, it also checks the specific type of srv
insert image description here

4.6 rosparam

Let's start the turtle first for verification
insert image description here

rosrun turtlesim turtlesim_node
  1. rosparam list lists the parameter list
    insert image description here

  2. rosparam set sets specific parameter values

    rosparam set 参数类型
    

    Please add a picture description

  3. rosparam get get the specific parameter value

  4. rosparam delete delete parameters

  5. rosparam load loads parameters to disk

  6. rosparam dump loads parameters from disk

So far, the introduction of parameter server communication and ros common tool instructions is over

Guess you like

Origin blog.csdn.net/qq_62839589/article/details/130650185