Skip to content

Commit adc3236

Browse files
committed
use timer for joint_states
1 parent 9cdc4ff commit adc3236

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

cob_hardware_emulation/scripts/emulation_follow_joint_trajectory.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,23 @@ def __init__(self):
2222
# rospy loop rate
2323
self.sample_rate = rospy.Rate(self.sample_rate_hz)
2424

25-
action_name = "joint_trajectory_controller/follow_joint_trajectory"
26-
27-
self.as_fjta = actionlib.SimpleActionServer(action_name, FollowJointTrajectoryAction, execute_cb=self.fjta_cb, auto_start = False)
28-
self.pub_joint_states = rospy.Publisher("joint_states", JointState, queue_size=1)
25+
# joint_states publisher
2926
js = JointState()
3027
js.name = copy.deepcopy(self.joint_names)
3128
js.position = [0]*len(js.name)
3229
js.velocity = [0]*len(js.name)
3330
js.effort = [0]*len(js.name)
3431
self.joint_states = js
35-
36-
self.as_fjta.start()
32+
self.pub_joint_states = rospy.Publisher("joint_states", JointState, queue_size=1)
33+
self.js_timer = rospy.Timer(rospy.Duration(self.sample_rate_dur_secs), self.publish_joint_states)
3734

3835
# reset service
3936
self.service_reset_fjta = rospy.Service("reset_joint_states", Trigger, self.reset_cb)
4037

38+
# follow_joint_trajectory action
39+
action_name = "joint_trajectory_controller/follow_joint_trajectory"
40+
self.as_fjta = actionlib.SimpleActionServer(action_name, FollowJointTrajectoryAction, execute_cb=self.fjta_cb, auto_start = False)
41+
self.as_fjta.start()
4142
rospy.loginfo("Emulation running for action %s of type FollowJointTrajectoryAction"%(action_name))
4243

4344
def reset_cb(self, req):
@@ -148,18 +149,12 @@ def fjta_cb(self, goal):
148149
rospy.logerr("received unexpected joint names in goal")
149150
self.as_fjta.set_aborted()
150151

151-
def publish_joint_states(self):
152+
def publish_joint_states(self, event):
152153
msg = copy.deepcopy(self.joint_states)
153154
msg.header.stamp = rospy.Time.now() # update to current time stamp
154155
self.pub_joint_states.publish(msg)
155156

156157
if __name__ == '__main__':
157158
rospy.init_node('emulation_follow_joint_trajectory')
158-
159159
emulation_follow_joint_trajectory = EmulationFollowJointTrajectory()
160-
161-
# updating the joint states: 10Hz
162-
joint_states_pub_rate = rospy.Rate(10)
163-
while not rospy.is_shutdown():
164-
emulation_follow_joint_trajectory.publish_joint_states()
165-
joint_states_pub_rate.sleep()
160+
rospy.spin()

0 commit comments

Comments
 (0)