rop_factory.cpp
Go to the documentation of this file.
1 
32 
33 #include <console_bridge/console.h>
34 
35 namespace tesseract_kinematics
36 {
37 std::unique_ptr<InverseKinematics> ROPInvKinFactory::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 {
45  double m_reach{ 0 };
46  Eigen::MatrixX2d sample_range;
47  Eigen::VectorXd sample_res;
48 
49  try
50  {
51  // Get Reach
52  if (YAML::Node n = config["manipulator_reach"])
53  m_reach = n.as<double>();
54  else
55  throw std::runtime_error("ROPInvKinFactory, missing 'manipulator_reach' entry!");
56 
57  // Get positioner sample resolution
58  std::map<std::string, std::array<double, 3>> sample_res_map;
59  if (YAML::Node sample_res_node = config["positioner_sample_resolution"])
60  {
61  for (auto it = sample_res_node.begin(); it != sample_res_node.end(); ++it)
62  {
63  const YAML::Node& joint = *it;
64  std::array<double, 3> values{ 0, 0, 0 };
65 
66  std::string joint_name;
67  if (YAML::Node n = joint["name"])
68  joint_name = n.as<std::string>();
69  else
70  throw std::runtime_error("ROPInvKinFactory, 'positioner_sample_resolution' missing 'name' entry!");
71 
72  if (YAML::Node n = joint["value"])
73  values[0] = n.as<double>();
74  else
75  throw std::runtime_error("ROPInvKinFactory, 'positioner_sample_resolution' missing 'value' entry!");
76 
77  auto jnt = scene_graph.getJoint(joint_name);
78  if (jnt == nullptr)
79  throw std::runtime_error("ROPInvKinFactory, 'positioner_sample_resolution' failed to find joint in scene "
80  "graph!");
81 
82  values[1] = jnt->limits->lower;
83  values[2] = jnt->limits->upper;
84 
85  if (YAML::Node min = joint["min"])
86  values[1] = min.as<double>();
87 
88  if (YAML::Node max = joint["max"])
89  values[2] = max.as<double>();
90 
91  if (values[1] < jnt->limits->lower)
92  throw std::runtime_error("ROPInvKinFactory, sample range minimum is less than joint minimum!");
93 
94  if (values[2] > jnt->limits->upper)
95  throw std::runtime_error("ROPInvKinFactory, sample range maximum is greater than joint maximum!");
96 
97  if (values[1] > values[2])
98  throw std::runtime_error("ROPInvKinFactory, sample range is not valid!");
99 
100  sample_res_map[joint_name] = values;
101  }
102  }
103  else
104  {
105  throw std::runtime_error("ROPInvKinFactory, missing 'positioner_sample_resolution' entry!");
106  }
107 
108  // Get Positioner
109  if (YAML::Node positioner = config["positioner"])
110  {
112  if (YAML::Node n = positioner["class"])
113  p_info.class_name = n.as<std::string>();
114  else
115  throw std::runtime_error("ROPInvKinFactory, 'positioner' missing 'class' entry!");
116 
117  if (YAML::Node n = positioner["config"])
118  p_info.config = n;
119 
120  fwd_kin = plugin_factory.createFwdKin(p_info.class_name, p_info, scene_graph, scene_state);
121  if (fwd_kin == nullptr)
122  throw std::runtime_error("ROPInvKinFactory, failed to create positioner forward kinematics!");
123 
124  if (sample_res_map.size() != static_cast<std::size_t>(fwd_kin->numJoints()))
125  throw std::runtime_error("ROPInvKinFactory, positioner sample resolution has incorrect number of joints!");
126  }
127  else
128  {
129  throw std::runtime_error("ROPInvKinFactory, missing 'positioner' entry!");
130  }
131 
132  // Load Positioner Resolution and Range
133  sample_range.resize(fwd_kin->numJoints(), 2);
134  sample_res.resize(fwd_kin->numJoints());
135  std::vector<std::string> joint_names = fwd_kin->getJointNames();
136  for (Eigen::Index i = 0; i < static_cast<Eigen::Index>(joint_names.size()); ++i)
137  {
138  const auto& jn = joint_names[static_cast<std::size_t>(i)];
139  auto it = sample_res_map.find(jn);
140  if (it == sample_res_map.end())
141  throw std::runtime_error("ROPInvKinFactory, positioner sample resolution missing joint '" + jn + "'!");
142 
143  sample_res(i) = it->second[0];
144  sample_range(i, 0) = it->second[1];
145  sample_range(i, 1) = it->second[2];
146  }
147 
148  // Get Manipulator
149  if (YAML::Node manipulator = config["manipulator"])
150  {
152  if (YAML::Node n = manipulator["class"])
153  m_info.class_name = n.as<std::string>();
154  else
155  throw std::runtime_error("ROPInvKinFactory, 'manipulator' missing 'class' entry!");
156 
157  if (YAML::Node n = manipulator["config"])
158  m_info.config = n;
159 
160  inv_kin = plugin_factory.createInvKin(m_info.class_name, m_info, scene_graph, scene_state);
161  if (inv_kin == nullptr)
162  throw std::runtime_error("ROPInvKinFactory, failed to create positioner inverse kinematics!");
163  }
164  else
165  {
166  throw std::runtime_error("ROPInvKinFactory, missing 'manipulator' entry!");
167  }
168  }
169  catch (const std::exception& e)
170  {
171  CONSOLE_BRIDGE_logError("ROPInvKinFactory: Failed to parse yaml config data! Details: %s", e.what());
172  return nullptr;
173  }
174 
175  return std::make_unique<ROPInvKin>(
176  scene_graph, scene_state, std::move(inv_kin), m_reach, std::move(fwd_kin), sample_range, sample_res, solver_name);
177 }
178 
179 PLUGIN_ANCHOR_IMPL(ROPInvKinFactoriesAnchor)
180 
181 } // namespace tesseract_kinematics
182 
183 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
graph.h
joint.h
tesseract_kinematics::ROPInvKinFactory::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: rop_factory.cpp:37
rop_factory.h
Robot on Positioner Inverse kinematics factory.
tesseract_scene_graph::SceneGraph
tesseract_kinematics::InverseKinematics::UPtr
std::unique_ptr< InverseKinematics > UPtr
Definition: inverse_kinematics.h:52
tesseract_scene_graph::SceneState
tesseract_common::PluginInfo::class_name
std::string class_name
tesseract_common::PluginInfo
tesseract_kinematics::KinematicsPluginFactory::createInvKin
std::unique_ptr< InverseKinematics > createInvKin(const std::string &group_name, const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state) const
Get inverse kinematics object given group name and solver name.
Definition: kinematics_plugin_factory.cpp:290
tesseract_kinematics::ROPInvKinFactory
Definition: rop_factory.h:34
forward_kinematics.h
Forward kinematics functions.
tesseract_common::PluginInfo::config
YAML::Node config
tesseract_kinematics::KinematicsPluginFactory::createFwdKin
std::unique_ptr< ForwardKinematics > createFwdKin(const std::string &group_name, const std::string &solver_name, const tesseract_scene_graph::SceneGraph &scene_graph, const tesseract_scene_graph::SceneState &scene_state) const
Get forward kinematics object given group name and solver name.
Definition: kinematics_plugin_factory.cpp:233
TESSERACT_ADD_INV_KIN_PLUGIN
TESSERACT_ADD_INV_KIN_PLUGIN(tesseract_kinematics::ROPInvKinFactory, ROPInvKinFactory)
tesseract_scene_graph::SceneGraph::getJoint
std::shared_ptr< const Joint > getJoint(const std::string &name) const
tesseract_kinematics::ForwardKinematics::UPtr
std::unique_ptr< ForwardKinematics > UPtr
Definition: forward_kinematics.h:52
tesseract_kinematics
Definition: forward_kinematics.h:40
tesseract_kinematics::KinematicsPluginFactory
Definition: kinematics_plugin_factory.h:116
rop_inv_kin.h


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