Skip to content

Publishing Topics and Advertising Services to the Server

Karthik Dharmarajan edited this page Jun 7, 2021 · 1 revision

Publishing Topics and Advertising Services to the Server

ROS Package Structure

In order to publish topics or advertise services from the local ROS network to the server, the Python code written to translate between local ROS message types and Python dictionaries needs to be accessible by the main server_connector node. This section outlines how to make the new package's code accessible to the server_connector node.

Example: Depth Camera Publisher (Publishes RGB images from camera to server)

File Structure:

└── src
    └── depth_camera_publisher
        ├── __init__.py
        └── sensor_registerer.py
├── CMakeLists.txt
├── package.xml
├── setup.py

Follow the tutorial here to set up Python module sharing: https://roboticsbackend.com/ros-import-python-module-from-another-package/. The depth camera publisher's setup is shown above.

Code Setup

The way topics are published and services are advertised is through a roslibpy ROS connection object. Documentation about this is found here: https://roslibpy.readthedocs.io/en/latest/reference/index.html#ros-setup

Luckily, much of this has been abstracted by the TopicPublisher class, which provides convenient methods for publishing topics and advertising services. However, in order to access the same connection object that already connects to the server, the new package's code must be on the same process. After completing the Python module sharing step, the next step is to tell the server_connector module about the existence of the new package.

Firstly, the new package must implement a setup module as follows: (From depth_camera_publisher)

def setup(connection_manager):

The connection_manager object is of type ConnectionManager, and it has a field topic_publisher of type TopicPublisher which will be relevant for this part of the tutorial. This setup method will be the only method called by the server_connector. Details about using the TopicPublisher will be shown in a separate Wiki page.

In order to pass new module information to the server_connector, the launch for the server_connector will be, as an example, roslaunch server_connector start_connection.launch setup_modules:=["depth_camera_publisher.sensor_registerer"]. setup_modules is a ROS argument that is a list of strings, where the setup method described above resides in. In the example above, the setup method is in the module depth_camera_publisher.sensor_registerer, where the first part is the name of the module, and the second is the specific Python file that contains the setup file.