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)