5 import moveit_commander
6 from geometry_msgs.msg
import Pose, PoseStamped
7 from tf.transformations
import quaternion_from_euler
8 from crane_x7_examples.srv
import ObstacleAvoidance, ObstacleAvoidanceResponse
17 server.shutdown(
'rospy shutdown')
21 arm = moveit_commander.MoveGroupCommander(
"arm")
22 arm.set_max_velocity_scaling_factor(0.1)
23 arm.set_max_acceleration_scaling_factor(1.0)
24 arm.set_named_target(
"vertical")
31 arm = moveit_commander.MoveGroupCommander(
"arm")
32 arm.set_max_velocity_scaling_factor(0.1)
33 arm.set_max_acceleration_scaling_factor(1.0)
34 scene = moveit_commander.PlanningSceneInterface()
35 rospy.sleep(SLEEP_TIME)
38 scene.remove_world_object()
39 rospy.sleep(SLEEP_TIME)
43 floor_size = (2.0, 2.0, 0.01)
44 floor_pose = PoseStamped()
45 floor_pose.header.frame_id =
"/base_link" 46 floor_pose.pose.position.z = -floor_size[2]/2.0
47 scene.add_box(floor_name, floor_pose, floor_size)
48 rospy.sleep(SLEEP_TIME)
51 if req.obstacle_enable:
52 scene.add_box(req.obstacle_name, req.obstacle_pose_stamped,
53 (req.obstacle_size.x, req.obstacle_size.y, req.obstacle_size.z))
54 rospy.sleep(SLEEP_TIME)
58 arm.set_named_target(
'home')
63 arm.set_pose_target(req.start_pose)
68 arm.set_pose_target(req.goal_pose)
73 arm.set_named_target(
'home')
78 scene.remove_world_object()
79 rospy.sleep(SLEEP_TIME)
81 return ObstacleAvoidanceResponse(result)
87 rospy.init_node(
"obstacle_avoidance_example")
88 rospy.on_shutdown(hook_shutdown)
90 server = rospy.Service(
'~obstacle_avoidance', ObstacleAvoidance, callback)
91 print(
'Ready to avoid obstacles')
96 if __name__ ==
'__main__':
98 if not rospy.is_shutdown():
100 except rospy.ROSInterruptException: