📄 face.~cpp
字号:
double t= Speed;
if (t>1.1*Speed) t=1.1*Speed;
return(t);
}
////About Mesh
int face::InWorkArea(double xx, double yy){
//WorkShape;//0:square,1:circle, 2: ellipse, 4:convex_polygon
if (WorkShape==1){
//Shape of Work-Area is circle.
int temp=( (xx*xx + (yy+WorkPosition)*(yy+WorkPosition))
< (WorkDiameter * WorkDiameter)/4 );
return ( temp );
}else if(WorkShape==2){
//XRadiusEllipse
//Shape of Work-Area is ellipse.
int temp=( (xx<WorkDiameter/2.)&&
(xx>-WorkDiameter/2.)&&
(xx*xx/XRadiusEllipse/XRadiusEllipse +
yy*yy/YRadiusEllipse/YRadiusEllipse
< 1 ));
return ( temp );
}else if(WorkShape==4){
double xa,ya,xb,yb;
double sign;
bool judge;
if (NumWorkAreaPoints<0)
{
return (false);
};
xa = xx-WorkAreaPoints[NumWorkAreaPoints-1].getX();
ya = yy-WorkAreaPoints[NumWorkAreaPoints-1].getY();
xb = WorkAreaPoints[0].getX()-WorkAreaPoints[NumWorkAreaPoints-1].getX();
yb = WorkAreaPoints[0].getY()-WorkAreaPoints[NumWorkAreaPoints-1].getY();
sign = xa*yb-xb*ya;
judge=true;
for (int i=0;i<NumWorkAreaPoints-1;i++)
{
xa = xx-WorkAreaPoints[i].getX();
ya = yy-WorkAreaPoints[i].getY();
xb = WorkAreaPoints[i+1].getX()-WorkAreaPoints[i].getX();
yb = WorkAreaPoints[i+1].getY()-WorkAreaPoints[i].getY();
if (sign*(xa*yb-xb*ya)<=0) {
judge = false;
};
};
return ((int)judge);
}else {
//Shape of Work-Area is square.
int temp = ((xx<WorkDiameter/2.)&&(xx>-WorkDiameter/2.)&&
((yy+WorkPosition)<WorkSizeY/2.)&&((yy+WorkPosition)>-WorkSizeY/2.));
return ( temp );
};
}
////X-direction pitch of mesh ;[mm]
double face::XPitch(double xx,double yy){
//double DistanceBetweenLines
// = 2*sqrt( RoughnessBetweenLines*( 2*EndmillRadius - RoughnessBetweenLines) );
/*980520
// change for fly-cutting-----------------------------------------
double DistanceBetweenLines
= 2*sqrt( RoughnessBetweenLines*( 2*(LargeRadius+SmallRadius) - RoughnessBetweenLines) );
//----------------------------------------------------------------
////Caution!!////////////// yyyy must be define later.
double yyyy= - WorkPosition;
vector nograd = NoGradientVector(xx,yyyy );
if ( nograd.length() < 0.99 ) { nograd = NoGradientVector(xx,(yyyy + WorkDiameter/4.0));};
double xp = DistanceBetweenLines *( nograd*vector(1,0,0) );
if (xp<0.0){ xp=(-xp);};
return(xp);
980520*/
//Caluculate of Roughness
//FeedDirection(0:y,1:x)
return ((recipro&&FeedDirection==1)&&recipro_count)?(-X_Pitch):(X_Pitch);
}
////Y-direction pitch of mesh ;[mm]
double face::YPitch(double xx,double yy){
/*980520
double dzdy = gradY(xx,yy);
double dzdydy = gradYY(xx,yy);
double yp = 2*sqrt(2*RoughnessAlongLine *sqrt( 1+dzdy*dzdy )/dzdydy );
// return( 2*sqrt( 2 *RoughnessAlongLine *sqrt(yy*yy +4*p*p ) ) );
return(yp);
980520*/
//Caluculate of Roughness
//FeedDirection(0:y,1:x)
return ((recipro&&FeedDirection==0)&&recipro_count)?(-Y_Pitch):(Y_Pitch);
}
//// Check Tool
int face::CheckTool(double xx,double yy){
//Calculate angle
double angle = ToolAngle(xx,yy);
if ( ( angle>MinAngle )&&( angle<MaxAngle ) ) {
return(1);
}
else {
return(0);
}
//return(1); //980930 for nulmirror
/*double angle = acos( NormalVector(xx,yy) * vector(0,0,1) );
angle = angle * 180 /M_PI ;
if ( ( angle>MinAngle )&&( angle<MaxAngle ) ) {
return(1);
}
else {
return(0);
} */
};
double face::ToolAngle(double xx,double yy){
//ball/torus
//z=zTop
double angle;
if (ToolType==0){
//torus tool 990322
angle = acos( NormalVector(xx,yy) * vector(0,1,0) );
angle = 90-angle * 180. /M_PI ;
}else if (ToolType==1){
//ball tool (in case (tool//z-axis)??) 990322
angle = acos( NormalVector(xx,yy) * vector(0,0,1) );
//ball tool (in case (tool axis//y-axis)) 990322
//angle = acos( NormalVector(xx,yy) * vector(0,1,0) );
angle = angle * 180. /M_PI ;
}else {
angle =0.;
};
return angle;
};
//// Input
/*
double face::InputParameter(const char* name, double init,double lower,double upper){
int value=1;
double parameter;
while (value){
cout <<"Input "<< name << " . ("<< lower<< "<= x <=" << upper << " )" <<endl;
cout <<"Defalt = " << init << endl;
double temp;
cin >> temp;
if ((temp<=upper)&&(temp>=lower)){
value = 0;
parameter = temp;
};
}
return (parameter);
};
void face::SetFaceParameters(){
//Set Paramaters
//// Parameters of Work
WorkDiameter =InputParameter("Work Diameter[mm]", 50.0, 0.0,100.0);
WorkPosition =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 =InputParameter("Minimum limit of angle of endmill[deg]",0.0,0.0,90.0);
MaxAngle =InputParameter("Maximum limit of angle of endmill[deg]",90.0,MinAngle,90.0);
//// Parameters of Machining
Speed =InputParameter("Machining Speed[mm/min]",50.0,0.01,1000.0);
JogSpeed =InputParameter("Sending Speed[mm/min]",500.0,0.0,1000.0);
RevSpeed =InputParameter("Speed of Endmill revolution[rpm]",11000.0,0.0,20000.0);
//DwellTime =InputParameter("Dwell time[sec]",1.0,0.0,100.0);
Escape =InputParameter("Escape length[mm]",3.0,0.1,10.0);
//// Parameters of Mesh
RoughnessBetweenLines = InputParameter("Ideal Surface roughness between 2 lines[mm]",
0.005,0.000001,1.0);
RoughnessAlongLine = InputParameter("Ideal Surface roughness along the line[mm]",
0.001,0.000001,1.0);
////Other Parameters
double ProgramNum =InputParameter("NC Pragram Number ",1000,1000,9999);
ProgramNumber =(int)ProgramNum;
//// Parameter for flycutting -----------97.11.25
ToolRadiusFlycut =InputParameter("Radius of Flycutting Tool [mm]",1.995,0.0,30.0);
WheelRadiusFlycut =InputParameter("Radius of Flycutting Tool nose rotation[mm]",19.180,0.0,200.0);
LargeRadius = WheelRadiusFlycut - ToolRadiusFlycut;
SmallRadius = ToolRadiusFlycut;
};//end of SetFaceParameter
*/
//// Output
int face::WriteAPoint(ofstream& fout, vector pos, const double speed){
//fout << "G01G90X "<< pos.getX() << " Y " << pos.getY() <<" Z "<<pos.getZ()
// << " F " <<speed << ';' << endl;
char cmd[256];
sprintf(cmd, "G01G90X %10.5lf Y %10.5lf Z %10.5lf F %10.5lf;\n",
pos.getX(), pos.getY(), pos.getZ(),speed);
/*sprintf(cmd, "X %.3lf Y %.3lf Z %.3lf \n",
pos.getX(), pos.getY(), pos.getZ()+workpiece_center_height);*/
fout << (char*)cmd;
return(1);
};
/*int face::WriteAPoint(ofstream& fout, vector pos, const double v){
fout << pos.getX() <<' '<< pos.getY()<<' '<<pos.getZ()<<' '<<v << endl;
return(1);
};*/
int face::NCDataOut(const char* filename){
//ErrorComp偺僠僃僢僋
if (ErrorComp){
bool judge=true;
for (int i=0;i<imax;i++){
for (int j=0;j<jmax[i];j++){
if (FeedDirection==0){
judge = judge && (fabs(x[i][j]-xx_lat[i])<1.e-6);
judge = judge && (fabs(y[i][j]-yy_lat[j])<1.e-6);
judge = judge && (imax==get_np_lat());
judge = judge && (jmax[i]==get_nq_lat());
}else{
judge = judge && (fabs(x[i][j]-xx_lat[j])<1.e-6);
judge = judge && (fabs(y[i][j]-yy_lat[i])<1.e-6);
judge = judge && (jmax[i]==get_np_lat());
judge = judge && (imax==get_nq_lat());
};
}
};
if (judge==false) {
ShowMessage("Error about ErrorComp in face::NCDataOut !");
return 0;
};
};
int ToolSafe= 1;
for (int i=0;i<imax;i++){
for (int j=0;j<jmax[i];j++){
ToolSafe = (ToolSafe && (ToolOk[i][j]) );
}
}
if (!ToolSafe){
if(Application->MessageBox ( "Tool angle is over range!!","Caution!",MB_YESNO)==IDNO)
return(0);
};
char text[256];
//open file
ofstream fout;
fout.open(filename);
if (fout==NULL)
{
sprintf(text, "Can't open file: %s ", filename);
//cout << text;
return(0);
}
else
{
sprintf(text, "The file to output NC program is : %s \n", filename);
//cout << text;
/////////////////////////////////
//prepare
fout.precision(7);
//fout.width(9);
////Program Initialize
fout << '%' << endl;
fout << 'O' << ProgramNumber << ';' << endl;
/* ////parameters
if (!ToolSafe){
fout << "(Attention!! : Tool Angle is over limit!)"<<endl<<endl;
};
fout << "(Work Diameter[mm] :" << WorkDiameter << ");" << endl;
fout << "(Work Position[mm] :0," << -WorkPosition << ",0);" << endl;
//fout << "(Endmill Radius[mm] :" << EndmillRadius << ");" << endl;
//Parameter for flycutting -----------97.11.25
fout << "(Radius of flycutting tool[mm] :" << ToolRadiusFlycut << ");" << endl;
fout << "(=EndmillRadius);" << endl;
fout << "(Radius of flycutting wheel[mm] :" << WheelRadiusFlycut << ");" << endl;
fout << "(Larger radius of donuts face[mm] :" << LargeRadius << ");" << endl;
fout << "(Smaller radius of donuts face[mm] :" << SmallRadius << ");" << endl;
fout << "(ToolType 0:torus,1:ball ;" << ToolType << ");" << endl;
fout << "(WorkShape 0:square,1:circle,2:ellips,4:polygon ;" << WorkShape << ");" << endl;
fout << "(wolter_thickness;" << wolter_thickness << ");" << endl;
fout << "(FeedDirection 0:Y,1:X ;" << FeedDirection << ");" << endl;
fout << "(ErrorComp 0:false,1:true ;" << int(ErrorComp) << ");" << endl;
fout << "(ErrorCompFileName :" << ErrorCompFileName.c_str() << ");" << endl;
fout << "(Minimum tool angle[deg] :" << MinAngle << ");" << endl;
fout << "(Maximum tool angle[deg] :" << MaxAngle << ");" << endl;
fout << "(Machining speed[mm/min]:" << Speed << ");" << endl;
fout << "(Sending speed[mm/min] :" << JogSpeed << ");" << endl;
fout << "(Endmill revolution speed[rpm] :" << RevSpeed <<");"<< endl;
fout << "(Escape length[mm] :" << Escape << ");" << endl;
fout << "(Ideal Surface roughness between 2 lines[mm] :"
<< RoughnessBetweenLines << ");" << endl;
fout << "(Ideal Surface roughness along the line[mm] :"
<< RoughnessAlongLine << ");" << endl<<endl;
vector CenterPoint(0.0, -WorkPosition, GetZ(0,-WorkPosition));
vector MachineCenterPoint = MachinePosition(CenterPoint);
fout << "(Machine coordinate at center of work on machining face is :"
<< MachineCenterPoint.getX() <<","
<< MachineCenterPoint.getY() <<","
<< MachineCenterPoint.getZ() << ");" << endl;
//fout << "(Machine coordinate at center of work on machining face is :"
// << "0,"<< WorkPosition <<","<< GetZ(0,WorkPosition) << ");" << endl;
WriteFaceName(fout);
WriteParameters(fout);
*/
////machine setting
////////set endmill speed
fout << 'S' << RevSpeed << ';' << endl;
////////coolant start
fout << "M17;" << endl;
////////endmill start
fout << "M03;" << endl;
////////ELID on
fout << "M63;" << endl;
////////set machining start point coordinate
////end of machine setting
vector Approach,Escape;
vector now,prev;
//machining-time predict
double MachiningTime=0;
// fout << "G01" <<endl;
//cutting depth setting 97.Nov.25 ------------------------------------
//// set initial point
vector temp = MachinePosition(GetPosition(xApproach[0],yApproach[0])) ;
temp.setZ(10.);
Approach = MachinePosition(GetPosition(xApproach[0],yApproach[0])) ;
WriteAPoint(fout, temp, 3000. );
WriteAPoint(fout, Approach, 1000. );
//// set cutting depth(=0)
char cmd[256];
sprintf(cmd, "G92Z%9.5lf;",Approach.getZ());
fout << cmd << endl;
//fout << "G92Z" << Approach.getZ() <<';'<<endl;
//// reset initial point
WriteAPoint(fout, Approach, 1000. );
//--------------------------------------------------------------------
//x_loop
for(int i=0;i<imax;i++)
{
fout << "(L" << (i+1) <<");" << endl;
////////ELID ON 990117 moriyasu
//fout << "M24;" << endl;
//// set initial point
//------------------------ErrorComp 981028
if (ErrorComp){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -