26 #ifndef TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H
27 #define TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H
42 const YAML::Node& config)
const override
44 std::string base_link;
46 std::size_t n_joints = 0;
47 std::vector<std::string> active_joints;
48 std::vector<std::vector<double>> free_joint_states;
51 if (YAML::Node n = config[
"base_link"])
52 base_link = n.as<std::string>();
54 throw std::runtime_error(
"IKFastInvKinFactory, missing 'base_link' entry");
56 if (YAML::Node n = config[
"tip_link"])
57 tip_link = n.as<std::string>();
59 throw std::runtime_error(
"IKFastInvKinFactory, missing 'tip_link' entry");
61 if (YAML::Node n = config[
"n_joints"])
62 n_joints = n.as<std::size_t>();
64 throw std::runtime_error(
"IKFastInvKinFactory, missing 'n_joints' entry");
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;
72 if (YAML::Node free_joint_states_node = config[
"free_joint_states"])
74 if (free_joints_required == 0)
75 throw std::runtime_error(
"IKFastInvKinFactory, entry 'free_joint_states' exists but no free joints exist");
77 for (std::size_t idx = 0; idx < free_joint_states_node.size(); ++idx)
80 if (free_joint_states_node[idx].size() != free_joints_required)
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());
88 free_joint_states_map[idx] = free_joint_states_node[idx].as<std::vector<double>>();
93 if (free_joints_required > 0)
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());
100 CONSOLE_BRIDGE_logDebug(
"IKFastInvKinFactory: No 'free_joint_states' entry found, none required");
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; });
109 catch (
const std::exception& e)
111 CONSOLE_BRIDGE_logError(
"IKFastInvKinFactory: Failed to parse yaml config data! Details: %s", e.what());
115 return std::make_unique<IKFastInvKin>(base_link, tip_link, active_joints, solver_name, free_joint_states);
121 #endif // TESSERACT_KINEMATICS_IKFAST_FACTORY_BOILERPLATE_H