Ask Your Question

Offline node subscribers of generated messages

asked 2015-04-22 22:20:39 -0500

EEngineer gravatar image

I have some nodes running some algorithms that take varying amounts of time right now. For debugging, I've created offline processing programs that read from bags and feed the data into nodes. Currently, the processing is done in these callbacks (for better or worse) and at the end it checks for subscribers and publishes messages depending on who is listening.

Is there a way to set up subscribers without running a live ROS system to write this data to a bag without re-architecting the callbacks and publishing? E.g. the nh.subscribe call without a node handle?

Some sample code:

 * Inherits from message_filters::SimpleFilter<M>
 * to use protected signalMessage function
template <class M>
class BagSubscriber : public message_filters::SimpleFilter<M>
    void newMessage(const boost::shared_ptr<M const> &msg)

// Callback for synchronized messages
void proxyCallback(const sensor_msgs::Image::ConstPtr &l_img,
              const sensor_msgs::Image::ConstPtr &r_img,
              const sensor_msgs::CameraInfo::ConstPtr &l_info,
              const sensor_msgs::CameraInfo::ConstPtr &r_info)
    // This will result in publications on certain topics, I'd like to create an offline callback
    node.image_callback(l_img, r_img, l_info, r_info); 

// How can I do this?
void visualizationCallback(const MarkerArray::ConstPtr &array)
   output_bag.write("/topic", array->header.stamp, array);

int main(int argc, char ** argv)
    typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::CameraInfo, sensor_msgs::CameraInfo> ApproximatePolicy;

    typedef message_filters::Synchronizer<ApproximatePolicy> ApproximateSync;
    boost::shared_ptr<ApproximateSync> approximate_sync_;

    // Set up fake subscribers to capture images
    BagSubscriber<sensor_msgs::Image> l_img_sub, r_img_sub;
    BagSubscriber<sensor_msgs::CameraInfo> l_info_sub, r_info_sub;

    approximate_sync_.reset(new ApproximateSync(ApproximatePolicy(25),
                                                l_img_sub, r_img_sub, l_info_sub, r_info_sub) );

    approximate_sync_->registerCallback(boost::bind(&proxyCallback, _1, _2, _3, _4));

    // I want a real subscriber for data generated here
    ros::Subscriber sub = nh.subscribe("my_topic", 1, visualizationCallback);

    BOOST_FOREACH(rosbag::MessageInstance const m, view)
    // Loop through messages
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2018-11-03 10:43:30 -0500

Matias gravatar image

Hi, I just created something that might be useful for this case. Please look into

edit flag offensive delete link more

answered 2015-08-28 03:04:21 -0500

tfoote gravatar image

You cannot use the subscribe API to get callbacks unless you are "running" ROS.

However I think you should look at the rosbag API for offline processing.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-04-22 22:20:39 -0500

Seen: 239 times

Last updated: Nov 03 '18