sr_right_evaluate_plan_quality.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # Copyright 2020 Shadow Robot Company Ltd.
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation version 2 of the License.
7 #
8 # This program is distributed in the hope that it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 # more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program. If not, see <http://www.gnu.org/licenses/>.
15 #
16 # This example demonstrates some the function of the robot commander for evaluating plan quality.
17 # https://github.com/shadow-robot/sr_interface/blob/melodic-devel/sr_robot_commander/src/sr_robot_commander/sr_robot_commander.py#L263-L310
18 #
19 # For more information, please see:
20 # https://dexterous-hand.readthedocs.io/en/latest/user_guide/2_software_description.html#robot-commander
21 #
22 # roslaunch commands used with this script to launch the robot:
23 # real robot with a NUC (or a separate computer with an RT kernel):
24 # roslaunch sr_robot_launch sr_right_ur10arm_hand.launch
25 # external_control_loop:=true sim:=false scene:=true
26 # simulated robot:
27 # roslaunch sr_robot_launch sr_right_ur10arm_hand.launch sim:=true scene:=true
28 #
29 # It is recommended to run this script in simulation first.
30 
31 import rospy
32 import sys
33 from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint
34 from sr_robot_commander.sr_robot_commander import SrRobotCommander
35 
36 rospy.init_node("right_hand_manipulator_plan_quality", anonymous=True)
37 
38 robot_commander = SrRobotCommander(name="right_arm_and_manipulator")
39 robot_commander.set_max_velocity_scaling_factor(0.4)
40 
41 rospy.sleep(2.0)
42 
43 arm_manipulator_home_joints_goal = {'ra_shoulder_pan_joint': 0.00, 'ra_elbow_joint': 2.00,
44  'ra_shoulder_lift_joint': -1.25, 'ra_wrist_1_joint': -0.733,
45  'ra_wrist_2_joint': 1.5708, 'ra_wrist_3_joint': 0.00,
46  'rh_WRJ1': 0.0, 'rh_WRJ2': 0.0}
47 
48 example_goal_1 = [1.18773740212, 0.175152574887,
49  1.00722873872, -0.509149713327,
50  0.504302807033, -0.490693581737,
51  0.49564610064]
52 
53 example_goal_2 = [1.03497881882, 0.174190990124,
54  1.00916719803, -0.510952874905,
55  0.510169511476, -0.4888330603,
56  0.489588059847]
57 
58 example_goal_3 = [1.18972252888, 0.174200052352,
59  1.12320616864, -0.516434824527,
60  0.516354718344, -0.483015844727,
61  0.483082364202]
62 
63 # Evaluate the plan quality from starting position of robot.
64 # https://github.com/shadow-robot/sr_interface/blob/melodic-devel/sr_robot_commander/src/sr_robot_commander/sr_robot_commander.py#L263-L310
65 # This is to confirm that the arm is in a safe place to move to the home joints goal,
66 # if the outcome is poor please refer to the readthedocs of where the start arm home position is.
67 rospy.loginfo("Planning to move arm and manipulator to joint states\n" + str(arm_manipulator_home_joints_goal) + "\n")
68 plan = robot_commander.plan_to_joint_value_target(arm_manipulator_home_joints_goal)
69 plan_quality = robot_commander.evaluate_given_plan(plan)
70 eval_plan_quality = robot_commander.evaluate_plan_quality(plan_quality)
71 
72 if eval_plan_quality != 'good':
73  rospy.logfatal("Plan quality to the home position is poor! " +
74  "For safety please refer to the hand and arm documentation " +
75  "for where to start the arm " +
76  "to ensure no unexpected movements during plan and execute.")
77  sys.exit("Exiting script to allow for the arm to be manually moved to better start position ...")
78 
79 raw_input("Press Enter to execute plan...")
80 robot_commander.execute_plan(plan)
81 
82 rospy.loginfo("Planning the move to the first pose:\n" + str(example_goal_1) + "\n")
83 plan2 = robot_commander.plan_to_pose_target(example_goal_1)
84 plan_quality = robot_commander.evaluate_given_plan(plan2)
85 eval_plan_quality = robot_commander.evaluate_plan_quality(plan_quality)
86 
87 raw_input("Press Enter to execute plan...")
88 robot_commander.execute_plan(plan2)
89 rospy.sleep(2.0)
90 
91 rospy.loginfo("Planning the move to the second pose:\n" + str(example_goal_1) + "\n")
92 plan3 = robot_commander.plan_to_pose_target(example_goal_2)
93 plan_quality = robot_commander.evaluate_given_plan(plan3)
94 eval_plan_quality = robot_commander.evaluate_plan_quality(plan_quality)
95 
96 raw_input("Press Enter to execute plan...")
97 robot_commander.execute_plan(plan3)
98 rospy.sleep(2.0)
99 
100 rospy.loginfo("Planning the move to the third pose:\n" + str(example_goal_1) + "\n")
101 plan4 = robot_commander.plan_to_pose_target(example_goal_3)
102 plan_quality = robot_commander.evaluate_given_plan(plan4)
103 eval_plan_quality = robot_commander.evaluate_plan_quality(plan_quality)
104 
105 raw_input("Press Enter to execute plan...")
106 robot_commander.execute_plan(plan4)
107 rospy.sleep(2.0)


sr_example
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:10