问题描述
我有这个代码,它从节点接收数据(订阅),然后在这个节点内我做了一些 数学运算,然后我想将数据发布到某个主题。
#!/usr/bin/env python
import rospy
from std_msgs.msg import String,Float32
from math import cos,sin
import sys
import os
import logging
from types import *
import time
class exact_pose():
def callback_car_yaw(self,data):
self.car_yaw = data
def callback_line_pose(self,data):
self.line_pose = data
def init(self):
self.car_yaw = None
self.line_pose = None
def subscriber(self):
self.car_yaw_sub = rospy.Subscriber('~car/yaw',Float32,self.callback_car_yaw)
self.line_pose_sub = rospy.Subscriber('~line_pose',self.callback_line_detect_xL15)
def publisher(self):
self.exact_pose_pub = rospy.Publisher('exact_pose',queue_size=10)
rospy.Rate(1)
rospy.spin()
#sloving for exact pose
def calculation(self,):
while not rospy.is_shutdown():
self.exact_pose = self.line_pose_sub * cos(self.car_yaw_sub) + self.line_pose_sub * sin(self.car_yaw_sub)
info1 = Float32()
info1.data = self.exact_pose
self.exact_pose_pub.publish(info1)
rospy.Rate.sleep()
rospy.spin()
if __name__ == '__main__':
rospy.init_node('exact_pose',anonymous=True)
try:
ne = exact_pose()
except rospy.ROSInterruptException: pass
代码的作用是,从前一个节点订阅一个主题,然后对这些主题内的数据进行一些数学运算,然后将最后的结果发布到单独的节点上
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)