Skip to content

Commit 78da3e4

Browse files
authored
Gracefully handle NULL robot_trajectory (moveit#469)
1 parent 76d2938 commit 78da3e4

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

core/src/stages/move_relative.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -281,35 +281,37 @@ bool MoveRelative::compute(const InterfaceState& state, planning_scene::Planning
281281
success =
282282
planner_->plan(state.scene(), *link, offset, target_eigen, jmg, timeout, robot_trajectory, path_constraints);
283283

284-
robot_state::RobotStatePtr& reached_state = robot_trajectory->getLastWayPointPtr();
285-
reached_state->updateLinkTransforms();
286-
const Eigen::Isometry3d& reached_pose = reached_state->getGlobalLinkTransform(link) * offset;
287-
288-
double distance = 0.0;
289-
if (use_rotation_distance) {
290-
Eigen::AngleAxisd rotation(reached_pose.linear() * ik_pose_world.linear().transpose());
291-
distance = rotation.angle();
292-
} else
293-
distance = (reached_pose.translation() - ik_pose_world.translation()).norm();
294-
295-
// min_distance reached?
296-
if (min_distance > 0.0) {
297-
success = distance >= min_distance;
298-
if (!success) {
299-
char msg[100];
300-
snprintf(msg, sizeof(msg), "min_distance not reached (%.3g < %.3g)", distance, min_distance);
301-
solution.setComment(msg);
284+
if (robot_trajectory) { // the following requires a robot_trajectory returned from planning
285+
robot_state::RobotStatePtr& reached_state = robot_trajectory->getLastWayPointPtr();
286+
reached_state->updateLinkTransforms();
287+
const Eigen::Isometry3d& reached_pose = reached_state->getGlobalLinkTransform(link) * offset;
288+
289+
double distance = 0.0;
290+
if (use_rotation_distance) {
291+
Eigen::AngleAxisd rotation(reached_pose.linear() * ik_pose_world.linear().transpose());
292+
distance = rotation.angle();
293+
} else
294+
distance = (reached_pose.translation() - ik_pose_world.translation()).norm();
295+
296+
// min_distance reached?
297+
if (min_distance > 0.0) {
298+
success = distance >= min_distance;
299+
if (!success) {
300+
char msg[100];
301+
snprintf(msg, sizeof(msg), "min_distance not reached (%.3g < %.3g)", distance, min_distance);
302+
solution.setComment(msg);
303+
}
304+
} else if (min_distance == 0.0) { // if min_distance is zero, we succeed in any case
305+
success = true;
306+
} else if (!success)
307+
solution.setComment("failed to move full distance");
308+
309+
// visualize plan
310+
auto ns = props.get<std::string>("marker_ns");
311+
if (!ns.empty() && linear_norm > 0) { // ensures that 'distance' is the norm of the reached distance
312+
visualizePlan(solution.markers(), dir, success, ns, scene->getPlanningFrame(), ik_pose_world, reached_pose,
313+
linear, distance);
302314
}
303-
} else if (min_distance == 0.0) { // if min_distance is zero, we succeed in any case
304-
success = true;
305-
} else if (!success)
306-
solution.setComment("failed to move full distance");
307-
308-
// visualize plan
309-
auto ns = props.get<std::string>("marker_ns");
310-
if (!ns.empty() && linear_norm > 0) { // ensures that 'distance' is the norm of the reached distance
311-
visualizePlan(solution.markers(), dir, success, ns, scene->getPlanningFrame(), ik_pose_world, reached_pose,
312-
linear, distance);
313315
}
314316
}
315317

0 commit comments

Comments
 (0)