ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

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) 
        
        time.sleep(2)
        
    def callback(self, data):        
        print(data)
      

def main(args=None):
    rclpy.init(args)
    pdb.set_trace()

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

    while rclpy.ok():
        rclpy.spin_once(node)

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

if __name__ == '__main__':
    main()

Output from pdb

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

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.

Cheers,
Mikael

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: https://github.com/ros2/turtlebot2_demo
  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);
    this->depthConnectCb();
    The node is up with starting depth stream
  7. Ok tried your test and works with both FRTPS and Connext

Thanks
Vince

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 https://github.com/tfoote/OpenNI2.git for ros2/ros_astra_camera and GIT_REPOSITORY https://github.com/orbbec/OpenNI2.git for orbbec/ros_astra_camera. Is this correct? Also no issue tab on https://github.com/ros2/ros_astra_camera site