11import numpy as np
22import rospy
3+ import time
4+ from collections import deque
35
46from std_msgs .msg import Float64 , Empty
57from trac_ik_python .trac_ik import IK
@@ -18,6 +20,8 @@ def __init__(self):
1820 rospy .Subscriber ('/joint_states' , JointState , self .get_joint_state )
1921 self .tf_listener = tf .TransformListener ()
2022
23+ self .history = {'timestamp' : deque (),
24+ 'joint_feedback' : deque ()}
2125 # global variables
2226 self .current_joint_state = None
2327 self .current_gripper_state = None
@@ -56,6 +60,19 @@ def set_arm_joint_angles(self, joint_target):
5660 self .arm_pub .publish (joint_state )
5761
5862 def get_joint_state (self , data ):
63+ # TODO: Change this when required
64+ moveable_joints = [1 ,2 ,3 ]
65+ # Add timestamp
66+ self .history ['timestamp' ].append (time .time ())
67+ if (len (self .history ['timestamp' ]) > 20 ):
68+ self .history ['timestamp' ].popleft ()
69+
70+ # Add Joint Feedback
71+ joint_angles = np .array (data .position )[moveable_joints ]
72+ self .history ['joint_feedback' ].append (joint_angles )
73+ if (len (self .history ['joint_feedback' ]) > 20 ):
74+ self .history ['joint_feedback' ].popleft ()
75+
5976 self .current_joint_state = data .position [0 :5 ]
6077 self .current_gripper_state = data .position [7 :9 ]
6178
0 commit comments