18 from moveit_commander
import RobotCommander
19 from moveit_commander
import PlanningSceneInterface
20 from moveit_commander
import MoveGroupCommander
21 from moveit_msgs.srv
import ListRobotStatesInWarehouse
as ListStates
22 from moveit_msgs.srv
import GetRobotStateFromWarehouse
as GetState
23 from moveit_msgs.srv
import CheckIfRobotStateExistsInWarehouse
as HasState
24 from moveit_msgs.srv
import GetPositionFK
25 from sr_robot_msgs.srv
import PlanTrajectoryFromList
26 from sr_robot_msgs.srv
import PlanTrajectoryFromPrefix
27 from sr_robot_msgs.srv
import ExecutePlannedTrajectory
29 from std_msgs.msg
import Header
30 import geometry_msgs.msg
35 rospy.init_node(
'moveit_warehouse_planner', anonymous=
True)
36 self.
scene = PlanningSceneInterface()
40 group_id = rospy.get_param(
"~arm_group_name")
41 self.
eef_step = rospy.get_param(
"~eef_step", 0.01)
44 self.
group = MoveGroupCommander(group_id)
53 rospy.loginfo(
"Waiting for warehouse services...")
54 rospy.wait_for_service(
'/list_robot_states')
55 rospy.wait_for_service(
'/get_robot_state')
56 rospy.wait_for_service(
'/has_robot_state')
58 rospy.wait_for_service(
'/compute_fk')
60 '/list_robot_states', ListStates)
62 '/get_robot_state', GetState)
64 '/has_robot_state', HasState)
66 'compute_fk', GetPositionFK)
67 rospy.loginfo(
"Service proxies connected")
70 PlanTrajectoryFromList,
74 PlanTrajectoryFromPrefix,
78 ExecutePlannedTrajectory,
84 regex =
"^" + str(prefix) +
".*" 92 response = self.
_forward_k(header, fk_link_names, state)
93 return response.pose_stamped[0].pose
97 waypoints.append(self.group.get_current_pose().pose)
98 for name
in waypoint_names:
103 rospy.logerr(
"Waypoint %s doesn't exist for robot %s.", name,
108 p = geometry_msgs.msg.PoseStamped()
109 p.header.frame_id = self.robot.get_planning_frame()
111 p.pose.position.x = 0
112 p.pose.position.y = 0
114 p.pose.position.z = -0.11
115 p.pose.orientation.x = 0
116 p.pose.orientation.y = 0
117 p.pose.orientation.z = 0
118 p.pose.orientation.w = 1
119 self.scene.add_box(
"ground", p, (3, 3, 0.01))
124 waypoint_names.sort()
126 if 0 == len(waypoint_names):
127 rospy.logerr(
"No waypoints found for robot %s with prefix %s. " +
128 "Can't make trajectory :(",
131 rospy.loginfo(
"Creating trajectory with %d waypoints selected by " +
132 "prefix %s.", len(waypoint_names), str(prefix))
136 self.group.clear_pose_targets()
138 if len(waypoints) != len(waypoint_names) + 1:
140 rospy.logerr(
"Not all waypoints existed, not executing.")
142 (plan, fraction) = self.group.compute_cartesian_path(
146 rospy.logerr(
"Only managed to generate trajectory through" +
147 "%f of waypoints. Not executing", fraction)
156 rospy.loginfo(
"Creating trajectory from points given: %s",
157 ",".join(request.waypoint_names))
162 rospy.loginfo(
"Creating trajectory from points filtered by prefix %s",
168 rospy.logerr(
"No plan stored!")
170 rospy.loginfo(
"Executing stored plan")
171 response = self.group.execute(self.
__plan)
175 if __name__ ==
"__main__":
def get_pose_from_state(self, state)
def _plan_from_prefix_cb(self, request)
def get_cartesian_waypoints(self, waypoint_names)
def plan_from_filter(self, prefix)
def _plan_from_list_cb(self, request)
def get_waypoint_names_by_prefix(self, prefix)
def plan_from_list(self, waypoint_names)
def _execute_plan_cb(self, request)