ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 get the class of a given topic

asked 2023-01-18 14:27:36 -0600

lfb gravatar image

Hi, how can a I get the class of a given topic in ROS2? Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-01-23 06:39:02 -0600

AibohphobiA gravatar image

Your question is not entirely clear. topics are of type message - not class.

As described in ROS2 Manual: If you want to know the type of message, you can use:

ros2 topic list -t

which will result in a similar output:

/parameter_events [rcl_interfaces/msg/ParameterEvent] ...

so that /parameter events is the topic/message name and rcl_interfaces/msg/ParameterEvent is the type.

Hope this helps.

edit flag offensive delete link more

Comments

sorry! I meant from a ROS2 python node.

lfb gravatar image lfb  ( 2023-01-23 09:32:23 -0600 )edit

What do you mean for "class"?

Andromeda gravatar image Andromeda  ( 2023-01-23 12:01:00 -0600 )edit

the message type of a given topic through a python ros2 node.

lfb gravatar image lfb  ( 2023-01-23 13:17:06 -0600 )edit

It does not make sense. In a node you import (using Python) already at the beginning of the file the message type (or class if you prefer), that you want to subscribe/publish. If I understood, you want a node, which automatically detect a topic and then it tries to identify the message sent. It does not make sense such design, since you could expect anything from a string to a pose messagge.

Andromeda gravatar image Andromeda  ( 2023-01-23 23:30:12 -0600 )edit

It has no sense for you because you have assumed that I only want to send messages through a given topic. What I would like to know is if is there a function y Python like the cpp get_topic_names_and_types function.

lfb gravatar image lfb  ( 2023-01-24 04:14:07 -0600 )edit

My assumption is based on what you wrote in your post above and on the information you gave us.

Andromeda gravatar image Andromeda  ( 2023-01-24 04:17:26 -0600 )edit

Please, stop making noise if you cannot help me.

lfb gravatar image lfb  ( 2023-01-24 04:26:05 -0600 )edit

Hi lfb, As I mentioned before, you can run ros2 topic list through an terminal and get the type. I found an example on how to use the API you just mentioned in the following link

Let me know if this helps.

AibohphobiA gravatar image AibohphobiA  ( 2023-01-24 04:41:04 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2023-01-18 14:27:36 -0600

Seen: 119 times

Last updated: Jan 23 '23