run-time update of odometry message while publishing to a new topic
hello everyone. I am trying to publish odometry messages over a new topic. I am having a small problem. I am subscribing to odom topic
, thhen creating a new topic and publishing the message with some change. The code is working. But when i run rostopic echo odom2
, it just gives me constant values and not the updated changing values. I am subscribing the newly published topic also, but data is not being updated in run time. Below is my code. What could be the posssible reason and how can i resolve the issue.
#!/usr/bin/env python
import rospy
from tf.transformations import euler_from_quaternion
from nav_msgs.msg import Odometry
def listener():
rospy.init_node('move_turtlebot', anonymous=True)
rospy.Subscriber("odom", Odometry, move_turtlebot)
rospy.spin()
def move_turtlebot(data):
pub = rospy.Publisher('odom2', Odometry, queue_size=10)
move_turtlebot= Odometry()
data.header.stamp= rospy.Time.now()
data.header.frame_id = "odom"
data.pose.covariance= [0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
pub.publish(data)
rospy.sleep(0.25)
if __name__ == '__main__':
try:
listener()
except rospy.ROSInterruptException:
pass