4.Publisher

4.1 Publisher

Publishers, as the name suggests, serve to publish messages. The message here can be sensor information transmitted from the lower computer to the upper computer, which is then packaged and sent to subscribers who have subscribed to the topic through the upper computer; It can also be the data from the upper computer that has been processed, packaged, and sent to subscribers who subscribe to the topic.

4.2. Create a workspace and topic feature pack

4.2.1 Creating a workspace

4.2.2 Compilation workspace

4.2.3. Updating Environmental Variables

4.2.4. Checking Environmental Variables

4.2.5. Create Function Package

4.2.6 Compilation Function Package

4.3. Creating a Publisher

4.3.1 Creation steps

  1. Initialize ROS node
  2. Create handleRegister
  3. node information with ROS Master, including the published topic name, message types in the topic, and queue length
  4. Create and initialize message data
  5. Cycle sending messages at a certain frequency

4.3.2. C++Language Implementation

  1. In the src folder of the feature pack, create a c++file (with the suffix. cpp) and name it turtle_ velocity_ publisher.cpp
  2. Copy and paste the program code below into the title_ velocity_ In the publisher.cpp file
  1. Program flowchart, corresponding to 1.3.1 content for viewing

  1. Configure in CMakelist.txt, under the build area, add the following content
  1. Compiling code under workspace directory
  1. run a program
  1. Screenshot of operation effect

  1. Program operation instructions

This indicates that Little Turtle is a subscription/tourle1/cmd_ The speed topic is vel, so the publisher keeps sending speed data. After receiving it, the little turtle starts to move according to the speed

4.3.3. Python Language Implementation

  1. In the feature pack directory, create a new folder called scripts, and then create a new Python file (with the suffix. py) under the scripts folder, named turtle_ velocity_ publisher.py
  2. Copy and paste the program code below into the title_ velocity_ In the publisher.py file
  1. Process Flow Chart

  1. run a program

Note: Before running, it is necessary to give the title_ velocity_ Publisher.py adds executable permissions in the title_ velocity_ Open the terminal in the publisher.py folder,

All Python requires adding execute file permissions, otherwise an error will be reported!5) Refer to 1.3.2 for operational effects and program instructions.