post_processor.cpp
Go to the documentation of this file.
1 /************************************************
2 Post processor using fanuc_post_processor_library.
3 This file which operate post processor represents
4 one node of the entire demonstrator
5 ************************************************/
6 
7 // ROS headers
8 #include <ros/ros.h>
9 #include <ros/package.h>
10 #include <ros/service.h>
13 #include <geometry_msgs/Transform.h>
14 #include "fanuc_post_processor_library/fanuc_post_processor_library.hpp"
15 
16 #include <fanuc_grinding_post_processor/PostProcessorService.h> // Description of the Service we will use
17 
19 
26 bool postProcessor(fanuc_grinding_post_processor::PostProcessorService::Request &req,
27  fanuc_grinding_post_processor::PostProcessorService::Response &res)
28 {
29  // Get parameters from the message and print them
30  //ROS_INFO_STREAM(std::endl << req);
31 
32  std::vector<Eigen::Isometry3d, Eigen::aligned_allocator<Eigen::Isometry3d> > robot_poses_eigen;
33 
34  for (geometry_msgs::Pose &tmp : req.RobotPoses)
35  {
36  Eigen::Isometry3d pose;
37  tf::poseMsgToEigen(tmp, pose);
38  pose.translation() += Eigen::Vector3d(0, 0, req.TrajectoryZOffset);
39  robot_poses_eigen.push_back(pose);
40  }
41 
42  if (robot_poses_eigen.empty())
43  {
44  res.ReturnStatus = false;
45  res.ReturnMessage = "Trajectory is empty";
46  return true;
47  }
48 
49  if (robot_poses_eigen.size() != req.IsGrindingPose.size())
50  {
51  res.ReturnStatus = false;
52  res.ReturnMessage = "Trajectory is not correct";
53  return true;
54  }
55 
56  FanucPostProcessor fanuc_pp;
57  fanuc_pp.setProgramName(req.ProgramName);
58  fanuc_pp.setProgramComment(req.Comment);
59 
60  unsigned int speed;
61  const double grinding_disk_DO(3);
62 
63  // First pose is a machining pose, we have to switch on the DO
64  fanuc_pp.appendDigitalOutput(grinding_disk_DO, true);
65  fanuc_pp.appendWait(1);
66  //speed = req.MachiningSpeed * 100;
67  speed = 30;
68  fanuc_pp.appendPoseCNT(FanucPostProcessor::JOINT, robot_poses_eigen[0], 1, speed, FanucPostProcessor::PERCENTAGE, 100);
69 
70  for (unsigned i = 1; i < robot_poses_eigen.size(); ++i)
71  {
72  // if the new point is an extrication point and the old one was a machining point, we have to switch off the DO
73  if (req.IsGrindingPose[i] == 0 && req.IsGrindingPose[i - 1] == 1)
74  {
75  fanuc_pp.appendDigitalOutput(grinding_disk_DO, false);
76  fanuc_pp.appendWait(1);
77  speed = 50;//req.ExtricationSpeed * 100;
78  }
79  // if the new point is an machining point and the old one was a extrication point, we have to switch on the DO
80  else if (req.IsGrindingPose[i] == 1 && req.IsGrindingPose[i - 1] == 0)
81  {
82  fanuc_pp.appendDigitalOutput(grinding_disk_DO, true);
83  fanuc_pp.appendWait(1);
84  speed = 30;//req.MachiningSpeed * 100;
85  }
86  fanuc_pp.appendPoseCNT(FanucPostProcessor::JOINT, robot_poses_eigen[i], i + 1, speed, FanucPostProcessor::PERCENTAGE, 100);
87  }
88 
89  std::string program;
90  fanuc_pp.generateProgram(program);
91  //ROS_INFO_STREAM("This is the generated program:\n\n" << program);
92 
93  std::ofstream tp_program_file;
94  std::string file_location = req.ProgramLocation + req.ProgramName + ".ls";
95 
96 
97  tp_program_file.open(file_location.c_str(), std::ios::out);
98  // We check if file have been opened correctly
99  if (tp_program_file.bad())
100  {
101  res.ReturnStatus = false;
102  res.ReturnMessage = "Cannot open/create TP program file";
103  return true;
104  }
105 
106  tp_program_file << program; // We put program into TP program file
107  tp_program_file.close();
108 
109  if (!req.Upload)
110  {
111  res.ReturnStatus = true;
112  res.ReturnMessage = "Program generated";
113  return true;
114  }
115 
116  ROS_INFO_STREAM("Try to upload program on IP address: " << req.IpAdress);
117  if (!fanuc_pp.uploadToFtp(req.IpAdress))
118  {
119  res.ReturnStatus = false;
120  res.ReturnMessage = "Cannot upload the program on IP address: " + req.IpAdress;
121  return true;
122  }
123 
124  res.ReturnStatus = true;
125  res.ReturnMessage = "Program generated and uploaded";
126  return true;
127 }
128 
129 int main(int argc, char **argv)
130 {
131  ros::init(argc, argv, "post_processor");
132  node.reset(new ros::NodeHandle);
133 
134  // Create service server and wait for incoming requests
135  ros::ServiceServer service = node->advertiseService("post_processor_service", postProcessor);
137  spinner.start();
138 
139  while (node->ok())
140  {
141  sleep(1);
142  }
143  spinner.stop();
144  return 0;
145 }
void poseMsgToEigen(const geometry_msgs::Pose &m, Eigen::Affine3d &e)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void spinner()
int main(int argc, char **argv)
boost::shared_ptr< ros::NodeHandle > node
#define ROS_INFO_STREAM(args)
bool postProcessor(fanuc_grinding_post_processor::PostProcessorService::Request &req, fanuc_grinding_post_processor::PostProcessorService::Response &res)


post_processor
Author(s): Kévin Bolloré, Victor Lamoine - Institut Maupertuis
autogenerated on Thu Dec 19 2019 03:38:19