How to store two data of consecutive frames for computation?
I am using ROS Kinetic on ubuntu 16.04.
The application I am trying to do is to obtain messages from the VRPN optitrack system and use these data to
construct a data array that displays variables in sync.
For example, the optitrack system reads in position and attitude data. The language I am using is python and I will write two subscribers, one is to subscribe to the position topic while the other on the attitude topic on the ros vrpn client. The read data are saved in variables for computation.
I will define three functions, one will return a rotational matrix, the other will return the linear velocity calculated from consecutive frame of position data, and the other function will calculate angular velocity from consecutive frame of attitude data.
The three functions will return a [1x9] rotational matrix representation [1x3] linear velocity representation and [1x3] angular velocity representation.
I will then append these numpy arrays in to an [1x18] array for display as follows: [ 1x9 rot matrix array 1x3 position data 1x3 linear velocity 1x3 angular velocity]
One question is how can I make sure the data are printed in sync? I understand the position data gets updated at the highest frequency and I only needed to queue two messages each time for processing. as the two messages would be the first frame followed by the second frame. The position data in the final display would be the one in the second frame. This could be a silly question because simply the script just needed to take whatever processing time and the variables given to compute results. And syncing this should not be a problem.
My main question in this case is how can I write code to store data from consecutive messages, basically consecutive frames? The following is my example code for calculating linear velocity from two position data of consecutive frames.
import transforms3d.euler as eul
import rospy
def ReturnLinearVelocity(previous, current, frequency):
linearVel =(current - previous)*frequency
return linearVel
def Callback(data):
previous = data
current = data
ReturnLinearVelocity(previous, current, frequency)
rospy.init_node('rq3_proxy')
while not rospy.is_shutdown():
rospy.Subscriber("ros_vrpn_client topic", positiongeometry, Callback)
rospy.sleep(1)
rospy.spin()