完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
创建功能包
cd ~/catkin_workspace/src catkin_create_pkg learning_parameter roscpp rospy std_srvs 参数命令行使用 YAML参数文件 background_b: 255 background_g: 86 background_r: 69 rosdistro: 'lunar' roslaunch: uris: {host_hcx_vpc__43763: 'http://hcx-vpc:43763/'} rosversion: '1.14.31' run_id: 077058de-a38b-11e9-818b-000c29d22e4d rosparam # 新建一个终端 roscore # 新建一个终端 rosrun turtlesim turtlesim_node # 新建一个终端 rosparam 列出当前参数 rosparam list 显示某个参数值 rosparam get param_key设置某个参数值 rosparam set param_key param_value保存参数到文件 rosparam dump file_name 从文件读取参数 rosparam load file_name 删除参数 rosparam delete param_key C++ 编写程序 nano ~/catkin_workspace/src/learning_parameter/src/parameter_config.cpp /*********************************************************************** Copyright 2020 GuYueHome (www.guyuehome.com). ***********************************************************************/ /** * 该例程设置/读取海龟例程中的参数 */ #include #include #include int main(int argc, char **argv) { int red, green, blue; // ROS节点初始化 ros::init(argc, argv, "parameter_config"); // 创建节点句柄 ros::NodeHandle node; // 读取背景颜色参数 ros::param::get("/background_r", red); ros::param::get("/background_g", green); ros::param::get("/background_b", blue); ROS_INFO("Get Backgroud Color[%d, %d, %d]", red, green, blue); // 设置背景颜色参数 ros::param::set("/background_r", 255); ros::param::set("/background_g", 255); ros::param::set("/background_b", 255); ROS_INFO("Set Backgroud Color[255, 255, 255]"); // 读取背景颜色参数 ros::param::get("/background_r", red); ros::param::get("/background_g", green); ros::param::get("/background_b", blue); ROS_INFO("Re-get Backgroud Color[%d, %d, %d]", red, green, blue); // 调用服务,刷新背景颜色 ros::service::waitForService("/clear"); ros::ServiceClient clear_background = node.serviceClient std_srvs::Empty srv; clear_background.call(srv); sleep(1); return 0; } 配置CMakeLists.txt nano ~/catkin_workspace/src/learning_parameter/CMakeLists.txt 添加 add_executable(parameter_config src/parameter_config.cpp) target_link_libraries(parameter_config ${catkin_LIBRARIES}) 编译并运行 cd ~/catkin_workspace catkin_make # 新建一个终端 source ~/catkin_workspace/devel/setup.bash roscore # 新建一个终端 source ~/catkin_workspace/devel/setup.bash rosrun turtlesim turtlesim_node # 新建一个终端 source ~/catkin_workspace/devel/setup.bash rosrun learning_parameter parameter_config python 编写程序 cd ~/catkin_workspace/src/learning_parameter mkdir scripts nano ~/catkin_workspace/src/learning_parameter/scripts/parameter_config.py 1 2 3 #!/usr/bin/env python # -*- coding: utf-8 -*- ######################################################################## #### Copyright 2020 GuYueHome (www.guyuehome.com). ### ######################################################################## # 该例程设置/读取海龟例程中的参数 import sys import rospy from std_srvs.srv import Empty def parameter_config(): # ROS节点初始化 rospy.init_node('parameter_config', anonymous=True) # 读取背景颜色参数 red = rospy.get_param('/background_r') green = rospy.get_param('/background_g') blue = rospy.get_param('/background_b') rospy.loginfo("Get Backgroud Color[%d, %d, %d]", red, green, blue) # 设置背景颜色参数 rospy.set_param("/background_r", 255); rospy.set_param("/background_g", 255); rospy.set_param("/background_b", 255); rospy.loginfo("Set Backgroud Color[255, 255, 255]"); # 读取背景颜色参数 red = rospy.get_param('/background_r') green = rospy.get_param('/background_g') blue = rospy.get_param('/background_b') rospy.loginfo("Get Backgroud Color[%d, %d, %d]", red, green, blue) # 发现/spawn服务后,创建一个服务客户端,连接名为/spawn的service rospy.wait_for_service('/clear') try: clear_background = rospy.ServiceProxy('/clear', Empty) # 请求服务调用,输入请求数据 response = clear_background() return response except rospy.ServiceException, e: print "Service call failed: %s"%e if __name__ == "__main__": parameter_config() 运行 sudo chmod +x ~/catkin_workspace/src/learning_parameter/scripts/parameter_config.py # 新建一个终端 source ~/catkin_workspace/devel/setup.bash roscore # 新建一个终端 source ~/catkin_workspace/devel/setup.bash rosrun turtlesim turtlesim_node # 新建一个终端 source ~/catkin_workspace/devel/setup.bash rosrun learning_parameter parameter_config.py |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1423 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
1534 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
3465 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 13:28 , Processed in 0.751926 second(s), Total 71, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号