ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

Subscription topic not connecting to sensor output data

I’m trying to create a python script as shown below to acquire sensor data. The sensor output data works in a cpp program, but not a Python script. No output from print statement in callback, any thoughts?

import pdb
import rclpy
from sensor_msgs.msg import Image
import time

class Test():
    def __init__(self, node):
        self.sub = node.create_subscription(Image,'image', self.callback) 
    def callback(self, data):        

def main(args=None):

    node = rclpy.create_node('Test')    
    test = Test(node)
    assert test  # prevent unused variable warning  

    while rclpy.ok():

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)

if __name__ == '__main__':

Output from pdb

> node = rclpy.create_node('Test') 
(Pdb) n 
> path/install/lib/python3.5/site-packages/ 
-> test = Test(node) 
(Pdb) s 
> path/install/lib/python3.5/site-packages/ 
-> def __init__(self, node): 
> path/install/lib/python3.5/site-packages/ 
-> self.sub = node.create_subscription(Image,'image', self.callback) 
> path/install/lib/python3.5/site-packages/rclpy/ 
-> def create_subscription(self, msg_type, topic, callback, qos_profile=qos_profile_default): 
> path/install/lib/python3.5/site-packages/rclpy/ 
-> if msg_type.__class__._TYPE_SUPPORT is None: 
> path/install/lib/python3.5/site-packages/rclpy/ 
-> msg_type.__class__.__import_type_support__() 
(Pdb) r 
> path/install/lib/python3.5/site-packages/rclpy/><rclpy.subscr...x7fdc34068b70> 
-> return subscription 
> path/install/lib/python3.5/site-packages/ 
-> time.sleep(2) 
> path/install/lib/python3.5/site-packages/>None 
-> time.sleep(2) 
> path/install/lib/python3.5/site-packages/ 
-> assert test  # prevent unused variable warning 

Hi @vdiluoffo,

I tried your code on my machine and the callback is called every time a message is received. Could you give more detail about your configuration? (version of the code, rmw_implementation used).
How are you publishing your images?

Note: I tested it running cam2image -b in a terminal and your code sample in another one.


Hi Mikael,
Thanks for your reply and interesting on your results.

  1. Beta 1 using RTI 5.2.5 on Linux 16.04
  2. I tried both FRTPS and Connext with same results
  3. I was using Turtlebot_demo code from here:
  4. The camera is astra camera
  5. Follower works with connext
  6. Line 132, 133 from astra_driver.cpp:
    pub_depth_raw_ = nh_->create_publisher<sensor_msgs::msg::Image>(“image”, rmw_qos_profile_sensor_data);
    The node is up with starting depth stream
  7. Ok tried your test and works with both FRTPS and Connext


Another test that I did was run the showimage with astra camera publishing. That worked, but the image window was very grainy and gray. No picture was shown.

I was also looking at the difference between orbbec/ros_astra_camera and ros2/ros_astra_camera ( forked from orbbec/ros_astra_camera), It seems that these aren’t sync’d. The CMakeLists.txt is pulling from GIT_REPOSITORY for ros2/ros_astra_camera and GIT_REPOSITORY for orbbec/ros_astra_camera. Is this correct? Also no issue tab on site