我试图通过Python来订阅4个不同的出版商ROS。我使用下面的代码:ROS蟒蛇发布/订阅
def callback(data):
rospy.loginfo (" Publisher1 Value %s ", custom_msg1.custom_string1)
rospy.loginfo (" Publisher2 Value %s ", custom_msg2.custom_string2)
rospy.loginfo (" Publisher3 Value %s ", custom_msg3.custom_string3)
rospy.loginfo (" Publisher4 Value %s ", custom_msg4.custom_string4)
rospy.loginfo (" float_publisher value %f ", data.Float64)
def python_code():
rospy.init_node("python_code")
rospy.Subscriber("float_publisher",Float64,callback)
rospy.Subscriber("publisher1", custom_msg1,callback)
rospy.Subscriber("publisher2", custom_msg2,callback)
rospy.Subscriber("publisher3", custom_msg3,callback)
rospy.Subscriber("publisher4", custom_msg4,callback)
rospy.loginfo(" Test: start spinning!")
rospy.spin()
rospy.loginfo("node has shutdown!")
其中custom_msg1.msg包含custom_string1定义为字符串,并以同样的方式custom_msg2.msg,custom_msg3.msg和custom_msg4.msg
我想知道我是否使用了浮动消息,也是自定义消息正确。 输出如下:
Publisher1 Value <member 'custom_string1' of 'custom_msg1' objects>
Publisher2 Value <member 'custom_string2' of 'custom_msg2' objects>
Publisher3 Value <member 'custom_string3' of 'custom_msg3' objects>
Publisher4 Value <member 'custom_string4' of 'custom_msg4' objects>
结束一个错误:
rospy.loginfo (" float_publisher value %f ", data.Float64)
AttributeError: 'Custom_msg4' object has no attribute 'Float64'
我不知道如果你想订阅五个不同的主题有五个是怎么回事错在这里
...它的工作原理? – jonrsharpe 2014-11-24 14:10:14
@jonrsharpe我得到一个输出,这是错误的,也是一个错误消息。 – ADI 2014-11-24 14:24:03
您的追踪与您发布的代码不符。另外请注意,'callback'的最后一行不像前四个。 – jonrsharpe 2014-11-24 14:25:32