Accessing data from 4 seconds back
Hi all, I am trying to create my own acceleration node. The idea is to have the difference between 2 velocities, every 4 seconds for example. I know how to get the value of the velocity at the current time. but how do I get the velocity 4 seconds back? the value should be accessible as the program runs, or as bag files are being played.
Below is my code:
#!/usr/bin/env python
import roslib; roslib.load_manifest('kee_use_cases')
import rospy
import math
#from std_msgs.msg import String
from std_msgs.msg import *
from nav_msgs.msg import Odometry
from geometry_msgs.msg import *
def callback(msg):
rospy.loginfo("Received actual forward velocity <</odom>> message! The value is %f" %msg.twist.twist.linear.x)
if rospy.Time.now() == 0:
vel_init = msg.twist.twist.linear.x
buffer_function(vel_init) #?
else:
#how do i get the the vel_init?
vel_last = msg.twist.twist.linear.x
acceleration = (vel_last - vel_init)/4
talker(acceleration)
def buffer_function(vel_init):
return vel_init
def talker(acc):
rospy.loginfo("x_acceleration: %f"%acc)
pub = rospy.Publisher('x_acceleration', Float64 )
pub.publish(acc)
def listener():
rospy.Subscriber("odom", Odometry, callback)
if __name__ == '__main__':
rospy.init_node('x_acceleration', anonymous=True)
duration = 4
while not rospy.is_shutdown():
try:
listener()
rospy.sleep(duration)
except rospy.ROSInterruptException:
pass