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

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:

主站蜘蛛池模板: 罗平县| 沂水县| 丰台区| 鄱阳县| 平潭县| 衡水市| 汶川县| 和林格尔县| 阿荣旗| 苗栗市| 中牟县| 岫岩| 喀喇沁旗| 彩票| 巴东县| 法库县| 莱阳市| 乡宁县| 团风县| 璧山县| 景谷| 桐乡市| 东丰县| 马鞍山市| 增城市| 阿瓦提县| 云和县| 平湖市| 西乌珠穆沁旗| 湘阴县| 大埔区| 延庆县| 金平| 乐昌市| 九江市| 贵州省| 乳山市| 旅游| 巴南区| 长汀县| 涿州市|