33
33
import math
34
34
import operator
35
35
import numpy as np
36
+ from multiprocessing import Lock
36
37
37
38
import bezier
38
39
@@ -69,6 +70,7 @@ def __init__(self, limb, reconfig_server, rate=100.0,
69
70
FollowJointTrajectoryAction ,
70
71
execute_cb = self ._on_trajectory_action ,
71
72
auto_start = False )
73
+ self ._mutex = Lock ()
72
74
self ._command = rospy .Subscriber (self ._ns + '/joint_trajectory/command' , JointTrajectory , self ._on_joint_trajectory )
73
75
self ._action_name = rospy .get_name ()
74
76
self ._limb = baxter_interface .Limb (limb )
@@ -417,6 +419,7 @@ def _on_trajectory_action(self, goal):
417
419
while (now_from_start < end_time and not rospy .is_shutdown () and
418
420
self .robot_is_enabled ()):
419
421
#Acquire Mutex
422
+ self ._mutex .acquire ()
420
423
now = rospy .get_time ()
421
424
now_from_start = now - start_time
422
425
idx = bisect .bisect (pnt_times , now_from_start )
@@ -439,6 +442,7 @@ def _on_trajectory_action(self, goal):
439
442
command_executed = self ._command_joints (joint_names , point , start_time , dimensions_dict )
440
443
self ._update_feedback (deepcopy (point ), joint_names , now_from_start )
441
444
# Release the Mutex
445
+ self ._mutex .release ()
442
446
if not command_executed :
443
447
return
444
448
control_rate .sleep ()
@@ -575,6 +579,9 @@ def _on_joint_trajectory(self, trajectory):
575
579
while (now_from_start < end_time and not rospy .is_shutdown ()):
576
580
idx = bisect .bisect (pnt_times , now_from_start )
577
581
582
+ #Acquire Mutex
583
+ self ._mutex .acquire ()
584
+
578
585
if idx == 0 :
579
586
# If our current time is before the first specified point
580
587
# in the trajectory, then we should interpolate between
@@ -599,6 +606,8 @@ def _on_joint_trajectory(self, trajectory):
599
606
if not self ._command_joints (joint_names , point ):
600
607
return
601
608
609
+ # Release the Mutex
610
+ self ._mutex .release ()
602
611
control_rate .sleep ()
603
612
now_from_start = rospy .get_time () - start_time
604
613
last_idx = idx
0 commit comments