cannot connect to more than one topic?

asked 2017-01-12 06:04:18 -0500

inflo gravatar image

updated 2017-01-12 07:04:05 -0500

hi, this simple code does not work with both subscribers, it only calls the callback of the first subscriber prox1_1_callback, 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",

def prox1_2_callback(data2):
    rospy.loginfo("prox1_2 load: %f", data2.load)
    rospy.loginfo("name: %s",

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

if __name__ == '__main__':

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():

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 ?

edit retag flag offensive close merge delete