当前位置:网站首页>ROS parameter server

ROS parameter server

2022-06-11 01:36:00 Mbot

First create a function package in the workspace

catkin_create_pkg test_param std_msgs roscpp rospy

Create a... Under the feature pack param Folder
 Insert picture description here
stay param Create one under the folder param.yaml file
The contents are as follows :

string: dsad3421
num1: 564.65
num2: 87896
sub_param_set:
  string: cvvx
  num: 423
  sub_sub_param_set:
    string: gfdg
    num: 767

Then load the parameters :
First run

roscore

And then param Run under folder directory

rosparam load param.yaml
rosparam list

give the result as follows :
 Insert picture description here
It can be used rosparam get and rosparam set To get and set parameter values
 Insert picture description here
The function of the package is src Create under directory test_param.cpp
 Insert picture description here
Fill in the following :

#include <string>
#include <ros/ros.h>
int main(int argc, char **argv)
{
     int aaa;
    // ROS Node initialization 
    ros::init(argc, argv, "parameter_config");
    //  Create node handle 
    ros::NodeHandle node;
    ros::param::get("/sub_param/num", aaa);
    ROS_INFO("aaa=%d\n", aaa);
    return 0;
}

The function of the package is CMakeLists.txt Add :

add_executable(test_param src/test_param.cpp)
target_link_libraries(test_param ${catkin_LIBRARIES})

then catkin_make Run... After compilation

rosrun test_param test_param

give the result as follows , When running this node , Must use rosparam load After loading the parameter file ,ROS Inner talent get To the value of the parameter , I used it here before rosparam set Set parameters /sub_param/num The value of is 456, So here get The value of is 456, without set, Then this value is the value in the parameter file
 Insert picture description here

原网站

版权声明
本文为[Mbot]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110025144087.html