3333import math
3434import operator
3535import numpy as np
36+ from multiprocessing import Lock
3637
3738import bezier
3839
@@ -69,6 +70,7 @@ def __init__(self, limb, reconfig_server, rate=100.0,
6970 FollowJointTrajectoryAction ,
7071 execute_cb = self ._on_trajectory_action ,
7172 auto_start = False )
73+ self ._mutex = Lock ()
7274 self ._command = rospy .Subscriber (self ._ns + '/joint_trajectory/command' , JointTrajectory , self ._on_joint_trajectory )
7375 self ._action_name = rospy .get_name ()
7476 self ._limb = baxter_interface .Limb (limb )
@@ -417,6 +419,7 @@ def _on_trajectory_action(self, goal):
417419 while (now_from_start < end_time and not rospy .is_shutdown () and
418420 self .robot_is_enabled ()):
419421 #Acquire Mutex
422+ self ._mutex .acquire ()
420423 now = rospy .get_time ()
421424 now_from_start = now - start_time
422425 idx = bisect .bisect (pnt_times , now_from_start )
@@ -439,6 +442,7 @@ def _on_trajectory_action(self, goal):
439442 command_executed = self ._command_joints (joint_names , point , start_time , dimensions_dict )
440443 self ._update_feedback (deepcopy (point ), joint_names , now_from_start )
441444 # Release the Mutex
445+ self ._mutex .release ()
442446 if not command_executed :
443447 return
444448 control_rate .sleep ()
@@ -575,6 +579,9 @@ def _on_joint_trajectory(self, trajectory):
575579 while (now_from_start < end_time and not rospy .is_shutdown ()):
576580 idx = bisect .bisect (pnt_times , now_from_start )
577581
582+ #Acquire Mutex
583+ self ._mutex .acquire ()
584+
578585 if idx == 0 :
579586 # If our current time is before the first specified point
580587 # in the trajectory, then we should interpolate between
@@ -599,6 +606,8 @@ def _on_joint_trajectory(self, trajectory):
599606 if not self ._command_joints (joint_names , point ):
600607 return
601608
609+ # Release the Mutex
610+ self ._mutex .release ()
602611 control_rate .sleep ()
603612 now_from_start = rospy .get_time () - start_time
604613 last_idx = idx
0 commit comments