Ask Your Question
0

Can the subscriber be part of a separate package than the one that it is subscribing to? [closed]

asked 2016-07-12 16:38:48 -0500

skr_robo gravatar image

Hello, I have the basic idea of writing a subscriber. But I am not quite sure about where it is to be placed. Suppose I am subscribing to a topic in a particular package (not written by me). Is it necessary that the subscriber code (C++ or python) be placed inside the src folder of this package or can I create a separate package just for this subscriber?

Will creating a new package for subscriber make writing/editing the the CMakeLists.txt and package.xml more difficult?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by skr_robo
close date 2016-07-14 10:35:58.103158

1 Answer

Sort by ยป oldest newest most voted
4

answered 2016-07-12 19:52:49 -0500

ahendrix gravatar image

Publishers and subscribers do not need to be in the same package; in fact, this is one of the strengths of ROS, because it means that you can interact with someone else's code without needing to modify it.

When you're setting up your CMakeLists and your package.xml for your subscriber, you should declare a dependency on the message package that contains the message type definition for the topic that you want to subscribe to. For some cases, this message may be in the package with the publisher (for custom messages), but in most cases the message definition will probably be in a separate package.

For example, most laser scanners publish a sensor_msgs/LaserScan, and so you should depend on the sensor_msgs package, and your code doesn't need a dependency on the specific driver for your laser, regardless of whether you're using a Hokuyo, SICK, or other brand of laser.

edit flag offensive delete link more

Comments

Thank you for the reply. I am looking to subscribe to the topic /camera/depth/image_rect_color obtained from zed-ros-wrapper. So, are the message package and zed-ros-wrapper package my only dependencies?

skr_robo gravatar image skr_robo  ( 2016-07-13 11:13:43 -0500 )edit

I mean, how do I identify my other dependencies, if any?

skr_robo gravatar image skr_robo  ( 2016-07-13 11:17:41 -0500 )edit

The wiki page for zed_ros_wrapper doesn't document the topic type, but I suspect it's a sensor_msgs/Image. (Image type from the sensor_msgs package). Therefore your only dependency should be the sensor_msgs package.

ahendrix gravatar image ahendrix  ( 2016-07-13 11:49:29 -0500 )edit

You can also use rostopic info <topic> to determine the type of a published topic, if there isn't good documentation.

ahendrix gravatar image ahendrix  ( 2016-07-13 11:50:46 -0500 )edit

Note that your node does not need a dependency on zed_ros_wrapper

ahendrix gravatar image ahendrix  ( 2016-07-13 11:51:58 -0500 )edit

It is sensor_msgs. I was concerned whether I would need any other dependencies or not. Thanks a lot.

skr_robo gravatar image skr_robo  ( 2016-07-13 12:12:35 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-12 16:38:48 -0500

Seen: 55 times

Last updated: Jul 12 '16