13 #include <yaml-cpp/yaml.h> 15 using namespace se2ez;
40 Eigen::Vector3d offset{0., 0., 0.};
43 if (node[
"offset"].size() != 3)
50 Eigen::Vector4d color{0., 0., 0., 1.};
53 if (node[
"color"].size() != 4)
62 Eigen::VectorXd dimensions{};
66 if (node[
"dimensions"].IsSequence())
71 return std::make_shared<Geometry>(type, dimensions, offset, color);
79 if (!node[
"points"].IsSequence())
83 for (
unsigned int i = 0; i < node[
"points"].size(); ++i)
86 return std::make_shared<Geometry>(type, points, offset, color);
120 Eigen::Vector3d tip{0., 0., 0.};
123 if (node[
"tip"].size() != 3)
130 Eigen::VectorXd lower{};
131 Eigen::VectorXd upper{};
137 if (node[
"limits"][
"upper"].IsSequence())
153 if (node[
"geometry"].IsSequence())
154 for (
const auto &geo : node[
"geometry"])
169 if (!node[
"allowed"].IsSequence())
172 for (
const auto &allow : node[
"allowed"])
176 return std::make_tuple(parent, std::make_shared<Frame>(name, tip, type, lower, upper, geometry),
184 RobotPtr YAMLToRobot(
const YAML::Node &node)
186 RobotPtr robot = std::make_shared<Robot>();
191 if (!node[
"robot"].IsSequence())
194 for (
const auto &frame : node[
"robot"])
196 const auto &result = YAMLToFrame(frame);
197 robot->attachFrame(std::get<1>(result), std::get<0>(result));
199 for (
const auto &allow : std::get<2>(result))
200 robot->getACM()->disable(allow, std::get<1>(result)->getName());
203 robot->compileTree();
211 void YAMLToNamedState(
RobotPtr robot,
const YAML::Node &node)
219 if (!node[
"configuration"].IsSequence())
222 StatePtr state = std::make_shared<State>(robot);
225 for (
const auto &joint : node[
"configuration"])
228 auto x = robot->getFrameValues(frame, state->data);
231 if (x.
size() != v.size())
233 joint,
"Wrong number of values in frame \"%2%\" for named state \"%1%\"", name, frame);
238 robot->setNamedState(name, state);
245 void YAMLToStates(
RobotPtr robot,
const YAML::Node &node)
250 if (!node[
"states"].IsSequence())
253 for (
const auto &state : node[
"states"])
254 YAMLToNamedState(robot, state);
274 catch (YAML::InvalidNode &e)
284 if (!node.IsSequence())
287 Eigen::VectorXd x(node.size());
288 for (
unsigned int i = 0; i < node.size(); ++i)
289 x[i] = node[i].as<double>();
297 for (
unsigned int i = 0; i < vec.size(); ++i)
298 node.push_back(vec[i]);
308 SE2EZ_ERROR(
"Failed to load file \"%1%\"", filename);
314 auto robot = YAMLToRobot(result.second);
315 YAMLToStates(robot, result.second);
331 SE2EZ_ERROR(
"Failed to load file \"%1%\"", filename);
337 YAMLToStates(robot, result.second);
Eigen::VectorXd toVector(const YAML::Node &node)
Convert a sequence of doubles in YAML to an Eigen vector.
A shared pointer wrapper for se2ez::State.
RobotPtr loadRobot(const std::string &filename)
Loads a robot from a YAML file.
void throwParsingError(const YAML::Node &node, const std::string &fmt, Args &&... args)
Convenience function to print out a YAML error message with line and column information.
const std::pair< bool, YAML::Node > loadFileToYAML(const std::string &path)
Loads a file to a YAML node.
static Type stringToType(const std::string &geometry)
Try to convert a string into a geometry type. Not case-sensitive.
Fixed joint, just a rigid transformation.
A shared pointer wrapper for se2ez::Geometry.
Eigen::VectorXd toVector(double x)
Converts a single double value into a 1 x 1 matrix.
A simple polygon (no holes).
static Type stringToType(const std::string &joint)
Try to convert a string into a joint type. Not case-sensitive.
A shared pointer wrapper for se2ez::Robot.
bool loadStates(RobotPtr robot, const std::string &filename)
Loads named robot states from a YAML file.
#define SE2EZ_ERROR(fmt,...)
bool isNode(const YAML::Node &node)
Returns true if node is a valid YAML node.
const std::string resolvePath(const std::string &path)
Resolves file paths to their canonical form.
T emplace_back(T... args)