28 #include <console_bridge/console.h>
55 std::set<std::string> fixed_joint_tree_links;
58 std::vector<std::string> links = { input_link };
60 while (!links.empty())
63 const std::string link = links.back();
67 for (
const std::shared_ptr<const tesseract_scene_graph::Joint>& joint : scene_graph.
getInboundJoints(link))
73 links.push_back(joint->parent_link_name);
79 fixed_joint_tree_links.insert(link);
83 fixed_joint_tree_links.insert(children.begin(), children.end());
91 std::vector<std::string> output;
92 output.reserve(fixed_joint_tree_links.size());
93 std::copy(fixed_joint_tree_links.begin(), fixed_joint_tree_links.end(), std::back_inserter(output));
102 : pose(p), working_frame(std::move(wf)), tip_link_name(std::move(tl))
107 std::vector<std::string> joint_names,
108 std::unique_ptr<InverseKinematics> inv_kin,
111 :
JointGroup(std::move(name), joint_names, scene_graph, scene_state)
112 , joint_names_(std::move(joint_names))
113 , inv_kin_(std::move(inv_kin))
115 std::vector<std::string> inv_kin_joint_names =
inv_kin_->getJointNames();
118 throw std::runtime_error(
"KinematicGroup: joint_names is not the correct size");
121 throw std::runtime_error(
"KinematicGroup: joint_names does not match same names in inverse kinematics object!");
130 inv_kin_joint_names.begin(), std::find(inv_kin_joint_names.begin(), inv_kin_joint_names.end(), joint_name)));
133 std::vector<std::string> active_link_names =
state_solver_->getActiveLinkNames();
136 const std::string working_frame =
inv_kin_->getWorkingFrame();
138 throw std::runtime_error(
"Working frame '" + working_frame +
"' is not a link in the scene state");
141 const std::vector<std::string> tip_links =
inv_kin_->getTipLinkNames();
142 for (
const std::string& link : tip_links)
144 throw std::runtime_error(
"Tip link '" + link +
"' is not a link in the scene state");
147 auto it = std::find(active_link_names.begin(), active_link_names.end(), working_frame);
148 if (it == active_link_names.end())
158 const std::vector<std::string> working_frame_fixed_joint_kin_tree_links =
160 for (
const std::string& link : working_frame_fixed_joint_kin_tree_links)
164 throw std::runtime_error(
"Working frame '" + link +
"' is not a link in the scene state");
172 for (
const auto& tip_link : tip_links)
174 const std::vector<std::string> tip_link_fixed_joint_kin_tree_links =
176 for (
const std::string& link : tip_link_fixed_joint_kin_tree_links)
180 throw std::runtime_error(
"Tip link '" + link +
"' is not a link in the scene state");
190 throw std::runtime_error(
"KinematicGroup: Static link names are not correct!");
211 const Eigen::Ref<const Eigen::VectorXd>& seed)
const
215 for (
const auto& tip_link_pose : tip_link_poses)
220 std::stringstream ss;
221 ss <<
"Specified working frame (" << tip_link_pose.working_frame
222 <<
") is not in the list of identified working frames. Available working frames are: [";
226 throw std::runtime_error(ss.str());
232 std::stringstream ss;
233 ss <<
"Failed to find specified tip link (" << tip_link_pose.tip_link_name <<
"). Available tip links are: [";
235 ss << pair.first <<
", ";
237 throw std::runtime_error(ss.str());
241 assert(std::abs(1.0 - tip_link_pose.pose.matrix().determinant()) < 1e-6);
245 std::string working_frame =
inv_kin_->getWorkingFrame();
250 const Eigen::Isometry3d wf_to_user_wf = world_to_wf.inverse() * world_to_user_wf;
255 const Eigen::Isometry3d tl_to_user_tl = world_to_tl.inverse() * world_to_user_tl;
258 const Eigen::Isometry3d& user_wf_to_user_tl = tip_link_pose.pose;
259 const Eigen::Isometry3d wf_to_tl = wf_to_user_wf * user_wf_to_user_tl * tl_to_user_tl.inverse();
261 ik_inputs[ik_solver_tip_link] = wf_to_tl;
267 Eigen::VectorXd ordered_seed = seed;
268 for (Eigen::Index i = 0; i <
inv_kin_->numJoints(); ++i)
273 solutions_filtered.reserve(solutions.size());
274 for (
const auto& solution : solutions)
276 Eigen::VectorXd ordered_sol = solution;
277 for (Eigen::Index i = 0; i <
inv_kin_->numJoints(); ++i)
282 solutions_filtered.push_back(ordered_sol);
285 return solutions_filtered;
290 solutions_filtered.reserve(solutions.size());
291 for (
auto& solution : solutions)
295 solutions_filtered.push_back(solution);
298 return solutions_filtered;
302 const Eigen::Ref<const Eigen::VectorXd>& seed)
const
311 std::vector<std::string> ik_tip_links;
314 ik_tip_links.push_back(pair.first);