16 from geometry_msgs.msg
import PoseStamped
20 from rclpy.duration
import Duration
25 'shelf_A': [-3.829, -7.604],
26 'shelf_B': [-3.791, -3.287],
27 'shelf_C': [-3.791, 1.254],
28 'shelf_D': [-3.24, 5.861]}
31 shipping_destinations = {
32 'recycling': [-0.205, 7.403],
33 'pallet_jack7': [-0.073, -8.497],
34 'conveyer_432': [6.217, 2.153],
35 'frieght_bay_3': [-6.349, 9.147]}
38 Basic item picking demo. In this demonstration, the expectation
39 is that there is a person at the item shelf to put the item on the robot
40 and at the pallet jack to remove it
41 (probably with some kind of button for 'got item, robot go do next task').
50 request_item_location =
'shelf_C'
51 request_destination =
'pallet_jack7'
56 navigator = BasicNavigator()
59 initial_pose = PoseStamped()
60 initial_pose.header.frame_id =
'map'
61 initial_pose.header.stamp = navigator.get_clock().now().to_msg()
62 initial_pose.pose.position.x = 3.45
63 initial_pose.pose.position.y = 2.15
64 initial_pose.pose.orientation.z = 1.0
65 initial_pose.pose.orientation.w = 0.0
66 navigator.setInitialPose(initial_pose)
69 navigator.waitUntilNav2Active()
71 shelf_item_pose = PoseStamped()
72 shelf_item_pose.header.frame_id =
'map'
73 shelf_item_pose.header.stamp = navigator.get_clock().now().to_msg()
74 shelf_item_pose.pose.position.x = shelf_positions[request_item_location][0]
75 shelf_item_pose.pose.position.y = shelf_positions[request_item_location][1]
76 shelf_item_pose.pose.orientation.z = 1.0
77 shelf_item_pose.pose.orientation.w = 0.0
78 print(f
'Received request for item picking at {request_item_location}.')
79 navigator.goToPose(shelf_item_pose)
85 while not navigator.isTaskComplete():
87 feedback = navigator.getFeedback()
88 if feedback
and i % 5 == 0:
89 print(
'Estimated time of arrival at ' + request_item_location +
90 ' for worker: ' +
'{0:.0f}'.format(
91 Duration.from_msg(feedback.estimated_time_remaining).nanoseconds / 1e9)
94 result = navigator.getResult()
95 if result == TaskResult.SUCCEEDED:
96 print(
'Got product from ' + request_item_location +
97 '! Bringing product to shipping destination (' + request_destination +
')...')
98 shipping_destination = PoseStamped()
99 shipping_destination.header.frame_id =
'map'
100 shipping_destination.header.stamp = navigator.get_clock().now().to_msg()
101 shipping_destination.pose.position.x = shipping_destinations[request_destination][0]
102 shipping_destination.pose.position.y = shipping_destinations[request_destination][1]
103 shipping_destination.pose.orientation.z = 1.0
104 shipping_destination.pose.orientation.w = 0.0
105 navigator.goToPose(shipping_destination)
107 elif result == TaskResult.CANCELED:
108 print(f
'Task at {request_item_location} was canceled. Returning to staging point...')
109 initial_pose.header.stamp = navigator.get_clock().now().to_msg()
110 navigator.goToPose(initial_pose)
112 elif result == TaskResult.FAILED:
113 print(f
'Task at {request_item_location} failed!')
116 while not navigator.isTaskComplete():
122 if __name__ ==
'__main__':