在这段代码中,编写了一个函数调用,但在定义其变量之一后执行,不会引发错误。
不适用
counter= 0
pub = None
def callback_receive_number_data(msg):
global counter
counter += msg.data
new_msg = Int64()
new_msg.data = counter
pub.publish(new_msg)
sub = rospy.Subscriber('/number', Int64, callback_receive_number_data)
pub = rospy.Publisher('/number_count', Int64, queue_size=10)