28 #include <boost/algorithm/string.hpp>
39 #include <boost_plugin_loader/plugin_loader.hpp>
40 #include <console_bridge/console.h>
58 plugin_loader_.search_paths.insert(TESSERACT_KINEMATICS_PLUGIN_PATH);
60 plugin_loader_.search_libraries, TESSERACT_KINEMATICS_PLUGINS, boost::is_any_of(
":"), boost::token_compress_on);
65 if (
const YAML::Node& plugin_info = config[KinematicsPluginInfo::CONFIG_KEY])
68 plugin_loader_.search_paths.insert(kin_plugin_info.search_paths.begin(), kin_plugin_info.search_paths.end());
69 plugin_loader_.search_libraries.insert(kin_plugin_info.search_libraries.begin(),
70 kin_plugin_info.search_libraries.end());
113 const std::string& solver_name,
128 throw std::runtime_error(
"KinematicsPluginFactory, tried to removed fwd kin solver '" + solver_name +
129 "' for a group '" + group_name +
"' that does not exist!");
131 auto solver_it = group_it->second.plugins.find(solver_name);
132 if (solver_it == group_it->second.plugins.end())
133 throw std::runtime_error(
"KinematicsPluginFactory, tried to removed fwd kin solver '" + solver_name +
134 "' that does not exist for group '" + group_name +
"'!");
136 group_it->second.plugins.erase(solver_it);
137 if (group_it->second.plugins.empty())
140 if (group_it->second.default_plugin == solver_name)
141 group_it->second.default_plugin.clear();
148 throw std::runtime_error(
"KinematicsPluginFactory, tried to set default fwd kin solver '" + solver_name +
149 "' for a group '" + group_name +
"' that does not exist!");
151 auto solver_it = group_it->second.plugins.find(solver_name);
152 if (solver_it == group_it->second.plugins.end())
153 throw std::runtime_error(
"KinematicsPluginFactory, tried to set default fwd kin solver '" + solver_name +
154 "' that does not exist for group '" + group_name +
"'!");
156 group_it->second.default_plugin = solver_name;
163 throw std::runtime_error(
"KinematicsPluginFactory, tried to get default fwd kin solver for a group '" + group_name +
164 "' that does not exist!");
166 if (group_it->second.default_plugin.empty())
167 return group_it->second.plugins.begin()->first;
169 return group_it->second.default_plugin;
173 const std::string& solver_name,
188 throw std::runtime_error(
"KinematicsPluginFactory, tried to removed inv kin solver '" + solver_name +
189 "' for a group '" + group_name +
"' that does not exist!");
191 auto solver_it = group_it->second.plugins.find(solver_name);
192 if (solver_it == group_it->second.plugins.end())
193 throw std::runtime_error(
"KinematicsPluginFactory, tried to removed inv kin solver '" + solver_name +
194 "' that does not exist for group '" + group_name +
"'!");
196 group_it->second.plugins.erase(solver_it);
197 if (group_it->second.plugins.empty())
200 if (group_it->second.default_plugin == solver_name)
201 group_it->second.default_plugin.clear();
208 throw std::runtime_error(
"KinematicsPluginFactory, tried to set default inv kin solver '" + solver_name +
209 "' for a group '" + group_name +
"' that does not exist!");
211 auto solver_it = group_it->second.plugins.find(solver_name);
212 if (solver_it == group_it->second.plugins.end())
213 throw std::runtime_error(
"KinematicsPluginFactory, tried to set default inv kin solver '" + solver_name +
214 "' that does not exist for group '" + group_name +
"'!");
216 group_it->second.default_plugin = solver_name;
223 throw std::runtime_error(
"KinematicsPluginFactory, tried to get default inv kin solver for a group '" + group_name +
224 "' that does not exist!");
226 if (group_it->second.default_plugin.empty())
227 return group_it->second.plugins.begin()->first;
229 return group_it->second.default_plugin;
232 std::unique_ptr<ForwardKinematics>
234 const std::string& solver_name,
241 CONSOLE_BRIDGE_logWarn(
"KinematicsPluginFactory, tried to get fwd kin solver '%s' for a group '%s' that does not "
248 auto solver_it = group_it->second.plugins.find(solver_name);
249 if (solver_it == group_it->second.plugins.end())
251 CONSOLE_BRIDGE_logWarn(
"KinematicsPluginFactory, tried to get fwd kin solver '%s' that does not exist for group "
258 return createFwdKin(solver_name, solver_it->second, scene_graph, scene_state);
261 std::unique_ptr<ForwardKinematics>
271 return it->second->create(solver_name, scene_graph, scene_state, *
this, plugin_info.
config);
274 if (plugin ==
nullptr)
276 CONSOLE_BRIDGE_logWarn(
"Failed to load symbol '%s'", plugin_info.
class_name.c_str());
280 return plugin->create(solver_name, scene_graph, scene_state, *
this, plugin_info.
config);
282 catch (
const std::exception&)
284 CONSOLE_BRIDGE_logWarn(
"Failed to load symbol '%s'", plugin_info.
class_name.c_str());
289 std::unique_ptr<InverseKinematics>
291 const std::string& solver_name,
298 CONSOLE_BRIDGE_logWarn(
"KinematicsPluginFactory, tried to get inv kin solver '%s' for a group '%s' that does not "
305 auto solver_it = group_it->second.plugins.find(solver_name);
306 if (solver_it == group_it->second.plugins.end())
308 CONSOLE_BRIDGE_logWarn(
"KinematicsPluginFactory, tried to get inv kin solver '%s' that does not exist for group "
315 return createInvKin(solver_name, solver_it->second, scene_graph, scene_state);
318 std::unique_ptr<InverseKinematics>
328 return it->second->create(solver_name, scene_graph, scene_state, *
this, plugin_info.
config);
331 if (plugin ==
nullptr)
333 CONSOLE_BRIDGE_logWarn(
"Failed to load symbol '%s'", plugin_info.
class_name.c_str());
337 return plugin->create(solver_name, scene_graph, scene_state, *
this, plugin_info.
config);
339 catch (
const std::exception& ex)
341 CONSOLE_BRIDGE_logWarn(ex.what());
349 std::ofstream fout(file_path.string());
362 config[KinematicsPluginInfo::CONFIG_KEY] = kinematic_plugins;