21 from moveit_commander
import RobotCommander, MoveItCommanderException
25 """Observes motions of the robot. 27 The implementation is based on using the get_current_joint_values()) functionality of the RobotCommander(). 29 :param group_name: Name of the planning group, default value is 'manipulator' 32 _DEFAULT_WAIT_TIME_FOR_MOTION_DETECTION_SEC = 3.0
33 _DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD = 0.01
34 _DEFAULT_SLEEP_INTERVAL_SEC = 0.01
35 _DEFAULT_GROUP_NAME =
"manipulator" 37 def __init__(self, group_name=_DEFAULT_GROUP_NAME):
42 def _detect_motion(joint_values_a, joint_values_b, tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD):
43 """TRUE if a significant motion was detected, otherwise FALSE.""" 44 return not numpy.allclose(joint_values_a, joint_values_b,
48 """Returns the current joint state values of the robot. 49 :raises RobotCurrentStateError if given planning group does not exist. 52 return self._robot_commander.get_group(self.
_group_name).get_current_joint_values()
53 except MoveItCommanderException
as e:
54 rospy.logerr(e.message)
55 raise RobotCurrentStateError(e.message)
58 sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC,
59 move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD):
60 """TRUE if the robot is currently moving, otherwise FLASE.""" 62 rospy.sleep(sleep_interval)
66 wait_time_out=_DEFAULT_WAIT_TIME_FOR_MOTION_DETECTION_SEC,
67 move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD,
68 sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC):
69 """TRUE if the motion started in the given time interval, otherwise FALSE.""" 72 rospy.loginfo(
"Start joint values: " + str(old_joint_values))
74 motion_started =
False 75 start_time = rospy.get_time()
76 rospy.loginfo(
"Wait until motion starts...")
79 rospy.sleep(sleep_interval)
82 if RobotMotionObserver._detect_motion(curr_joint_values, old_joint_values, move_tolerance):
84 rospy.loginfo(
"Changed joint values detected: " + str(curr_joint_values))
85 rospy.loginfo(
"Motion started.")
88 if (rospy.get_time() - start_time > wait_time_out):
89 rospy.loginfo(
"Reached timeout when waiting for motion start.")
95 wait_time_out=_DEFAULT_WAIT_TIME_FOR_MOTION_DETECTION_SEC,
96 move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD,
97 sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC):
98 """TRUE if the motion stopped in the given time interval, otherwise FALSE.""" 100 motion_stopped =
False 101 start_time = rospy.get_time()
102 rospy.loginfo(
"Wait until motion stops...")
107 motion_stopped =
True 108 rospy.loginfo(
"Motion stopped.")
111 if (rospy.get_time() - start_time > wait_time_out):
112 rospy.loginfo(
"Reached timeout when waiting for motion stop.")
115 return motion_stopped
def wait_motion_start(self, wait_time_out=_DEFAULT_WAIT_TIME_FOR_MOTION_DETECTION_SEC, move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD, sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC)
def _get_current_joint_states(self)
def wait_motion_stop(self, wait_time_out=_DEFAULT_WAIT_TIME_FOR_MOTION_DETECTION_SEC, move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD, sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC)
def _detect_motion(joint_values_a, joint_values_b, tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD)
def __init__(self, group_name=_DEFAULT_GROUP_NAME)
def is_robot_moving(self, sleep_interval=_DEFAULT_SLEEP_INTERVAL_SEC, move_tolerance=_DEFAULT_TOLERANCE_FOR_MOTION_DETECTION_RAD)