你做错了什么,你可以尝试类似下面的东西,
import rospy
from std_msgs.msg import Float32
class Handler():
def __init__(self):
rospy.subscriber('x_values', Float32, self.callback_xvalues)
rospy.subscriber('y_values', Float32, self.callback_yvalues)
rospy.subscriber('theta_values', Float32, self.callback_zvalues)
self.extreme_pub = rospy.publisher('extreme/results', Float32, queue_size = 10)
self.x = None
self.y = None
self.theta = None
def callback_xvalues(self, data):
self.y = data
def callback_yvalues(self, data):
self.y = data
def callback_zvalues(self, data):
self.y = data
if((self.x is not None) and (self.theta is not None)):
self.extreme = (self.x - self.y) + ((self.x * self.y) * cos(self.theta))
info = Float32()
info.data = self.extreme
self.extreme_pub.publish(info)
rospy.init_node('extreme_values', annonymous=True)
node_ = Handler()
rospy.subscriber
不返回任何内容,但是当消息到达时触发相应的回调,即 callback_xvalues,因此您的逻辑应该在这些回调之一中实现,即 callback_zvalues。不要为不同的主题注册相同的回调,不推荐。让我知道你明白了