follow_poses_imp.hpp
Go to the documentation of this file.
1 #ifndef RAM_PATH_PLANNING_FOLLOW_POSES_IMP_HPP
2 #define RAM_PATH_PLANNING_FOLLOW_POSES_IMP_HPP
3 
4 namespace ram_path_planning
5 {
6 template<class ActionSpec>
8  PathPlanningAlgorithm<ActionSpec>("Follow poses", "Generate a trajectory from a list of poses",
9  "ram/path_planning/generate_trajectory/follow_poses")
10  {
11  }
12 
13 template<class ActionSpec>
15  ram_msgs::AdditiveManufacturingTrajectory &msg)
16  {
17  // A contour in the poly_data is a polygon in the ram_msg
18  msg.poses.clear();
19 
20  vtkIdType n_contours = poly_data->GetNumberOfCells();
21 
22  if (n_contours == 0)
23  return "YAML is empty";
24 
25  for (vtkIdType contour_id(0); contour_id < n_contours; ++contour_id)
26  {
27  // Contours the poly_data
28  vtkIdType n_points = poly_data->GetCell(contour_id)->GetNumberOfPoints();
29  if (n_points == 0)
30  return "Polygon in YAML file is empty";
31 
32  for (vtkIdType point_id(0); point_id < n_points; ++point_id)
33  {
34  // points in contour
35  double p[3]; // Central point
36  poly_data->GetCell(contour_id)->GetPoints()->GetPoint(point_id, p);
37 
38  ram_msgs::AdditiveManufacturingPose ram_pose;
39  ram_pose.unique_id = unique_id::toMsg(unique_id::fromRandom());
40  // Geometric pose
41  ram_pose.pose.orientation.w = 1;
42 
43  ram_pose.pose.position.x = p[0];
44  ram_pose.pose.position.y = p[1];
45  ram_pose.pose.position.z = p[2];
46 
47  // Polygon_start and polygon_end
48  if (point_id == 0)
49  ram_pose.polygon_start = true;
50  if ((point_id + 1) == n_points)
51  ram_pose.polygon_end = true;
52 
53  msg.poses.push_back(ram_pose);
54  }
55  }
56 
57  return "";
58  }
59 
60 template<class ActionSpec>
61  std::string FollowPoses<ActionSpec>::duplicateLayers(ram_msgs::AdditiveManufacturingTrajectory &msg,
62  const unsigned number_of_layers,
63  const double height_between_layers,
64  bool invert_one_of_two_layers)
65  {
66  if (number_of_layers < 2)
67  return "Number of layers < 2";
68 
69  if (!msg.poses.empty())
70  {
71  msg.poses.front().polygon_start = true;
72  msg.poses.back().polygon_end = true;
73  }
74 
75  const std::vector<ram_msgs::AdditiveManufacturingPose> first_layer(msg.poses);
76 
77  // msg contains only one layer, copy it
78  for (unsigned i(1); i < number_of_layers; ++i)
79  {
80  std::vector < ram_msgs::AdditiveManufacturingPose > new_layer(first_layer);
81  if (invert_one_of_two_layers && i % 2 == 1)
82  {
83  // Invert layer before pushing it
84  std::reverse(new_layer.begin(), new_layer.end());
85  new_layer.front().polygon_start = true;
86  new_layer.front().polygon_end = false;
87 
88  new_layer.back().polygon_end = true;
89  new_layer.back().polygon_start = false;
90  }
91 
92  for (auto &pose : new_layer)
93  {
94  pose.unique_id = unique_id::toMsg(unique_id::fromRandom());
95  pose.layer_level = i;
96  pose.layer_index = pose.layer_level;
97  pose.pose.position.z += i * height_between_layers;
98  }
99 
100  // Insert the poses
101  msg.poses.insert(msg.poses.end(), new_layer.begin(), new_layer.end());
102  }
103 
104  if (invert_one_of_two_layers)
105  msg.similar_layers = false;
106  else
107  msg.similar_layers = true;
108  return "";
109  }
110 
111 template<class ActionSpec>
112  std::string FollowPoses<ActionSpec>::generateTrajectory(const std::string yaml_file,
113  ram_msgs::AdditiveManufacturingTrajectory &msg)
114  {
115  if (ram_utils::yamlFileToTrajectory(yaml_file, msg))
116  return "";
117 
118  // Prepare contours
119  const Polygon poly_data = Polygon::New();
120  std::vector<unsigned> layer_count;
121  if (ram_utils::yamlFileToPolydata2(yaml_file, poly_data, layer_count))
122  {
123  std::string error = generateTrajectory(poly_data, msg);
124  if (!error.empty())
125  return error;
126 
127  msg.file = yaml_file;
128  msg.generated = ros::Time::now();
129  msg.modified = msg.generated;
130  msg.similar_layers = false;
131  msg.generation_info = "From YAML (points) file";
132  return "";
133  }
134 
135  return "Failed to read YAML file";
136  }
137 }
138 
139 #endif
static boost::uuids::uuid fromRandom(void)
vtkSmartPointer< vtkPolyData > Polygon
std::string duplicateLayers(ram_msgs::AdditiveManufacturingTrajectory &msg, const unsigned number_of_layers, const double height_between_layers, bool invert_one_of_two_layers)
std::string generateTrajectory(const Polygon poly_data, ram_msgs::AdditiveManufacturingTrajectory &msg)
bool yamlFileToPolydata2(const std::string yaml_file, Polygon poly_data, std::vector< unsigned > &layer_count)
static Time now()
static uuid_msgs::UniqueID toMsg(boost::uuids::uuid const &uu)
bool yamlFileToTrajectory(const std::string yaml_file, ram_msgs::AdditiveManufacturingTrajectory &traj)


ram_path_planning
Author(s): Andres Campos - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:03