cannot connect to more than one topic?
hi, this simple code does not work with both subscribers, it only calls the callback of the first subscriber prox11callback, but the second never gets called ?
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from dynamixel_msgs.msg import JointState
from std_msgs.msg import Float64
prox1_1_pub = rospy.Publisher('/proximal1_1_controller/command', Float64, queue_size=1)
prox1_2_pub = rospy.Publisher('/proximal1_2_controller/command', Float64, queue_size=1)
def prox1_1_callback(data):
rospy.loginfo("prox1_1 load: %f", data.load)
rospy.loginfo("name %s", data.name)
def prox1_2_callback(data2):
rospy.loginfo("prox1_2 load: %f", data2.load)
rospy.loginfo("name: %s", data2.name)
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("/proximal1_1_controller/state", JointState, prox1_1_callback)
rospy.Subscriber("/proxiaml1_2_controller/state", JointState, prox1_2_callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
listener()
what is the problem, the code is the same ?
thanks for help
EDIT: If i use:
rate = rospy.Rate(1)
while not rospy.is_shutdown():
rate.sleep()
instead of rospy.spin() it also does only print the first callback ??
EDIT-2: If i use the rospy.Subscriber calls global, it works ?? is that correct way ?
Asked by inflo on 2017-01-12 07:04:18 UTC
Comments