post_processor.cpp
Go to the documentation of this file.
2 
3 namespace ram_post_processor
4 {
5 PostProcessor::PostProcessor(const std::string name,
6  const std::string description,
7  const std::string service_name) :
8  name_(name),
9  description_(description),
10  service_name_(service_name)
11 {
12  get_start_pose_client_ = nh_.serviceClient<ram_utils::GetStartPose>("ram/get_start_pose");
13  get_tool_client_ = nh_.serviceClient<ram_utils::GetTool>("ram/get_tool");
14  get_trajectory_infos_client_ = nh_.serviceClient<ram_utils::GetTrajectoryInfos>(
15  "ram/information/get_trajectory_infos");
16 }
17 
18 void PostProcessor::addComment(const std::string comment)
19 {
20  programs_.front().second.append("\n" + comment);
21 }
22 
23 void PostProcessor::addPose(const bool,
24  const bool,
25  const bool,
26  const bool,
27  const bool,
28  const bool)
29 {
30  std::stringstream buffer;
31  buffer << currentPose()->pose;
32  std::string pose_str(buffer.str());
33  programs_.front().second.append("\n Pose: \n" + buffer.str());
34 }
35 
37 {
38  programs_.clear();
39 }
40 
42 {
43 }
44 
46 {
47 }
48 
51 {
52  programs_.front().second.append("\nStart polygon");
53 }
54 
56 {
57 }
58 
60 {
61 }
62 
64 {
65  programs_.front().second.append("\nFinish polygon");
66 }
67 
70 {
72  {
73  programs_.front().second.append("\nLayer index " + std::to_string(currentPose()->layer_index));
74  programs_.front().second.append("\nLayer level " + std::to_string(currentPose()->layer_level));
75  }
76 }
77 
80 {
81  programs_.front().second.append("\nStart feed rate: " + std::to_string(currentPose()->params.feed_rate));
82 }
83 
85 {
86 }
87 
89 {
90  programs_.front().second.append("\nChange feed rate: " + std::to_string(currentPose()->params.feed_rate));
91 }
92 
94 {
95 }
96 
98 {
99  programs_.front().second.append("\nStop feed rate");
100 }
101 
103 {
104  programs_.front().second.append("\nStop feed rate");
105 }
106 
109 {
110  programs_.front().second.append("\nStart laser_power: " + std::to_string(currentPose()->params.laser_power));
111 }
112 
114 {
115 }
116 
118 {
119  programs_.front().second.append("\nChange laser power: " + std::to_string(currentPose()->params.laser_power));
120 }
121 
123 {
124 }
125 
127 {
128  programs_.front().second.append("\nStop laser power");
129 }
130 
132 {
133 }
134 
135 void PostProcessor::generatePrograms(const ram_msgs::AdditiveManufacturingTrajectory &trajectory,
136  std::vector<std::pair<std::string, std::string>> &programs)
137 {
138  ram_msgs::AdditiveManufacturingPose last_pose;
139 
141  clearProgram();
142 
144  programs_.push_back(std::pair<std::string, std::string>(program_name_, ""));
145 
146  if (trajectory.poses.empty())
147  throw std::runtime_error("Trajectory is empty");
148 
149  trajectory_ = trajectory;
150 
152  // Check that service exists
154  throw std::runtime_error("Cannot get start pose, service does not exist");
155 
156  // Call service to get start pose
157  ram_utils::GetStartPose srv_1;
158  if (!get_start_pose_client_.call(srv_1))
159  throw std::runtime_error("Cannot get start pose, call to service failed");
160 
161  tf::poseMsgToEigen(srv_1.response.pose, start_pose_);
162 
164  // Check that service exists
166  throw std::runtime_error("Cannot get tool, service does not exist");
167 
168  // Call service to get start pose
169  ram_utils::GetTool srv_2;
170  if (!get_tool_client_.call(srv_2))
171  throw std::runtime_error("Cannot get tool, call to service failed");
172 
173  tf::poseMsgToEigen(srv_2.response.pose, tool_);
174 
175  programs_.front().second.append("Program comment: " + program_comment_);
176  if (verbose_comments_)
177  {
178  unsigned highest_layer(0);
179  for (auto ram_pose : trajectory_.poses)
180  if (ram_pose.layer_level > highest_layer)
181  highest_layer = ram_pose.layer_level;
182  addComment("File = " + trajectory_.file);
183  addComment("Number of layers = " + std::to_string(highest_layer + 1));
184  addComment(trajectory_.generation_info);
185 
186  // Check that service exists
188  throw std::runtime_error("Cannot get trajectory infos, service does not exist");
189 
190  // Call service to get traj infos
191  ram_utils::GetTrajectoryInfos srv_3;
193  throw std::runtime_error("Cannot get trajectory infos, call to service failed");
194  else
195  {
196  uint16_t seconds(srv_3.response.informations.execution_time);
197  unsigned hours(seconds / 3600);
198  seconds -= hours * 3600;
199 
200  unsigned minutes(seconds / 60);
201  seconds -= minutes * 60;
202 
203  addComment("Execution duration = " + std::to_string(hours) + ":" + std::to_string(minutes) + ":"
204  + std::to_string(seconds));
205  addComment("");
206  }
207  }
208 
210 
212  for (auto &ram_pose : trajectory_.poses)
213  {
214  Eigen::Isometry3d pose;
215  // geometry_msg to Eigen
216  tf::poseMsgToEigen(ram_pose.pose, pose);
217  // Transform pose
218  pose = start_pose_ * pose * tool_;
219  // Eigen to geometry
220  tf::poseEigenToMsg(pose, ram_pose.pose);
221  }
222 
223  bool first_pose(true);
224  for (current_pose_ = trajectory_.poses.begin(); current_pose_ != trajectory_.poses.end(); ++current_pose_)
225  {
226  bool laser_power_start(false),
227  laser_power_stop(false),
228  laser_power_change(false),
229  feed_rate_start(false),
230  feed_rate_stop(false),
231  feed_rate_change(false);
232 
234 
235  // (Layer index changed OR first pose) AND verbose comments
236  if ((current_pose_->layer_index != last_pose.layer_index || first_pose))
238 
239  if (current_pose_->polygon_start)
241 
242  if (current_pose_->polygon_end)
244 
245  if (first_pose)
246  {
247  if (current_pose_->params.feed_rate != 0)
248  {
249  feed_rate_start = true;
251  }
252 
253  if (last_pose.params.laser_power != 0)
254  {
255  laser_power_start = true;
257  }
258  }
259  else
260  {
261  // Feed rate changes
262  if (current_pose_->params.feed_rate != last_pose.params.feed_rate)
263  {
264  if (last_pose.params.feed_rate != 0 && current_pose_->params.feed_rate == 0)
265  {
266  feed_rate_stop = true;
268  }
269  else if (last_pose.params.feed_rate == 0)
270  {
271  feed_rate_start = true;
273  }
274  else
275  {
276  feed_rate_change = true;
278  }
279  }
280 
281  // Laser power changes
282  if (current_pose_->params.laser_power != last_pose.params.laser_power)
283  {
284  if (last_pose.params.laser_power != 0 && current_pose_->params.laser_power == 0)
285  {
286  laser_power_stop = true;
288  }
289  else if (last_pose.params.laser_power == 0)
290  {
291  laser_power_start = true;
293  }
294  else
295  {
296  laser_power_change = true;
298  }
299  }
300  }
301 
303  addPose(laser_power_start,
304  laser_power_stop,
305  laser_power_change,
306  feed_rate_start,
307  feed_rate_stop,
308  feed_rate_change);
309 
311  if (current_pose_->polygon_start)
313 
314  if (current_pose_->polygon_end)
316 
317  if (first_pose)
318  {
319  if (current_pose_->params.feed_rate != 0)
321 
322  if (last_pose.params.laser_power != 0)
324  }
325  else
326  {
327  // Feed rate changes
328  if (current_pose_->params.feed_rate != last_pose.params.feed_rate)
329  {
330  if (last_pose.params.feed_rate != 0 && current_pose_->params.feed_rate == 0)
332  else if (last_pose.params.feed_rate == 0)
334  else
336  }
337 
338  // Laser power changes
339  if (current_pose_->params.laser_power != last_pose.params.laser_power)
340  {
341  if (last_pose.params.laser_power != 0 && current_pose_->params.laser_power == 0)
343  else if (last_pose.params.laser_power == 0)
345  else
347  }
348  }
349 
350  first_pose = false;
351  last_pose = *current_pose_;
352  }
353 
354  afterGenerating();
355  programs = programs_;
356 }
357 
358 void PostProcessor::saveToFiles(const std::string directory,
359  const std::string file_extension)
360 {
361  std::ofstream program_file;
362  for (auto &program : programs_)
363  {
364  const std::string file_name(directory + "/" + program.first + file_extension);
365  program_file.open(file_name, std::ofstream::out);
366  if (!program_file.is_open())
367  throw std::runtime_error("Could not open file " + file_name + " for writing");
368 
369  program_file << program.second;
370  program_file.close();
371  }
372  return;
373 }
374 
375 }
virtual void changeLaserPowerBefore()
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
virtual void startFeedRateAfter()
std::string program_name_
ros::NodeHandle nh_
void generatePrograms(const ram_msgs::AdditiveManufacturingTrajectory &trajectory, std::vector< std::pair< std::string, std::string >> &programs)
void poseEigenToMsg(const Eigen::Affine3d &e, geometry_msgs::Pose &m)
ram_msgs::AdditiveManufacturingParams params
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
const ram_pose_const_iterator & currentPose()
bool call(MReq &req, MRes &res)
virtual void clearProgram()
Eigen::Isometry3d start_pose_
virtual void startPolygonBefore()
Polygons.
std::string program_comment_
Eigen::Isometry3d tool_
virtual void startFeedRateBefore()
Feed rate.
ros::ServiceClient get_start_pose_client_
virtual void stopFeedRateBefore()
virtual void changeFeedRateBefore()
virtual void addComment(const std::string comment)
virtual void beforeGenerating()
ros::ServiceClient get_trajectory_infos_client_
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
ros::ServiceClient get_tool_client_
virtual void startPolygonAfter()
virtual void stopLaserPowerAfter()
virtual void finishPolygonAfter()
virtual void saveToFiles(const std::string directory, const std::string file_extension="")
virtual void addPose(const bool laser_power_start, const bool laser_power_stop, const bool laser_power_change, const bool feed_rate_start, const bool feed_rate_stop, const bool feed_rate_change)
virtual void stopLaserPowerBefore()
std::vector< std::pair< std::string, std::string > > programs_
virtual void layerIndexChanged()
Layer change.
virtual void finishPolygonBefore()
PostProcessor(const std::string name="Generic", const std::string description="A human readable textual output.\n""Not meant to be used by any kind of hardware.", const std::string service_name="ram/post_processors/generic")
ram_msgs::AdditiveManufacturingTrajectory trajectory_
bool verbose_comments_
ram_pose_const_iterator current_pose_
virtual void changeFeedRateAfter()
virtual void changeLaserPowerAfter()
virtual void startLaserPowerBefore()
Laser power.
virtual void afterGenerating()
virtual void startLaserPowerAfter()
virtual void stopFeedRateAfter()


ram_post_processor
Author(s): Victor Lamoine - Institut Maupertuis
autogenerated on Mon Jun 10 2019 14:50:06