📄 face.~cpp
字号:
#if !defined(__face_cpp)
#define __fine_cpp
//Inprementation of face class
#include <vcl\vcl.h>
#include <math.h>
#include <fstream.h>
#include <stdio.h>
using namespace std;
#include <string.h>
#pragma hdrstop
#include "vector.h"
#include "face.h"
#include "ReadErr.h"
//Constructor and Destructor
face::face(){
//// Parameters of Work
WorkDiameter =356.0; //InputParameter("Work Diameter[mm]", 50.0, 0.0,100.0);
WorkSizeY =170.0; //InputParameter("Work Diameter[mm]", 50.0, 0.0,100.0);
WorkPosition =0.0; //InputParameter("Distance between center of work and (0,0,0) of face[mm]",350.0,0.0,500.0);
//// Position of work is ( 0,-WorkPosition,0).
//////and (info of z-coordinate and xy-machine-coordinate)
//// Parameters of Ball endmill
//EndmillRadius =InputParameter("Radius of ball endmill[mm]",1.0,0.0,20.0);
MinAngle =-90.0;//InputParameter("Minimum limit of angle of endmill[deg]",0.0,0.0,90.0);
MaxAngle =90.0;//InputParameter("Maximum limit of angle of endmill[deg]",90.0,MinAngle,90.0);
//// Parameters of Machining
Speed =1000.0;//InputParameter("Machining Speed[mm/min]",50.0,0.01,1000.0);
JogSpeed =3000.0;//InputParameter("Sending Speed[mm/min]",500.0,0.0,1000.0);
RevSpeed =1000.0;//InputParameter("Speed of Endmill revolution[rpm]",11000.0,0.0,20000.0);
//DwellTime =InputParameter("Dwell time[sec]",1.0,0.0,100.0);
Escape =0.0;//InputParameter("Escape length[mm]",3.0,0.1,10.0);
//// Parameters of Mesh
RoughnessBetweenLines = 1.e-10;//InputParameter("Ideal Surface roughness between 2 lines[mm]",0.005,0.000001,1.0);
RoughnessAlongLine = 1.e-10;//InputParameter("Ideal Surface roughness along the line[mm]",0.001,0.000001,1.0);
X_Pitch = 2.;//Line Pitch
Y_Pitch = 0.5;//Point Pitch
////Other Parameters
//double ProgramNum = 1000;//InputParameter("NC Pragram Number ",1000,1000,9999);
ProgramNumber =1000;
//// Parameter for flycutting -----------97.11.25
wolter_thickness =0.285;
ToolRadiusFlycut =5.537-wolter_thickness;//Yin2004.03.15 5.7---5.537,InputParameter("Radius of Flycutting Tool [mm]",1.995,0.0,30.0);
WheelRadiusFlycut =224.74;//yin2004.03.15InputParameter("Radius of Flycutting Tool nose rotation[mm]",19.180,0.0,200.0);
LargeRadius = WheelRadiusFlycut - ToolRadiusFlycut;
SmallRadius = ToolRadiusFlycut;
//// Tool Type--------------980930
ToolType = 0; //0:torus,1:ball
//// Work Shape------------981008
WorkShape = 0; //0:square,1:circle, 2:ellispe
//// FeedDirection------------981027
FeedDirection = 0; //0:Y,1:X
//981028
ErrorComp=false;
ErrorCompFileName="";
imaxmax = 1;
jmaxmax = 1;
x = new double* [imaxmax];
y = new double* [imaxmax];
ToolOk= new int* [imaxmax];
jmax = new int [imaxmax];
xApproach = new double [imaxmax];
yApproach = new double [imaxmax];
xEscape = new double [imaxmax];
yEscape = new double [imaxmax];
for (int i=0;i<imaxmax;i++){
x[i] = new double [jmaxmax];
y[i] = new double [jmaxmax];
ToolOk[i] = new int [jmaxmax];
};
NumWorkAreaPoints=0;
WorkAreaPoints=NULL;
XRadiusEllipse = 100.019998;
YRadiusEllipse = 2/sqrt(2);
recipro = true;
workpiece_center_height = 0;//17.6;
};
face::~face(){
for (int i=0; i<imaxmax; i++){
delete[] x[i];
delete[] y[i];
delete[] ToolOk[i];
}
delete[] x;
delete[] y;
delete[] ToolOk;
delete[] jmax;
delete[] xApproach;
delete[] yApproach;
delete[] xEscape;
delete[] yEscape;
delete[] WorkAreaPoints;
};
// accessor
////981027 Making Face data
int face::MakeFace(){
RoughnessBetweenLines = 1.e-10;
RoughnessAlongLine = 1.e-10;
recipro_count = false;
bool f=true;
if (f) {
RoughnessBetweenLines = 1.e-10;
RoughnessAlongLine = 1.e-10;
for (int i=0; i<imaxmax; i++){
delete[] x[i];
delete[] y[i];
delete[] ToolOk[i];
};
delete[] x;
delete[] y;
delete[] ToolOk;
delete[] jmax;
delete[] xApproach;
delete[] yApproach;
delete[] xEscape;
delete[] yEscape;
//Calculate Start-Point(xs,ys).End-Point(xe,ye)
double xs = WorkDiameter/2 ;
double ys = -WorkPosition + WorkSizeY/2;
double xe = -WorkDiameter/2;
double ye = -WorkPosition - WorkSizeY/2;
// Estimate imaxmax,jmaxmax (*2 for safe)
if (FeedDirection==0){ //in case of FeedDirection==0(0:y,1:x)
imaxmax = 1.1 * (int)(WorkDiameter /XPitch(xs,ys));
jmaxmax = 1.1 * (int)(WorkSizeY /YPitch(xs,ys));
}else{
imaxmax = 1.1 * (int)(WorkSizeY /YPitch(xs,ys));
jmaxmax = 1.1 * (int)(WorkDiameter /XPitch(xs,ys));
}
//"new" about [i] (x = new int* [imaxmax] )
x = new double* [imaxmax];
y = new double* [imaxmax];
ToolOk= new int* [imaxmax];
jmax = new int [imaxmax];
xApproach = new double [imaxmax];
yApproach = new double [imaxmax];
xEscape = new double [imaxmax];
yEscape = new double [imaxmax];
//"new" about x[i][j] (x[i] = new int [jmaxmax] )
for (int i=0;i<imaxmax;i++){
x[i] = new double [jmaxmax];
y[i] = new double [jmaxmax];
ToolOk[i] = new int [jmaxmax];
}
if(FeedDirection==0){ //in case of FeedDirection==0(0:y,1:x)
//Set Start Point
double xx = xs;
double yy;
imax = 0;
while ( xx > xe ){
bool recipro_skip=false;
jmax[imax]=0;
yy=ys;
if (recipro&&recipro_count) yy=ye;
double yyNext = yy - YPitch( xx,yy);
int StopLoop = 0;
while ( ((recipro&&recipro_count)?(yy < ys):(yy > ye))
&&(!StopLoop) )
{
if ( InWorkArea( xx,yyNext) )
{
if (!isConflict(xx,yy)){
x[imax][jmax[imax] ] = xx;
y[imax][jmax[imax] ] = yy;
ToolOk[imax][jmax[imax] ] = CheckTool(xx,yy);
jmax[imax]++;
// if jmaxmax is too small , ErrorMsg.
double yr=y_roughness(xx,yy);
if(RoughnessAlongLine<yr) RoughnessAlongLine = yr;
}else{
recipro_skip=true;
};
}
else
{
// Add last point of the line //LAST POINT乮0.1,0,-0.1,-0.2,-0.4乯偵僶僌桳傝
// ,and make approach and escape
if (!(jmax[imax]==0))
{
double xr=x_roughness(xx,y[imax][0]);//y[imax][0] is dummy
if(RoughnessBetweenLines<xr) RoughnessBetweenLines = xr;
x[imax][jmax[imax] ] = xx;
y[imax][jmax[imax] ] = yyNext;
ToolOk[imax][jmax[imax] ] = CheckTool(xx,yyNext);
//make approach point
double xStart = x[imax][0];
double yStart = y[imax][0];
double gyApproach= 1.0
/sqrt(1.0+gradY(xStart,yStart)*gradY(xStart,yStart) );
xApproach[imax] = xStart;
yApproach[imax] = yStart + gyApproach*Escape;
//make escape
//make approach point
double xEnd = x[imax][jmax[imax]];
double yEnd = y[imax][jmax[imax]];
double gyEscape= 1.0
/sqrt(1.0+gradY(xEnd,yEnd)*gradY(xEnd,yEnd) );
xEscape[imax] = xEnd;
yEscape[imax] = yEnd - gyEscape*Escape;
// Add last point
jmax[imax]++;
// If jmaxmax is too small , ErrorMsg.
// If jmax[imax] isn't 0, add line.
imax++;
//If imaxmax is too small, ErrorMsg.
StopLoop = 1;
}
}; //end of else
yy = yyNext;
yyNext = yy - YPitch( xx,yy);
}; //end of 'while' (yy loop)
//Calculate xx;
xx = xx - XPitch(xx,0);
if(!recipro_skip)recipro_count = !recipro_count;
};//end of 'while'(xx loop)
}else{
//in case of FeedDirection==1(0:y,1:x)
//Set Start Point
double yy = ys;
double xx;
imax = 0;
while ( yy > ye ){
jmax[imax]=0;
xx=xs;
if (recipro&&recipro_count) xx=xe;
double xxNext = xx - XPitch( xx,yy);
int StopLoop = 0;
while ( ((recipro&&recipro_count)?(xx < xs):(xx > xe))
&&(!StopLoop) )
{
if ( InWorkArea( xxNext,yy) )
{
if (!isConflict(xx,yy)){
x[imax][jmax[imax] ] = xx;
y[imax][jmax[imax] ] = yy;
ToolOk[imax][jmax[imax] ] = CheckTool(xx,yy);
jmax[imax]++;
// if jmaxmax is too small , ErrorMsg.
double xr=x_roughness(xx,yy);
if(RoughnessAlongLine<xr) RoughnessAlongLine = xr;
};
}
else
{
// Add last point of the line
// ,and make approach and escape
if (!(jmax[imax]==0))
{
double yr=y_roughness(x[imax][0],yy);//x[imax][0]is dummy
if(RoughnessBetweenLines<yr) RoughnessBetweenLines = yr;
x[imax][jmax[imax] ] = xxNext;
y[imax][jmax[imax] ] = yy;
ToolOk[imax][jmax[imax] ] = CheckTool(xxNext,yy);
//make approach point
double xStart = x[imax][0];
double yStart = y[imax][0];
double gxApproach= 1.0
/sqrt(1.0+gradX(xStart,yStart)*gradX(xStart,yStart) );
xApproach[imax] = xStart + gxApproach*Escape;
yApproach[imax] = yStart;
//make escape
//make approach point
double xEnd = x[imax][jmax[imax]];
double yEnd = y[imax][jmax[imax]];
double gxEscape= 1.0
/sqrt(1.0+gradX(xEnd,yEnd)*gradX(xEnd,yEnd) );
xEscape[imax] = xEnd- gxEscape*Escape;
yEscape[imax] = yEnd ;
// Add last point
jmax[imax]++;
// If jmaxmax is too small , ErrorMsg.
// If jmax[imax] isn't 0, add line.
imax++;
//If imaxmax is too small, ErrorMsg.
StopLoop = 1;
}
}; //end of else
xx = xxNext;
xxNext = xx - XPitch( xx,yy);
}; //end of 'while' (xx loop)
//Calculate yy;
yy = yy - YPitch(0,yy);
recipro_count = !recipro_count;
};//end of 'while'(yy loop)
}; //end of 'if'(FeedDireciton)
return(1);
}
else{ return(0);}
}
////Convert (i,j) to (x,y,z)
vector face::FacePosition( int i, int j){
return( GetPosition( x[i][j],y[i][j] ) );
}
////tool correction at the point
vector face::MachinePosition(vector point){
vector result;
vector c_hosei; //2000.02.09 morishin
vector center(0.0, -WorkPosition, GetZ(0,-WorkPosition));
if (ToolType==1){
result = point + ToolRadiusFlycut*NormalVector(point);
c_hosei = center + ToolRadiusFlycut*NormalVector(center);
}else{
// change for fly-cutting ( donuts-like tool)---------------97.Nov.25
//980911 for fly-cutting of NullMirror
vector hosei;
vector normal = NormalVector(point);
vector C1=SmallRadius*normal;
vector n2=normal;
n2.setY(0.);
vector C2=LargeRadius*n2.normalize();
hosei = C1+C2;
result = point + hosei;
normal = NormalVector(center);
C1=SmallRadius*normal;
n2=normal;
n2.setY(0.);
C2=LargeRadius*n2.normalize();
hosei = C1+C2;
c_hosei = center + hosei;
};
//-------------------------------------------------------------------
//2000.02.09
return (result-c_hosei);
}
////Machining speed correction
double face::MachineSpeed(const vector& prev,const vector& now){
/*double FacePointMovement
= distance2( prev, now );
double MachineMovement
= distance2( MachinePosition(prev), MachinePosition(now) );
double SpeedRatio = MachineMovement / FacePointMovement; */
//double t= Speed* SpeedRatio;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -