4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
热卖商品
新闻详情
ROS学习笔记(一):自己动手写一个ROS程序_yake827的专栏-CSDN博客
来自 : CSDN技术社区 发布时间:2021-03-25
* The ros::init() function needs to see argc and argv so that it can perform * any ROS arguments and name remapping that were provided at the command line. For programmatic * remappings you can use a different version of init() which takes remappings * directly, but for most command-line programs, passing argc and argv is the easiest * way to do it. The third argument to init() is the name of the node. * You must call one of the versions of ros::init() before using any other * part of the ROS system. ros::init(argc, argv, listener * NodeHandle is the main access point to communications with the ROS system. * The first NodeHandle constructed will fully initialize this node, and the last * NodeHandle destructed will close down the node. ros::NodeHandle n; * The subscribe() call is how you tell ROS that you want to receive messages * on a given topic. This invokes a call to the ROS * master node, which keeps a registry of who is publishing and who * is subscribing. Messages are passed to a callback function, here * called chatterCallback. subscribe() returns a Subscriber object that you * must hold on to until you want to unsubscribe. When all copies of the Subscriber * object go out of scope, this callback will automatically be unsubscribed from * this topic. * The second parameter to the subscribe() function is the size of the message * queue. If messages are arriving faster than they are being processed, this * is the number of messages that will be buffered up before beginning to throw * away the oldest ones. ros::Subscriber sub n.subscribe( chatter , 1000, chatterCallback); * ros::spin() will enter a loop, pumping callbacks. With this version, all * callbacks will be called from within this thread (the main one). ros::spin() * will exit when Ctrl-C is pressed, or the node is shutdown by the master. ros::spin(); return 0;}
编译创建的节点
在编译我们创建的节点之前 我们还需要编辑Cmakelist.txt文件 注意 是beginner_tutorials项目包下的CMakelist文件 告诉编辑器我们需要编辑什么文件 需要什么依赖。

$ gedit CMakeLists.txt
在文件末尾添加如下语句

include_directories(include ${catkin_INCLUDE_DIRS})add_executable(talker src/talker.cpp)target_link_libraries(talker ${catkin_LIBRARIES})add_dependencies(talker beginner_tutorials_generate_messages_cpp)add_executable(listener src/listener.cpp)target_link_libraries(listener ${catkin_LIBRARIES})add_dependencies(listener beginner_tutorials_generate_messages_cpp)

将目录切换到工作区目录 并执行catkin_make运行命令

$ cd ~/catkin_ws$ catkin_make

不出意外的话 会出现如下界面

\"\"
至此 程序已经创建完成 而接下来我们要检查一下我们创建的程序是否正确。

测试程序的正确性 首先 我们得要启动ROS核心程序roscore。

本文链接: http://wasros.immuno-online.com/view-750558.html

发布于 : 2021-03-25 阅读(0)
公司介绍
品牌分类
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://