How can I read ROS topics in python?

asked 2020-03-20 05:09:18 -0500

TestUser gravatar image

Hi guys,

i want to know if there is any way to read subscribers and publishers from an executable file in Python? I have searched in roslaunch API but didn't find anything related to this.

edit retag flag offensive close merge delete

Comments

Could you clarify how this is related to #q346984?

gvdhoorn gravatar image gvdhoorn  ( 2020-03-20 05:11:46 -0500 )edit

I wanted to read ROS topics directly from the launchfile, but couldn't find anything. I don't want to execute any node I just want to read from files. So If I have file location where a publisher or subscriber lives, what API can I use to extract the publisher or subscriber of that file. I hope I made it clear.

TestUser gravatar image TestUser  ( 2020-03-20 05:17:26 -0500 )edit
1

For me that is a bit weird since the topic only exists while a ROS Master is running and a node is using it. Hence, in order to know what topics are used, you have to execute the nodes, in the case they are hardcoded. If they are passed as argument you may find those on the parameter server, but I still do not know the purpose of this.

Weasfas gravatar image Weasfas  ( 2020-03-24 15:09:03 -0500 )edit
2

It sounds like something which could be used as part of a static code analysis.

However this is far from trivial to do. One of the reasons is what @Weasfas hints at: topics could be created by code segments which hard-code a particular control flow/execution path, but also dynamically, based on events which only happen at runtime.

This does not make it impossible, but a hard challenge.

Having written this, @TestUser, you could perhaps take a look at haros, which tries to achieve something similar, but mostly for C++. Success is limited, and Pythons support has only recently been added.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-25 05:45:37 -0500 )edit