@@ -22,22 +22,23 @@ def __init__(self):
22
22
# rospy loop rate
23
23
self .sample_rate = rospy .Rate (self .sample_rate_hz )
24
24
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
29
26
js = JointState ()
30
27
js .name = copy .deepcopy (self .joint_names )
31
28
js .position = [0 ]* len (js .name )
32
29
js .velocity = [0 ]* len (js .name )
33
30
js .effort = [0 ]* len (js .name )
34
31
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 )
37
34
38
35
# reset service
39
36
self .service_reset_fjta = rospy .Service ("reset_joint_states" , Trigger , self .reset_cb )
40
37
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 ()
41
42
rospy .loginfo ("Emulation running for action %s of type FollowJointTrajectoryAction" % (action_name ))
42
43
43
44
def reset_cb (self , req ):
@@ -148,18 +149,12 @@ def fjta_cb(self, goal):
148
149
rospy .logerr ("received unexpected joint names in goal" )
149
150
self .as_fjta .set_aborted ()
150
151
151
- def publish_joint_states (self ):
152
+ def publish_joint_states (self , event ):
152
153
msg = copy .deepcopy (self .joint_states )
153
154
msg .header .stamp = rospy .Time .now () # update to current time stamp
154
155
self .pub_joint_states .publish (msg )
155
156
156
157
if __name__ == '__main__' :
157
158
rospy .init_node ('emulation_follow_joint_trajectory' )
158
-
159
159
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