Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add approximate solution joint jump threshold parameter #42

Merged
merged 3 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ auto make_frame_test_fn(Eigen::Isometry3d goal_frame,
auto const q_goal = Eigen::Quaterniond(goal_frame.rotation());
auto const q_frame = Eigen::Quaterniond(tip_frame.rotation());
auto const angular_distance = q_frame.angularDistance(q_goal);
return ((goal_frame.translation() - tip_frame.translation()).norm() <=
position_threshold) &&
auto const linear_distance = (goal_frame.translation() - tip_frame.translation()).norm();
return (linear_distance <= position_threshold) &&
(!orientation_threshold.has_value() ||
std::abs(angular_distance) <= orientation_threshold.value());
};
Expand Down
8 changes: 8 additions & 0 deletions src/pick_ik_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ pick_ik:
gt_eq<>: [0.0],
},
}
approximate_solution_joint_threshold: {
type: double,
default_value: 0.0,
description: "Joint threshold for approximate IK solutions, in radians. If displacement is larger than this, the approximate solution will fall back to the initial guess",
validation: {
lower_bounds<>: [0.0],
},
}
cost_threshold: {
type: double,
default_value: 0.001,
Expand Down
21 changes: 17 additions & 4 deletions src/pick_ik_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ class PickIKPlugin : public kinematics::KinematicsBase {
solution = ik_seed_state;
}

// If using an approximate solution, check against the maximum allowable pose threshold.
// If the approximate solution is too far from the goal frame, fall back to the initial
// state.
// If using an approximate solution, check against the maximum allowable pose and joint
// thresholds. If the approximate solution is too far from the goal frame,
// fall back to the initial state.
if (options.return_approximate_solution) {
// Check pose thresholds
std::optional<double> approximate_solution_orientation_threshold = std::nullopt;
if (test_rotation) {
approximate_solution_orientation_threshold =
Expand All @@ -230,6 +231,18 @@ class PickIKPlugin : public kinematics::KinematicsBase {
break;
}
}

// Check joint thresholds
if (approx_solution_valid && params.approximate_solution_joint_threshold > 0.0) {
for (size_t i = 0; i < solution.size(); ++i) {
if (std::abs(solution[i] - ik_seed_state[i]) >
params.approximate_solution_joint_threshold) {
approx_solution_valid = false;
break;
}
}
}

if (!approx_solution_valid) {
error_code.val = error_code.NO_IK_SOLUTION;
solution = ik_seed_state;
Expand All @@ -242,7 +255,7 @@ class PickIKPlugin : public kinematics::KinematicsBase {
solution_callback(ik_poses.front(), solution, error_code);
}

return error_code.val == error_code.SUCCESS;
return found_solution;
}

virtual std::vector<std::string> const& getJointNames() const { return joint_names_; }
Expand Down
1 change: 0 additions & 1 deletion src/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ auto Robot::from(std::shared_ptr<moveit::core::RobotModel const> const& model,
std::vector<size_t> tip_link_indices) -> Robot {
auto robot = Robot{};

// jmg_->getKinematicsSolverJointBijection();
auto const active_variable_indices = get_active_variable_indices(model, jmg, tip_link_indices);
auto const variable_count = active_variable_indices.size();

Expand Down
Loading