kdl_factories.cpp
Go to the documentation of this file.
1 
32 
35 
36 #include <console_bridge/console.h>
37 
38 namespace tesseract_kinematics
39 {
40 std::unique_ptr<ForwardKinematics>
41 KDLFwdKinChainFactory::create(const std::string& solver_name,
42  const tesseract_scene_graph::SceneGraph& scene_graph,
43  const tesseract_scene_graph::SceneState& /*scene_state*/,
44  const KinematicsPluginFactory& /*plugin_factory*/,
45  const YAML::Node& config) const
46 {
47  std::string base_link;
48  std::string tip_link;
49 
50  try
51  {
52  if (YAML::Node n = config["base_link"])
53  base_link = n.as<std::string>();
54  else
55  throw std::runtime_error("KDLFwdKinChainFactory, missing 'base_link' entry");
56 
57  if (YAML::Node n = config["tip_link"])
58  tip_link = n.as<std::string>();
59  else
60  throw std::runtime_error("KDLFwdKinChainFactory, missing 'tip_link' entry");
61  }
62  catch (const std::exception& e)
63  {
64  CONSOLE_BRIDGE_logError("KDLFwdKinChainFactory: Failed to parse yaml config data! Details: %s", e.what());
65  return nullptr;
66  }
67 
68  return std::make_unique<KDLFwdKinChain>(scene_graph, base_link, tip_link, solver_name);
69 }
70 
71 std::unique_ptr<InverseKinematics>
72 KDLInvKinChainLMAFactory::create(const std::string& solver_name,
73  const tesseract_scene_graph::SceneGraph& scene_graph,
74  const tesseract_scene_graph::SceneState& /*scene_state*/,
75  const KinematicsPluginFactory& /*plugin_factory*/,
76  const YAML::Node& config) const
77 {
78  std::string base_link;
79  std::string tip_link;
80  KDLInvKinChainLMA::Config kdl_config;
81 
82  try
83  {
84  if (YAML::Node n = config["base_link"])
85  base_link = n.as<std::string>();
86  else
87  throw std::runtime_error("KDLInvKinChainLMAFactory, missing 'base_link' entry");
88 
89  if (YAML::Node n = config["tip_link"])
90  tip_link = n.as<std::string>();
91  else
92  throw std::runtime_error("KDLInvKinChainLMAFactory, missing 'tip_link' entry");
93 
94  // Optional configuration parameters
95  if (YAML::Node n = config["task_weights"])
96  {
97  // Make sure the length matches the constructor interface
98  if (n.size() != 6)
99  throw std::runtime_error("KDLInvKinChainLMAFactory, size of task_weights needs to be 6");
100 
101  kdl_config.task_weights = n.as<std::array<double, 6>>();
102  }
103 
104  if (YAML::Node n = config["eps"])
105  kdl_config.eps = n.as<double>();
106 
107  if (YAML::Node n = config["max_iterations"])
108  kdl_config.max_iterations = n.as<int>();
109 
110  if (YAML::Node n = config["eps_joints"])
111  kdl_config.eps_joints = n.as<double>();
112  }
113  catch (const std::exception& e)
114  {
115  CONSOLE_BRIDGE_logError("KDLInvKinChainLMAFactory: Failed to parse yaml config data! Details: %s", e.what());
116  return nullptr;
117  }
118 
119  return std::make_unique<KDLInvKinChainLMA>(scene_graph, base_link, tip_link, kdl_config, solver_name);
120 }
121 
122 std::unique_ptr<InverseKinematics>
123 KDLInvKinChainNRFactory::create(const std::string& solver_name,
124  const tesseract_scene_graph::SceneGraph& scene_graph,
125  const tesseract_scene_graph::SceneState& /*scene_state*/,
126  const KinematicsPluginFactory& /*plugin_factory*/,
127  const YAML::Node& config) const
128 {
129  std::string base_link;
130  std::string tip_link;
131  KDLInvKinChainNR::Config kdl_config;
132 
133  try
134  {
135  if (YAML::Node n = config["base_link"])
136  base_link = n.as<std::string>();
137  else
138  throw std::runtime_error("KDLInvKinChainNRFactory, missing 'base_link' entry");
139 
140  if (YAML::Node n = config["tip_link"])
141  tip_link = n.as<std::string>();
142  else
143  throw std::runtime_error("KDLInvKinChainNRFactory, missing 'tip_link' entry");
144 
145  // Optional configuration parameters
146  if (YAML::Node n = config["velocity_eps"])
147  kdl_config.vel_eps = n.as<double>();
148 
149  if (YAML::Node n = config["velocity_iterations"])
150  kdl_config.vel_iterations = n.as<int>();
151 
152  if (YAML::Node n = config["position_eps"])
153  kdl_config.pos_eps = n.as<double>();
154 
155  if (YAML::Node n = config["position_iterations"])
156  kdl_config.pos_iterations = n.as<int>();
157  }
158  catch (const std::exception& e)
159  {
160  CONSOLE_BRIDGE_logError("KDLInvKinChainNRFactory: Failed to parse yaml config data! Details: %s", e.what());
161  return nullptr;
162  }
163 
164  return std::make_unique<KDLInvKinChainNR>(scene_graph, base_link, tip_link, kdl_config, solver_name);
165 }
166 
167 std::unique_ptr<InverseKinematics>
168 KDLInvKinChainNR_JLFactory::create(const std::string& solver_name,
169  const tesseract_scene_graph::SceneGraph& scene_graph,
170  const tesseract_scene_graph::SceneState& /*scene_state*/,
171  const KinematicsPluginFactory& /*plugin_factory*/,
172  const YAML::Node& config) const
173 {
174  std::string base_link;
175  std::string tip_link;
176  KDLInvKinChainNR_JL::Config kdl_config;
177 
178  try
179  {
180  if (YAML::Node n = config["base_link"])
181  base_link = n.as<std::string>();
182  else
183  throw std::runtime_error("KDLInvKinChainNR_JLFactory, missing 'base_link' entry");
184 
185  if (YAML::Node n = config["tip_link"])
186  tip_link = n.as<std::string>();
187  else
188  throw std::runtime_error("KDLInvKinChainNR_JLFactory, missing 'tip_link' entry");
189  // Optional configuration parameters
190  if (YAML::Node n = config["velocity_eps"])
191  kdl_config.vel_eps = n.as<double>();
192 
193  if (YAML::Node n = config["velocity_iterations"])
194  kdl_config.vel_iterations = n.as<int>();
195 
196  if (YAML::Node n = config["position_eps"])
197  kdl_config.pos_eps = n.as<double>();
198 
199  if (YAML::Node n = config["position_iterations"])
200  kdl_config.pos_iterations = n.as<int>();
201  }
202  catch (const std::exception& e)
203  {
204  CONSOLE_BRIDGE_logError("KDLInvKinChainNR_JLFactory: Failed to parse yaml config data! Details: %s", e.what());
205  return nullptr;
206  }
207 
208  return std::make_unique<KDLInvKinChainNR_JL>(scene_graph, base_link, tip_link, kdl_config, solver_name);
209 }
210 
211 PLUGIN_ANCHOR_IMPL(KDLFactoriesAnchor)
212 
213 } // namespace tesseract_kinematics
214 
215 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
217 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
219 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
221 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
graph.h
kdl_fwd_kin_chain.h
Tesseract KDL forward kinematics chain implementation.
tesseract_kinematics::KDLInvKinChainNR::Config::pos_iterations
int pos_iterations
Definition: kdl_inv_kin_chain_nr.h:72
tesseract_kinematics::KDLInvKinChainLMAFactory
Definition: kdl_factories.h:43
tesseract_kinematics::KDLInvKinChainNRFactory
Definition: kdl_factories.h:52
tesseract_kinematics::KDLFwdKinChainFactory
Definition: kdl_factories.h:34
tesseract_kinematics::KDLInvKinChainNR_JL::Config::pos_eps
double pos_eps
Definition: kdl_inv_kin_chain_nr_jl.h:71
tesseract_scene_graph::SceneGraph
tesseract_kinematics::KDLInvKinChainNRFactory::create
std::unique_ptr< InverseKinematics > create(const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state, const KinematicsPluginFactory &plugin_factory, const YAML::Node &config) const override final
Create Inverse Kinematics Object.
Definition: kdl_factories.cpp:123
tesseract_kinematics::KDLInvKinChainLMAFactory::create
std::unique_ptr< InverseKinematics > create(const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state, const KinematicsPluginFactory &plugin_factory, const YAML::Node &config) const override final
Create Inverse Kinematics Object.
Definition: kdl_factories.cpp:72
tesseract_kinematics::KDLInvKinChainNR::Config::vel_eps
double vel_eps
Definition: kdl_inv_kin_chain_nr.h:69
kdl_factories.h
Tesseract KDL Factories.
tesseract_kinematics::KDLInvKinChainNR_JL::Config
The Config struct.
Definition: kdl_inv_kin_chain_nr_jl.h:67
tesseract_scene_graph::SceneState
tesseract_kinematics::KDLInvKinChainLMA::Config::eps_joints
double eps_joints
Definition: kdl_inv_kin_chain_lma.h:70
tesseract_kinematics::KDLInvKinChainNR::Config::vel_iterations
int vel_iterations
Definition: kdl_inv_kin_chain_nr.h:70
tesseract_kinematics::KDLInvKinChainNR::Config
The Config struct.
Definition: kdl_inv_kin_chain_nr.h:67
tesseract_kinematics::KDLInvKinChainLMA::Config::task_weights
std::array< double, 6 > task_weights
Definition: kdl_inv_kin_chain_lma.h:67
kdl_inv_kin_chain_nr.h
tesseract_kinematics::KDLInvKinChainLMA::Config
The Config struct.
Definition: kdl_inv_kin_chain_lma.h:65
tesseract_kinematics::KDLInvKinChainLMA::Config::max_iterations
int max_iterations
Definition: kdl_inv_kin_chain_lma.h:69
tesseract_kinematics::KDLInvKinChainNR_JLFactory::create
std::unique_ptr< InverseKinematics > create(const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state, const KinematicsPluginFactory &plugin_factory, const YAML::Node &config) const override final
Create Inverse Kinematics Object.
Definition: kdl_factories.cpp:168
tesseract_kinematics::KDLInvKinChainNR::Config::pos_eps
double pos_eps
Definition: kdl_inv_kin_chain_nr.h:71
tesseract_kinematics::KDLInvKinChainNR_JL::Config::vel_iterations
int vel_iterations
Definition: kdl_inv_kin_chain_nr_jl.h:70
tesseract_kinematics::KDLFwdKinChainFactory::create
std::unique_ptr< ForwardKinematics > create(const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state, const KinematicsPluginFactory &plugin_factory, const YAML::Node &config) const override final
Create Inverse Kinematics Object.
Definition: kdl_factories.cpp:41
scene_state.h
tesseract_kinematics::KDLInvKinChainNR_JLFactory
Definition: kdl_factories.h:61
tesseract_kinematics::KDLInvKinChainNR_JL::Config::vel_eps
double vel_eps
Definition: kdl_inv_kin_chain_nr_jl.h:69
tesseract_kinematics
Definition: forward_kinematics.h:40
tesseract_kinematics::KDLInvKinChainNR_JL::Config::pos_iterations
int pos_iterations
Definition: kdl_inv_kin_chain_nr_jl.h:72
tesseract_kinematics::KinematicsPluginFactory
Definition: kinematics_plugin_factory.h:116
kdl_inv_kin_chain_nr_jl.h
TESSERACT_ADD_INV_KIN_PLUGIN
TESSERACT_ADD_INV_KIN_PLUGIN(tesseract_kinematics::KDLInvKinChainLMAFactory, KDLInvKinChainLMAFactory)
kdl_inv_kin_chain_lma.h
Tesseract KDL Inverse kinematics chain Levenberg-Marquardt implementation.
TESSERACT_ADD_FWD_KIN_PLUGIN
TESSERACT_ADD_FWD_KIN_PLUGIN(tesseract_kinematics::KDLFwdKinChainFactory, KDLFwdKinChainFactory)
tesseract_kinematics::KDLInvKinChainLMA::Config::eps
double eps
Definition: kdl_inv_kin_chain_lma.h:68


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