collision_aware_cart_control.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2017, Svenzva Robotics
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of SRI International nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 
36 import sys
37 import copy
38 import rospy
39 import moveit_commander
40 import moveit_msgs.msg
41 import geometry_msgs.msg
42 import tf
43 
45  moveit_commander.roscpp_initialize(sys.argv)
46  global joy_cmd
47  ## Instantiate a RobotCommander object. This object is an interface to
48  ## the robot as a whole.
49  robot = moveit_commander.RobotCommander()
50 
51  scene = moveit_commander.PlanningSceneInterface()
52 
53  group = moveit_commander.MoveGroupCommander("svenzva_arm")
54 
55  display_trajectory_publisher = rospy.Publisher(
56  '/move_group/display_planned_path',
57  moveit_msgs.msg.DisplayTrajectory,
58  queue_size=20)
59 
60  while not rospy.is_shutdown():
61  if joy_cmd != geometry_msgs.msg.Twist():
62  cur_pose = group.get_current_pose();
63  quaternion = cur_pose.pose.orientation
64  explicit_quat = [quaternion.x, quaternion.y, quaternion.z, quaternion.w]
65  euler = tf.transformations.euler_from_quaternion(explicit_quat)
66  new_euler = [euler[0] + joy_cmd.angular.x, euler[1] + joy_cmd.angular.y, euler[2] + joy_cmd.angular.z]
67 
68  quat = tf.transformations.quaternion_from_euler(new_euler[0], new_euler[1], new_euler[2])
69  pose_target = geometry_msgs.msg.Pose()
70  pose_target.orientation.x = quat[0]
71  pose_target.orientation.y = quat[1]
72  pose_target.orientation.z = quat[2]
73  pose_target.orientation.w = quat[3]
74  pose_target.position.x = cur_pose.pose.position.x + joy_cmd.linear.x
75  pose_target.position.y = cur_pose.pose.position.y + joy_cmd.linear.y
76  pose_target.position.z = cur_pose.pose.position.z + joy_cmd.linear.z
77  group.set_pose_target(pose_target)
78 
79  #display_trajectory = moveit_msgs.msg.DisplayTrajectory()
80  #display_trajectory.trajectory_start = robot.get_current_state()
81  #display_trajectory.trajectory.append(plan1)
82  #display_trajectory_publisher.publish(display_trajectory);
83 
84  group.go(wait=False)
85  rospy.sleep(0.1)
86 
87  """
88  ## Cartesian Paths
89  ## ^^^^^^^^^^^^^^^
90  ## You can plan a cartesian path directly by specifying a list of waypoints
91  ## for the end-effector to go through.
92  waypoints = []
93 
94  # start with the current pose
95  waypoints.append(group.get_current_pose().pose)
96 
97  # first orient gripper and move forward (+x)
98  wpose = geometry_msgs.msg.Pose()
99  wpose.orientation.w = 1.0
100  wpose.position.x = waypoints[0].position.x + 0.1
101  wpose.position.y = waypoints[0].position.y
102  wpose.position.z = waypoints[0].position.z
103  waypoints.append(copy.deepcopy(wpose))
104 
105  # second move down
106  wpose.position.z -= 0.10
107  waypoints.append(copy.deepcopy(wpose))
108 
109  # third move to the side
110  wpose.position.y += 0.05
111  waypoints.append(copy.deepcopy(wpose))
112 
113  ## We want the cartesian path to be interpolated at a resolution of 1 cm
114  ## which is why we will specify 0.01 as the eef_step in cartesian
115  ## translation. We will specify the jump threshold as 0.0, effectively
116  ## disabling it.
117  (plan3, fraction) = group.compute_cartesian_path(
118  waypoints, # waypoints to follow
119  0.01, # eef_step
120  0.0) # jump_threshold
121 
122  # Uncomment the line below to execute this plan on a real robot.
123  # group.execute(plan3)
124  """
125 
126  ## When finished shut down moveit_commander.
127  moveit_commander.roscpp_shutdown()
128 
129 def joy_callback(data):
130  global joy_cmd
131  joy_cmd = data
132 
133 if __name__=='__main__':
134  global joy_cmd
135  joy_cmd = geometry_msgs.msg.Twist()
136  rospy.init_node('collision_aware_cartesian_control', anonymous=True)
137 
138  try:
139  rospy.Subscriber("/revel/eef_velocity", geometry_msgs.msg.Twist, joy_callback, queue_size=1)
141  except rospy.ROSInterruptException:
142  pass
143 
144 


svenzva_drivers
Author(s): Max Svetlik
autogenerated on Wed Oct 28 2020 03:31:27