[ros-users] [Discourse.ros.org] [Next Generation ROS] Subscription topic not connecting to sensor output data

vdiluoffo ros.discourse at gmail.com
Tue Jan 31 20:40:20 UTC 2017

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

[Visit Topic](https://discourse.ros.org/t/subscription-topic-not-connecting-to-sensor-output-data/1245/1) or reply to this email to respond.

More information about the ros-users mailing list