Skip to content

Commit 2b21619

Browse files
committed
AIRO-392 Fixing list index exception when planner fails
When the MoveIt trajectory planner fails to find a valid path, it returns an empty list of path points. Our mover.py script assumes there is always something in the list, so we get an exception when there is not (which breaks our listener node and mandates a re-launch). Added out of bounds checks and moved the response population to the bottom to ensure we only send a path back when it is complete, and otherwise send an empty response (for which the srv will print an adequate error to console). Tested by running DemoScene with out of bounds locations for target placement.
1 parent 1efc796 commit 2b21619

File tree

1 file changed

+18
-5
lines changed
  • tutorials/pick_and_place/ROS/src/niryo_moveit/scripts

1 file changed

+18
-5
lines changed

tutorials/pick_and_place/ROS/src/niryo_moveit/scripts/mover.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,41 @@ def plan_pick_and_place(req):
8787

8888
# Pre grasp - position gripper directly above target object
8989
pre_grasp_pose = plan_trajectory(move_group, req.pick_pose, current_robot_joint_configuration)
90+
91+
# If the trajectory has no points, planning has failed and we return an empty response
92+
if not pre_grasp_pose.joint_trajectory.points:
93+
return response
9094

9195
previous_ending_joint_angles = pre_grasp_pose.joint_trajectory.points[-1].positions
92-
response.trajectories.append(pre_grasp_pose)
9396

9497
# Grasp - lower gripper so that fingers are on either side of object
9598
pick_pose = copy.deepcopy(req.pick_pose)
9699
pick_pose.position.z -= 0.05 # Static value coming from Unity, TODO: pass along with request
97100
grasp_pose = plan_trajectory(move_group, pick_pose, previous_ending_joint_angles)
101+
102+
if not grasp_pose.joint_trajectory.points:
103+
return response
98104

99105
previous_ending_joint_angles = grasp_pose.joint_trajectory.points[-1].positions
100-
response.trajectories.append(grasp_pose)
101106

102107
# Pick Up - raise gripper back to the pre grasp position
103108
pick_up_pose = plan_trajectory(move_group, req.pick_pose, previous_ending_joint_angles)
109+
110+
if not pick_up_pose.joint_trajectory.points:
111+
return response
104112

105113
previous_ending_joint_angles = pick_up_pose.joint_trajectory.points[-1].positions
106-
response.trajectories.append(pick_up_pose)
107114

108115
# Place - move gripper to desired placement position
109116
place_pose = plan_trajectory(move_group, req.place_pose, previous_ending_joint_angles)
110117

111-
previous_ending_joint_angles = place_pose.joint_trajectory.points[-1].positions
118+
if not place_pose.joint_trajectory.points:
119+
return response
120+
121+
# If trajectory planning worked for all pick and place stages, add plan to response
122+
response.trajectories.append(pre_grasp_pose)
123+
response.trajectories.append(grasp_pose)
124+
response.trajectories.append(pick_up_pose)
112125
response.trajectories.append(place_pose)
113126

114127
move_group.clear_pose_targets()
@@ -126,4 +139,4 @@ def moveit_server():
126139

127140

128141
if __name__ == "__main__":
129-
moveit_server()
142+
moveit_server()

0 commit comments

Comments
 (0)