opw_factory.cpp
Go to the documentation of this file.
1 
29 
32 
33 #include <console_bridge/console.h>
34 
35 namespace tesseract_kinematics
36 {
37 std::unique_ptr<InverseKinematics> OPWInvKinFactory::create(const std::string& solver_name,
38  const tesseract_scene_graph::SceneGraph& scene_graph,
39  const tesseract_scene_graph::SceneState& /*scene_state*/,
40  const KinematicsPluginFactory& /*plugin_factory*/,
41  const YAML::Node& config) const
42 {
43  std::string base_link;
44  std::string tip_link;
47 
48  try
49  {
50  if (YAML::Node n = config["base_link"])
51  base_link = n.as<std::string>();
52  else
53  throw std::runtime_error("OPWInvKinFactory, missing 'base_link' entry");
54 
55  if (YAML::Node n = config["tip_link"])
56  tip_link = n.as<std::string>();
57  else
58  throw std::runtime_error("OPWInvKinFactory, missing 'tip_link' entry");
59 
60  if (YAML::Node opw_params = config["params"])
61  {
62  if (YAML::Node n = opw_params["a1"])
63  params.a1 = n.as<double>();
64  else
65  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'a1' entry");
66 
67  if (YAML::Node n = opw_params["a2"])
68  params.a2 = n.as<double>();
69  else
70  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'a2' entry");
71 
72  if (YAML::Node n = opw_params["b"])
73  params.b = n.as<double>();
74  else
75  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'b' entry");
76 
77  if (YAML::Node n = opw_params["c1"])
78  params.c1 = n.as<double>();
79  else
80  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'c1' entry");
81 
82  if (YAML::Node n = opw_params["c2"])
83  params.c2 = n.as<double>();
84  else
85  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'c2' entry");
86 
87  if (YAML::Node n = opw_params["c3"])
88  params.c3 = n.as<double>();
89  else
90  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'c3' entry");
91 
92  if (YAML::Node n = opw_params["c4"])
93  params.c4 = n.as<double>();
94  else
95  throw std::runtime_error("OPWInvKinFactory, 'params' missing 'c4' entry");
96 
97  if (YAML::Node offsets = opw_params["offsets"])
98  {
99  auto o = offsets.as<std::vector<double>>();
100  if (o.size() != 6)
101  throw std::runtime_error("OPWInvKinFactory, offsets should have six elements!");
102 
103  std::copy(o.begin(), o.end(), params.offsets.begin());
104  }
105 
106  if (YAML::Node sign_corrections = opw_params["sign_corrections"])
107  {
108  auto sc = sign_corrections.as<std::vector<int>>();
109  if (sc.size() != 6)
110  throw std::runtime_error("OPWInvKinFactory, sign_corrections should have six elements!");
111 
112  for (std::size_t i = 0; i < sc.size(); ++i)
113  {
114  if (sc[i] == 1)
115  params.sign_corrections[i] = 1;
116  else if (sc[i] == -1)
117  params.sign_corrections[i] = -1;
118  else
119  throw std::runtime_error("OPWInvKinFactory, sign_corrections can only contain 1 or -1");
120  }
121  }
122  }
123  else
124  {
125  throw std::runtime_error("OPWInvKinFactory, missing 'params' entry");
126  }
127 
128  path = scene_graph.getShortestPath(base_link, tip_link);
129  }
130  catch (const std::exception& e)
131  {
132  CONSOLE_BRIDGE_logError("OPWInvKinFactory: Failed to parse yaml config data! Details: %s", e.what());
133  return nullptr;
134  }
135 
136  return std::make_unique<OPWInvKin>(params, base_link, tip_link, path.active_joints, solver_name);
137 }
138 
139 PLUGIN_ANCHOR_IMPL(OPWFactoriesAnchor)
140 
141 } // namespace tesseract_kinematics
142 
143 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
graph.h
tesseract_kinematics::OPWInvKinFactory
Definition: opw_factory.h:34
opw_kinematics::Parameters::a2
T a2
tesseract_scene_graph::ShortestPath::active_joints
std::vector< std::string > active_joints
opw_kinematics::Parameters::c3
T c3
tesseract_scene_graph::SceneGraph
tesseract_scene_graph::SceneState
tesseract_kinematics::OPWInvKinFactory::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: opw_factory.cpp:37
opw_inv_kin.h
Tesseract OPW Inverse kinematics Wrapper.
TESSERACT_ADD_INV_KIN_PLUGIN
TESSERACT_ADD_INV_KIN_PLUGIN(tesseract_kinematics::OPWInvKinFactory, OPWInvKinFactory)
opw_kinematics::Parameters::c1
T c1
tesseract_scene_graph::SceneGraph::getShortestPath
ShortestPath getShortestPath(const std::string &root, const std::string &tip) const
opw_kinematics::Parameters::offsets
std::array< T, 6 > offsets
opw_kinematics::Parameters::b
T b
opw_kinematics::Parameters::sign_corrections
std::array< signed char, 6 > sign_corrections
tesseract_scene_graph::ShortestPath
opw_kinematics::Parameters::a1
T a1
opw_factory.h
Tesseract OPW Inverse kinematics Factory.
scene_state.h
tesseract_kinematics
Definition: forward_kinematics.h:40
opw_kinematics::Parameters< double >
tesseract_kinematics::KinematicsPluginFactory
Definition: kinematics_plugin_factory.h:116
opw_kinematics::Parameters::c2
T c2
opw_kinematics::Parameters::c4
T c4


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