15 YAML::Node traj_node = YAML::LoadFile(yaml_file);
17 for (
const auto &node : traj_node)
19 for (
const auto &layer_array : node)
21 YAML::Node key_layer = layer_array.first;
22 if (!key_layer.IsScalar())
25 YAML::Node value_layer = layer_array.second;
26 if (!value_layer.IsSequence())
29 if (key_layer.as<std::string>() !=
"layer")
32 for (
const auto &layer : value_layer)
34 for (
const auto &polygon : layer)
36 YAML::Node key_polygon = polygon.first;
37 if (!key_polygon.IsScalar())
40 YAML::Node value_polygon = polygon.second;
41 if (!value_polygon.IsSequence())
44 if (key_polygon.as<std::string>() !=
"polygon")
47 for (
const auto &pose : value_polygon)
49 if (!pose.IsSequence())
52 Pose t_pose(Pose::Identity());
53 std::vector<double> p = pose.as<std::vector<double>>();
57 t_pose.linear() = Eigen::Quaterniond(p[6], p[3], p[4], p[5]).toRotationMatrix();
59 else if (p.size() != 3)
62 t_pose.translation()[0] = p[0];
63 t_pose.translation()[1] = p[1];
64 t_pose.translation()[2] = p[2];
66 t_polygon.push_back(t_pose);
68 if (!t_polygon.empty())
70 t_layer.push_back(t_polygon);
77 poses.push_back(t_layer);
83 catch (YAML::Exception &e)
96 ram_msgs::AdditiveManufacturingTrajectory &traj)
99 unsigned layer_number(0);
102 YAML::Node traj_node = YAML::LoadFile(yaml_file);
104 for (
const auto &node : traj_node)
106 for (
const auto &layer_array : node)
108 YAML::Node key_layer = layer_array.first;
109 if (!key_layer.IsScalar())
112 YAML::Node value_layer = layer_array.second;
113 if (!value_layer.IsSequence())
116 if (key_layer.as<std::string>() !=
"layer")
119 for (
const auto &layer : value_layer)
121 for (
const auto &polygon : layer)
123 YAML::Node key_polygon = polygon.first;
124 if (!key_polygon.IsScalar())
127 YAML::Node value_polygon = polygon.second;
128 if (!value_polygon.IsSequence())
131 if (key_polygon.as<std::string>() !=
"polygon")
135 for (
const auto &pose : value_polygon)
137 if (!pose.IsSequence())
140 ram_msgs::AdditiveManufacturingPose ram_pose;
141 std::vector<double> p = pose.as<std::vector<double>>();
144 ram_pose.pose.orientation.x = 0;
145 ram_pose.pose.orientation.y = 0;
146 ram_pose.pose.orientation.z = 0;
147 ram_pose.pose.orientation.w = 1;
149 else if (p.size() == 7)
151 ram_pose.pose.orientation.x = p[3];
152 ram_pose.pose.orientation.y = p[4];
153 ram_pose.pose.orientation.z = p[5];
154 ram_pose.pose.orientation.w = p[6];
159 ram_pose.layer_index = layer_number;
160 ram_pose.layer_level = layer_number;
161 ram_pose.entry_pose =
false;
162 ram_pose.exit_pose =
false;
164 ram_pose.pose.position.x = p[0];
165 ram_pose.pose.position.y = p[1];
166 ram_pose.pose.position.z = p[2];
169 ram_pose.polygon_start =
true;
171 traj.poses.push_back(ram_pose);
174 traj.poses.back().polygon_end =
true;
181 catch (YAML::Exception &e)
187 if (traj.poses.empty())
190 traj.file = yaml_file;
192 traj.modified = traj.generated;
193 traj.similar_layers =
false;
194 traj.generation_info =
"From YAML (poses) file";
static boost::uuids::uuid fromRandom(void)
bool yamlFileToPoses(std::string yaml_file, PosesTrajectory &poses)
std::vector< PosesPolygon > PosesLayer
static uuid_msgs::UniqueID toMsg(boost::uuids::uuid const &uu)
bool yamlFileToTrajectory(const std::string yaml_file, ram_msgs::AdditiveManufacturingTrajectory &traj)
#define ROS_ERROR_STREAM(args)
std::vector< PosesLayer > PosesTrajectory
std::vector< Eigen::Isometry3d > PosesPolygon