Skip to content

Commit

Permalink
Fix Cartesian interpolation (moveit#3652)
Browse files Browse the repository at this point in the history
* Reduce code duplication
* Fix Cartesian interpolation with multiple waypoints continue from latest RobotState
  • Loading branch information
rhaschke authored Oct 6, 2024
1 parent 2e5b70c commit 65e2f9e
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions moveit_core/robot_state/src/cartesian_interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,20 @@ double CartesianInterpolator::computeCartesianPath(
double wp_percentage_solved =
computeCartesianPath(start_state, group, waypoint_traj, link, waypoints[i], global_reference_frame, max_step,
precision, validCallback, options, link_offset);

std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());

if (fabs(wp_percentage_solved - 1.0) < std::numeric_limits<double>::epsilon())
{
percentage_solved = (double)(i + 1) / (double)waypoints.size();
std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());
}
else
{
percentage_solved += wp_percentage_solved / (double)waypoints.size();
std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());
break;
}
start_state = traj.back().get();
}

return percentage_solved;
Expand Down Expand Up @@ -360,21 +357,17 @@ double CartesianInterpolator::computeCartesianPath(
computeCartesianPath(start_state, group, waypoint_traj, link, waypoints[i], global_reference_frame, max_step,
NO_JOINT_SPACE_JUMP_TEST, validCallback, options, link_offset);
#pragma GCC diagnostic pop

std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());

if (fabs(wp_percentage_solved - 1.0) < std::numeric_limits<double>::epsilon())
{
percentage_solved = (double)(i + 1) / (double)waypoints.size();
std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());
}
else
{
percentage_solved += wp_percentage_solved / (double)waypoints.size();
std::vector<RobotStatePtr>::iterator start = waypoint_traj.begin();
if (i > 0 && !waypoint_traj.empty())
std::advance(start, 1);
traj.insert(traj.end(), start, waypoint_traj.end());
break;
}
}
Expand Down

0 comments on commit 65e2f9e

Please sign in to comment.