"True" parallelization in rospy with subscribers
Hey everyone,
Using Rospy (python 2.7) with Indigo.
I ran into the issue that once I command a moveit group to "go" with wait=True it will be a blocking call that causes my subscription to topics to stop / pause until I run something like rospy.sleep() or something similar to let it catch up and get some data. I think it issues a global lock that blocks all running threads (even subscribers). Is there a better way to do this? I was thinking maybe multiprocessing but I could not get a simple example like this to work:
#! /usr/bin/env python
import rospy
import multiprocessing as mp
from geometry_msgs.msg import PoseStamped
class P1(mp.Process):
def __init__(self):
super(P1, self).__init__()
rospy.init_node('p1')
self.data = PoseStamped()
pass
def run(self):
rospy.Subscriber("/listener", PoseStamped, self.receive_pose_data)
rospy.spin()
def receive_pose_data(self, data):
print(data)
self.data = data
def get_data(self):
return self.data
p = P1()
p.start()
while not rospy.is_shutdown():
rospy.sleep(1)
print(p.get_data())
Thankful for any advice of what I might be doing wrong here!