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

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:

主站蜘蛛池模板: 汶上县| 会理县| 临沧市| 鹿泉市| 根河市| 陆丰市| 鄢陵县| 化德县| 肥东县| 麦盖提县| 贺兰县| 张家港市| 西畴县| 鄂伦春自治旗| 枣阳市| 三明市| 滨州市| 白河县| 县级市| 华阴市| 吉隆县| 宁晋县| 桑植县| 平凉市| 武义县| 都江堰市| 华安县| 隆德县| 普宁市| 乌海市| 达尔| 财经| 沙河市| 台南市| 喀喇沁旗| 偏关县| 梓潼县| 南投市| 东乡族自治县| 中西区| 连云港市|