官术网_书友最值得收藏!

Creating a ROS package

In this section, we will look at how to create a sample package that contains two Python nodes. One of the nodes is used to publish a Hello World string message on a topic called /hello_pub and the other node will subscribe to this topic.

A catkin ROS package can be created using the catkin_create_pkg command in ROS.

The package is created inside the src folder that we created during the creation of the workspace. Before creating the packages, switch to the src folder using the following command:

    $ cd ~/catkin_ws/src  

The following command will create a hello_world package with std_msgs dependencies, which contain standard message definitions. The rospy is the Python client library for ROS:

    $ catkin_create_pkg hello_world std_msgs rospy  

This is the message we get upon a successful creation:

    Created file hello_world/package.xml 
    Created file hello_world/CMakeLists.txt 
    Created folder hello_world/src 
    Successfully created files in /home/lentin/catkin_ws/src/hello_world. 
Please adjust the values in package.xml.

After the successful creation of the hello_world package, we need to add two Python nodes or scripts to demonstrate the subscribing and publishing of topics.

First, create a folder named scripts in the hello_world package using the following command:

    $ mkdir scripts  

Switch to the scripts folder and create a script named hello_world_publisher.py and another script called hello_world_subscriber.py to publish and subscribe to the hello world message. The following section covers the code and function of these scripts or nodes:

主站蜘蛛池模板: 安岳县| 应城市| 红河县| 潜山县| 五莲县| 那坡县| 远安县| 庆元县| 苏尼特右旗| 高州市| 太和县| 保定市| 石河子市| 钟山县| 乌苏市| 冷水江市| 临江市| 雷山县| 江孜县| 凤阳县| 潼南县| 清河县| 新丰县| 疏勒县| 拜泉县| 宜兴市| 林州市| 绥棱县| 贺州市| 香格里拉县| 保德县| 左云县| 朝阳县| 伽师县| 固原市| 唐海县| 清苑县| 城口县| 安阳县| 平阳县| 安新县|