13 #include <geometry_msgs/Transform.h> 14 #include "fanuc_post_processor_library/fanuc_post_processor_library.hpp" 16 #include <fanuc_grinding_post_processor/PostProcessorService.h> 26 bool postProcessor(fanuc_grinding_post_processor::PostProcessorService::Request &req,
27 fanuc_grinding_post_processor::PostProcessorService::Response &res)
32 std::vector<Eigen::Isometry3d, Eigen::aligned_allocator<Eigen::Isometry3d> > robot_poses_eigen;
34 for (geometry_msgs::Pose &tmp : req.RobotPoses)
36 Eigen::Isometry3d pose;
38 pose.translation() += Eigen::Vector3d(0, 0, req.TrajectoryZOffset);
39 robot_poses_eigen.push_back(pose);
42 if (robot_poses_eigen.empty())
44 res.ReturnStatus =
false;
45 res.ReturnMessage =
"Trajectory is empty";
49 if (robot_poses_eigen.size() != req.IsGrindingPose.size())
51 res.ReturnStatus =
false;
52 res.ReturnMessage =
"Trajectory is not correct";
56 FanucPostProcessor fanuc_pp;
57 fanuc_pp.setProgramName(req.ProgramName);
58 fanuc_pp.setProgramComment(req.Comment);
61 const double grinding_disk_DO(3);
64 fanuc_pp.appendDigitalOutput(grinding_disk_DO,
true);
65 fanuc_pp.appendWait(1);
68 fanuc_pp.appendPoseCNT(FanucPostProcessor::JOINT, robot_poses_eigen[0], 1, speed, FanucPostProcessor::PERCENTAGE, 100);
70 for (
unsigned i = 1; i < robot_poses_eigen.size(); ++i)
73 if (req.IsGrindingPose[i] == 0 && req.IsGrindingPose[i - 1] == 1)
75 fanuc_pp.appendDigitalOutput(grinding_disk_DO,
false);
76 fanuc_pp.appendWait(1);
80 else if (req.IsGrindingPose[i] == 1 && req.IsGrindingPose[i - 1] == 0)
82 fanuc_pp.appendDigitalOutput(grinding_disk_DO,
true);
83 fanuc_pp.appendWait(1);
86 fanuc_pp.appendPoseCNT(FanucPostProcessor::JOINT, robot_poses_eigen[i], i + 1, speed, FanucPostProcessor::PERCENTAGE, 100);
90 fanuc_pp.generateProgram(program);
93 std::ofstream tp_program_file;
94 std::string file_location = req.ProgramLocation + req.ProgramName +
".ls";
97 tp_program_file.open(file_location.c_str(), std::ios::out);
99 if (tp_program_file.bad())
101 res.ReturnStatus =
false;
102 res.ReturnMessage =
"Cannot open/create TP program file";
106 tp_program_file << program;
107 tp_program_file.close();
111 res.ReturnStatus =
true;
112 res.ReturnMessage =
"Program generated";
116 ROS_INFO_STREAM(
"Try to upload program on IP address: " << req.IpAdress);
117 if (!fanuc_pp.uploadToFtp(req.IpAdress))
119 res.ReturnStatus =
false;
120 res.ReturnMessage =
"Cannot upload the program on IP address: " + req.IpAdress;
124 res.ReturnStatus =
true;
125 res.ReturnMessage =
"Program generated and uploaded";
129 int main(
int argc,
char **argv)
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)
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)