ikfast_factory_boilerplate.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H
27 #define TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H
28 
32 
33 namespace tesseract_kinematics
34 {
36 {
37 public:
38  InverseKinematics::UPtr create(const std::string& solver_name,
39  const tesseract_scene_graph::SceneGraph& scene_graph,
40  const tesseract_scene_graph::SceneState& /*scene_state*/,
41  const KinematicsPluginFactory& /*plugin_factory*/,
42  const YAML::Node& config) const override
43  {
44  std::string base_link;
45  std::string tip_link;
46  std::size_t n_joints = 0;
47  std::vector<std::string> active_joints;
48  std::vector<std::vector<double>> free_joint_states;
49  try
50  {
51  if (YAML::Node n = config["base_link"])
52  base_link = n.as<std::string>();
53  else
54  throw std::runtime_error("IKFastInvKinFactory, missing 'base_link' entry");
55 
56  if (YAML::Node n = config["tip_link"])
57  tip_link = n.as<std::string>();
58  else
59  throw std::runtime_error("IKFastInvKinFactory, missing 'tip_link' entry");
60 
61  if (YAML::Node n = config["n_joints"])
62  n_joints = n.as<std::size_t>();
63  else
64  throw std::runtime_error("IKFastInvKinFactory, missing 'n_joints' entry");
65 
66  // Get the active joints in between the base link and tip link
67  active_joints = scene_graph.getShortestPath(base_link, tip_link).active_joints;
68 
69  std::size_t free_joints_required = active_joints.size() - n_joints;
70  std::map<std::size_t, std::vector<double>> free_joint_states_map;
71  // Get the free joint states
72  if (YAML::Node free_joint_states_node = config["free_joint_states"])
73  {
74  if (free_joints_required == 0)
75  throw std::runtime_error("IKFastInvKinFactory, entry 'free_joint_states' exists but no free joints exist");
76 
77  for (std::size_t idx = 0; idx < free_joint_states_node.size(); ++idx)
78  {
79  // Check the joints specification
80  if (free_joint_states_node[idx].size() != free_joints_required)
81  {
82  std::stringstream ss;
83  ss << "IKFastInvKinFactory, Number of active joints (" << active_joints.size()
84  << ") must equal the sum of the number of nominal joints (" << n_joints
85  << ") and the number of free joints (" << free_joint_states_map.size() << ")";
86  throw std::runtime_error(ss.str());
87  }
88  free_joint_states_map[idx] = free_joint_states_node[idx].as<std::vector<double>>();
89  }
90  }
91  else
92  {
93  if (free_joints_required > 0)
94  {
95  std::stringstream ss;
96  ss << "IKFastInvKinFactory, missing 'free_joint_states' entry, but states for " << free_joints_required
97  << " free joints required";
98  throw std::runtime_error(ss.str());
99  }
100  CONSOLE_BRIDGE_logDebug("IKFastInvKinFactory: No 'free_joint_states' entry found, none required");
101  }
102 
103  free_joint_states.reserve(free_joint_states_map.size());
104  std::transform(free_joint_states_map.begin(),
105  free_joint_states_map.end(),
106  std::back_inserter(free_joint_states),
107  [](const std::pair<const std::size_t, std::vector<double>>& pair) { return pair.second; });
108  }
109  catch (const std::exception& e)
110  {
111  CONSOLE_BRIDGE_logError("IKFastInvKinFactory: Failed to parse yaml config data! Details: %s", e.what());
112  return nullptr;
113  }
114 
115  return std::make_unique<IKFastInvKin>(base_link, tip_link, active_joints, solver_name, free_joint_states);
116  }
117 };
118 
119 } // namespace tesseract_kinematics
120 
121 #endif // TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H
graph.h
tesseract_kinematics::InvKinFactory
Define a inverse kinematics plugin which the factory can create an instance.
Definition: kinematics_plugin_factory.h:61
tesseract_scene_graph::ShortestPath::active_joints
std::vector< std::string > active_joints
tesseract_scene_graph::SceneGraph
tesseract_kinematics::InverseKinematics::UPtr
std::unique_ptr< InverseKinematics > UPtr
Definition: inverse_kinematics.h:52
tesseract_kinematics::IKFastInvKinFactory
Definition: ikfast_factory_boilerplate.h:35
tesseract_scene_graph::SceneState
tesseract_scene_graph::SceneGraph::getShortestPath
ShortestPath getShortestPath(const std::string &root, const std::string &tip) const
ikfast_inv_kin.hpp
Tesseract IKFast Inverse kinematics Wrapper Implementation.
kinematics_plugin_factory.h
Kinematics Plugin Factory.
tesseract_kinematics
Definition: forward_kinematics.h:40
tesseract_kinematics::KinematicsPluginFactory
Definition: kinematics_plugin_factory.h:116
tesseract_kinematics::IKFastInvKinFactory::create
InverseKinematics::UPtr create(const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &, const KinematicsPluginFactory &, const YAML::Node &config) const override
Create Inverse Kinematics Object.
Definition: ikfast_factory_boilerplate.h:38


tesseract_kinematics
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:02:14