Ask Your Question

Revision history [back]

Thank you everyone for telling me good information, I implemented a sample code below.

### `sample_to_show_topic_list.py` ###
from rclpy.callback_groups import ReentrantCallbackGroup
import rclpy
rom rclpy.node import Node

def get_topic_list():
    node_dummy = Node("_ros2cli_dummy_to_show_topic_list")
    topic_list = node_dummy.get_topic_names_and_types()
    node_dummy.destroy_node()
    return topic_list


rclpy.init()
topic_list = get_topic_list()
for info in topic_list:
    print(info[0])
rclpy.shutdown()

Execute this code, and get following output in terminal.

$ ros2 topic pub --rate 1 hoge std_msgs/msg/String "{data: "hoge"}"  # publish a string
$ python3 sample_to_show_topic_list.py  # show topic list

/hoge
/parameter_events
/rosout

Thank you everyone for telling me good information, I implemented a sample code below.

### `sample_to_show_topic_list.py` ###
from rclpy.callback_groups import ReentrantCallbackGroup
import rclpy
rom rclpy.node import Node

def get_topic_list():
    node_dummy = Node("_ros2cli_dummy_to_show_topic_list")
    topic_list = node_dummy.get_topic_names_and_types()
    node_dummy.destroy_node()
    return topic_list


rclpy.init()
topic_list = get_topic_list()
for info in topic_list:
    print(info[0])
rclpy.shutdown()

Execute this code, and get following output in terminal.

$ ros2 topic pub --rate 1 hoge std_msgs/msg/String "{data: "hoge"}"  # publish a string
$ python3 sample_to_show_topic_list.py  # show topic list

/hoge
/parameter_events
/rosout

Thank you everyone for telling me good information, I implemented a sample code below.

### `sample_to_show_topic_list.py` ###
import rclpy
rom from rclpy.node import Node

def get_topic_list():
    node_dummy = Node("_ros2cli_dummy_to_show_topic_list")
    topic_list = node_dummy.get_topic_names_and_types()
    node_dummy.destroy_node()
    return topic_list


rclpy.init()
topic_list = get_topic_list()
for info in topic_list:
    print(info[0])
rclpy.shutdown()

Execute this code, and get following output in terminal.

$ ros2 topic pub --rate 1 hoge std_msgs/msg/String "{data: "hoge"}"  # publish a string
$ python3 sample_to_show_topic_list.py  # show topic list

/hoge
/parameter_events
/rosout

Thank you everyone for telling me good information, I implemented a sample code below.

### `sample_to_show_topic_list.py` ###
import rclpy
from rclpy.node import Node

def get_topic_list():
    node_dummy = Node("_ros2cli_dummy_to_show_topic_list")
    topic_list = node_dummy.get_topic_names_and_types()
    node_dummy.destroy_node()
    return topic_list


rclpy.init()
topic_list = get_topic_list()
for info in topic_list:
    print(info[0])
rclpy.shutdown()

Execute this code, and get following output in the terminal.

$ ros2 topic pub --rate 1 hoge std_msgs/msg/String "{data: "hoge"}"  # publish a string
$ python3 sample_to_show_topic_list.py  # show topic list

/hoge
/parameter_events
/rosout

Thank you everyone for telling me good information, I implemented a sample code below.below using get_topic_names_and_types.

### `sample_to_show_topic_list.py` ###
import rclpy
from rclpy.node import Node

def get_topic_list():
    node_dummy = Node("_ros2cli_dummy_to_show_topic_list")
    topic_list = node_dummy.get_topic_names_and_types()
    node_dummy.destroy_node()
    return topic_list


rclpy.init()
topic_list = get_topic_list()
for info in topic_list:
    print(info[0])
rclpy.shutdown()

Execute this code, and get following output in the terminal.

$ ros2 topic pub --rate 1 hoge std_msgs/msg/String "{data: "hoge"}"  # publish a string
$ python3 sample_to_show_topic_list.py  # show topic list

/hoge
/parameter_events
/rosout