Phần phụ lục báo cáo

Một phần của tài liệu Báo cáo nghiên cứu ứng dụng hệ thống tính toán song song hiệu nâng cao để lập trình gia công các bề mặt khuôn mẫu trên máy công cụ CNC (Trang 144 - 432)

5.1. Phụ lục 1: Th− viện tính đ−ờng dụng cụ chạy trên hệ thống song song hiệu n¨ng cao

5.2. Phụ lục 2: Mã nguồn ch−ơng trình phần mềm tính toán phân chia và truyền/nhận dữ liệu cho hệ thống máy tính song song hiệu năng cao và máy phay CNC 5 trôc

5.3. Phụ lục 3: Bản vẽ thiết kế các bộ khuôn

5.4. Phụ lục 4: Hồ sơ đo kiểm thông số hình học các bộ khuôn

Phụ lục 1 - Th− viện tính đ−ờng dụng cụ chạy trên hệ thống song song hiệu năng cao

1.1. Môdun xấp xỉ các đường cong thành Polyline cơ sở //---Xap xi Arc thanh Polyline---//

AcGePoint3dArray

projectArc( AcDbArc *pArc) {

AcGePoint3d ptS,ptE;

double length,step;

AcGePoint3dArray ptArr;

AcGePoint3d temp;

pArc->getStartPoint(ptS);

pArc->getEndPoint(ptE);

pArc->getDistAtPoint(ptE,length);

step=length/10;

ptArr.append(ptS);

for(int j=1;j<=10;j++) {

pArc->getPointAtDist(j*step,temp);

ptArr.append(temp);

}

return ptArr;

}

//---Xap xi Circle thanh Polyline---//

AcGePoint3dArray projectCircle(AcDbCircle *pCir) { AcGePoint3d ptS,ptE;

double rad,length,step;

AcGePoint3dArray ptArr;

rad=pCir->radius();

length=2*PI*rad;

pCir->getStartPoint(ptS);

step=length/50;

ptArr.append(ptS);

for(int j=1;j<=50;j++) {

pCir->getPointAtDist(j*step,ptE);

ptArr.append(ptE);

}

return ptArr;

}

//---Xap xi Ellipse thanh polyline---//

AcGePoint3dArray projectEllipse(AcDbEllipse *pElp) {

AcGePoint3d ptS,ptE;

double length,step;

AcGePoint3dArray ptArr;

AcGePoint3d temp;

pElp->getStartPoint(ptS);

pElp->getEndPoint(ptE);

pElp->getDistAtPoint(ptE,length);

step=length/10;

ptArr.append(ptS);

for(int j=1;j<=10;j++) {

pElp->getPointAtDist(j*step,temp);

ptArr.append(temp);

}

return ptArr;

}

//---Xap xi Spline thanh polyline---//

AcGePoint3dArray projectSpline(AcDbSpline* pSpl) {

//acedAlert("Dang Xap xi Spline....");

AcGePoint3d ptS,ptE;

double length,step;

AcGePoint3dArray ptArr;

AcGePoint3d temp;

pSpl->getStartPoint(ptS);

pSpl->getEndPoint(ptE);

pSpl->getDistAtPoint(ptE,length);

for(int j=1;j<=10;j++) {

pSpl->getPointAtDist(j*step,temp);

ptArr.append(temp);

}

return ptArr;

}

1.2. Môdun nối các đường cơ sở thành Polyline khép kín void

Join (AcDbRegion *pRegion, AcDbVoidPtrArray *polyListResult,AcGeDoubleArray

*zUpArr) {

AcDbVoidPtrArray entset;

AcDbVoidPtrArray pVoidPtrArray;

AcDbObjectId id,entId;

Acad::ErrorStatus es;

///////////////////////PHA TUNG MOT REGION///////////////////

if((es = pRegion->explode(entset)) != Acad::eOk) {

ads_alert("\nKhong explode duoc va return !!!");

return;

}

AcDbEntity *ent;

AcGePoint3dArray Arr1;

ent = AcDbEntity::cast((AcRxObject*)entset.first());

if (ent == NULL) {return;}

if (ent->isKindOf(AcDbLine::desc())) {

AcGePoint3d start,end;

AcDbLine *pLine;

pLine = AcDbLine::cast(ent);

start = pLine->startPoint();

end = pLine->endPoint();

pLine->close();

Arr1.append(start);

Arr1.append(end);

} else

{ ads_alert("\nChua xap xi dang duong nay.");

}

ent->close();

for (int i=1;i<entset.length();i++) {

AcGePoint3dArray points;

AcGePoint3d start,end;

AcDbEntity *ent2;

AcDbVoidPtrArray polyResult;

AcGePoint3dArray Arr2,tg;

ent2 = AcDbEntity::cast((AcRxObject*)entset[i]);

if (ent2 == NULL) {return;}

if (ent2->isKindOf(AcDbLine::desc())) {

AcDbLine *pLine1;

pLine1 = AcDbLine::cast(ent2);

start = pLine1->startPoint();

end = pLine1->endPoint();

pLine1->close();

Arr2.append(start);

Arr2.append(end);

}

else

{ads_alert("\nChua xap xi dang duong nay.");

}

AcGeDoubleArray zUpArrtemp;

points = join2Poly(Arr1,Arr2, &polyResult,&zUpArrtemp);

polyListResult->append(polyResult);

Arr1 = points;

zUpArr->append(zUpArrtemp);

} }

{

AcDbObjectId id;

Acad::ErrorStatus es;

id=region->objectId();

AcDbVoidPtrArray ptrArrRegion;

ptrArrRegion = createNewRegion(region);

//Tim cach xoa Region old Da xoa xong

acdbOpenObject(region,id,AcDb::kForWrite);

region->erase(); //OK region->close();

long len=ptrArrRegion.length();

while(len != 0) {

AcDbRegion* pRegionNew;

pRegionNew = (AcDbRegion*) ptrArrRegion[len-1];

AcDbVoidPtrArray polyList;

AcGeDoubleArray zUpArrtemp;

Join(pRegionNew,&polyList,&zUpArrtemp);

pRegionNew->close();

for(int i=0; i<polyList.length(); i++) {

AcDbEntity *pObj;

pObj = (AcDbEntity*) polyList[i];

AcDbObjectId polyId;

polyId=pObj->objectId();

acdbOpenObject(pObj,polyId,AcDb::kForWrite);

pObj->upgradeOpen();

pObj->setColorIndex(1);

es = postToDatabase(pObj,id);

if (es != Acad::eOk) {

ads_alert("\nError (Loi) postToDatabase!");

pObj->close();

return;

}

pObj->close();

}

polyList1->append(polyList);

zUpArr->append(zUpArrtemp);

len--;

}

}

AcGePoint3dArrayjoin2Poly (AcGePoint3dArray a1, AcGePoint3dArray a2, AcDbVoidPtrArray

*polyReturn, AcGeDoubleArray *pUpArr) {

if (a1.isEmpty()) {

ads_alert("\n Arr1 RONG!");

}

if (a2.isEmpty()) {

ads_alert("\n Arr2 RONG!");

}

AcGePoint3dArray ptArr,tg,Arr1;

AcDbObjectId id;

if ((a1.last() == a2.first()) && (a1.first() != a2.last())) {

ptArr = a1;

tg = a2.removeFirst();

ptArr.append(tg);

} else

{

if (a1.first() == a2.first() && (a1.last() != a2.last())) {

tg = a1.reverse();

ptArr = tg;

tg = a2.removeFirst();

ptArr.append(tg);

}

else {

ptArr = a1;

tg =a2.removeLast();

ptArr.append(tg);

}

else {

if (a1.first() == a2.last() && (a1.last() != a2.first())) {

tg = a1.reverse();

ptArr = tg;

tg = a2.removeLast();

ptArr.append(tg);

}

else {

if(((a1.first() == a2.first()) && (a1.last() == a2.last ())) ||

((a1.first() == a2.last()) && (a1.last() == a2.first()))) {

ptArr = a1;

Arr1 = ptArr;

double temp;

AcGePoint3d tempPoint;

tempPoint = Arr1.first();

temp = tempPoint.z;

pUpArr->append(temp);

AcDb2dPolyline *pPline = new AcDb2dPolyline(AcDb::k2dSimplePoly, Arr1,0.0,Adesk::kTrue);

pPline->makeClosed();

pPline->close();

polyReturn->append(pPline);

} else {

ptArr = a2;

} }

}

} }

return ptArr; }

1.3. Môdun xuất kết quả tính toán ra dữ liệu dạng DAT cho hệ thống tính toán song song hiệu năng cao

///////////////////mainGcodeFile//////////////////////////////////

int mainGcodeFile(FILE *f,simpleCut* sCut,ads_real zUp,ads_real speed,ads_real speed1) {

if (f==NULL) {

ads_printf("Can't write to G-code files");

return RTERROR;

}

int len=sCut->ptArr.length();

if (len <= 1) return RTNORM;

double pt[3];

for (int i=1;i<len;i++) {

pt[0]=sCut->ptArr[i].x;

pt[1]=sCut->ptArr[i].y;

pt[2]=sCut->ptArr[i].z+zUp;

fwrite(pt,sizeof(pt),1,f);

}

return RTNORM;

}

///////////////////CreateGcodeFile/////////////

int

CreateGcodeFile(simpleCut** scList,techPara* tPara) {

struct resbuf result;

if (ads_getfiled("Creat Dat file",NULL,"dat",1+2,&result)!=RTNORM) return RTERROR;

FILE *f;

f=fopen(result.resval.rstring,"wb");

free(result.resval.rstring);

{

if((rc = mainGcodeFile(f,temp,tPara->zUp,tPara->speed,tPara-

>speed1)!=RTNORM)) {

acutPrintf("Creat Dat files not successfully\n");

fclose(f);

return RTERROR;

} }

fclose(f);

acutPrintf("\n Creat Dat file successful ");

return RTNORM;

}

// tao file chua du lieu duong chay dao

void createToolPathFile (simpleCut** scList,FILE* f) {

for (simpleCut* temp=(*scList);temp!=NULL;temp=temp->next) {

fwrite(temp,sizeof(simpleCut*),1,f);

} }

1.4. Môdun tính đường chạy dao cơ sở dạng song song Parallel // --- Phan tinh toan cho Parallel ---

int createParaFunc(simpleCut** scList,dataSlice* dSlice,techPara* tPara) {

AcDbVoidPtrArray curves,pPlines ;

pPlines = complementToolRadius(dSlice,tPara->toolRad);

if (pPlines.length()==2)

pPlines = checkDSlice(pPlines);

//int len = dSlice->curves.length();

int len = pPlines.length();

AcDbVoidPtrArray ents = createParallelCutting(dSlice->p2dPl,tPara);

for (int i =0;i<ents.length();i++) {

// tim cac giao diem cua mot duong Xline

AcDbXline* pXline;

AcDbEntity* ent;

ent = (AcDbEntity*) ents[i];

if ((pXline = AcDbXline::cast(ent)) ==NULL ) return RTNORM;

curves = pPlines;

curves.append(dSlice->p2dPl);

AcGePoint3dArray resIntArr = getIntersectPoints(curves,pXline);

int numPoints = resIntArr.length();

if (numPoints>1)

{ resIntArr = sortArrayPoint(resIntArr);

curves=NULL;

AcGeIntArray flag;

flag.setLogicalLength(numPoints-1);

for (int j=0;j<numPoints-1;j++ ) flag[j] = 0;

curves.append(pPlines[0]);

curves.append(dSlice->p2dPl);

getflagArray(curves,resIntArr,&flag);

curves = NULL;

curves.append(pPlines[0]);

if (len>1)

for (int j=1;j<len;j++) {

if (dSlice->flag[j] == 0) curves.append(pPlines[j]);

if (dSlice->flag[j] == 1) {

getflagArray(curves,resIntArr,&flag);

curves = NULL;

curves.append(pPlines[j]);

}

if (j==len - 1)

getflagArray(curves,resIntArr,&flag);

} if (len == 1)

getflagArray(curves,resIntArr,&flag);

simpleCut *newCt =(simpleCut*)calloc(1,sizeof(simpleCut));

newCt->ptArr=resIntArr;

newCt->flag = flag;

addsimpleCut(scList,newCt);

pXline->close();

} }

if (tPara->bound == Adesk::kTrue ) { simpleCut* newCt;

newCt=createsimpleCut(dSlice->p2dPl,tPara->height);

addsimpleCut(scList,newCt);

for (i=0;i<pPlines.length();i++) {

AcDbEntity* ent;

ent = (AcDbEntity*) pPlines[i];

AcDb2dPolyline *pPl;

if ((pPl = AcDb2dPolyline ::cast (ent))!=NULL) {

newCt=createsimpleCut(pPl,tPara->height);

addsimpleCut(scList,newCt);

} }

}

eraseEnts(pPlines);

eraseEnts(dSlice->curves);

return RTNORM;

}

//////////////////createParallelCutting/////////////

AcDbVoidPtrArray

createParallelCutting(AcDb2dPolyline *p2dPl,techPara* tPara) {

if (p2dPl->isClosed()!=Adesk::kTrue) {

acutPrintf("Polyline bao ngoai chua dong");

return NULL;

}

ads_real step;

step = tPara->step;

///////Duyet lay cac dinh pLine AcGePoint3dArray Arr;

Arr=iterate(p2dPl);

//////Xay dung mang 4 pt min max Pt //////0:xMin, 1:xMax, 2:yMin, 3:yMax AcGePoint3d tempPt;

AcGePoint3dArray resArr;

for (int j=0;j<4;j++) {

tempPt=findMinMaxPoint(Arr,j);

resArr.append(tempPt);

}

/// Tim dinh cao nhat cho PlineArc AcGePoint3d topPt;

topPt=findTopPoint(resArr[3],p2dPl,tPara,1);

topPt.set(topPt.x,topPt.y-step,0.0);

///////Xay dung pXlineBase///Xet giao voi p2dPl AcDbVoidPtrArray curves;

AcGePoint3dArray tempRes;

AcDbXline *pXline;

int res;

while(1) {

pXline=createXline(topPt,tPara->angle);

pXline->intersectWith(p2dPl,AcDb::kOnBothOperands,tempRes,0,0);

{

res=tempRes.length();

if ((res)==0) break;

}

topPt.set(topPt.x,topPt.y-step,0.0);

curves.append(pXline);

tempRes=NULL;

}

return curves;

1.5. Môdun tính đường chạy dao cơ sở dạng tia Radial // --- Phan tinh toan cho Ray ---

int createRayFunc(simpleCut** scList,dataSlice* dSlice,techPara* tPara) {

AcDbVoidPtrArray curves,pPlines ;

pPlines = complementToolRadius(dSlice,tPara->toolRad);

if (pPlines.length()==2)

pPlines = checkDSlice(pPlines);

int len = pPlines.length();

AcDbVoidPtrArray ents = createRayCutting(dSlice->p2dPl,tPara);

for (int i =0;i<ents.length();i++) {

// tim cac giao diem cua mot duong Ray AcDbRay* pRay;

AcDbEntity* ent;

ent = (AcDbEntity*) ents[i];

if ((pRay = AcDbRay::cast(ent)) ==NULL ) return RTNORM;

curves = pPlines;

curves.append(dSlice->p2dPl);

AcGePoint3dArray resIntArr = getIntersectPoints(curves,pRay); if (inside(dSlice->p2dPl,pRay->basePoint())==1)

resIntArr.insertAt(0,pRay->basePoint());

int numPoints = resIntArr.length();

if (numPoints>1)

{ resIntArr = sortArrayPoint(resIntArr);

curves=NULL;

AcGeIntArray flag;

flag.setLogicalLength(numPoints-1);

for (int j=0;j<numPoints-1;j++ ) flag[j] = 0;

curves.append(pPlines[0]);

curves.append(dSlice->p2dPl);

getflagArray(curves,resIntArr,&flag);

curves = NULL;

curves.append(pPlines[0]);

if (len>1)

for (int j=1;j<len;j++) {

if (dSlice->flag[j] == 0) curves.append(pPlines[j]);

if (dSlice->flag[j] == 1) {

getflagArray(curves,resIntArr,&flag);

curves = NULL;

curves.append(pPlines[j]);

}

if (j==len - 1)

getflagArray(curves,resIntArr,&flag);

} if (len == 1)

getflagArray(curves,resIntArr,&flag);

simpleCut *newCt =(simpleCut*)calloc(1,sizeof(simpleCut));

for (j=0;j<numPoints;j++)

resIntArr[j].z=tPara->height;

newCt->ptArr=resIntArr;

newCt->flag = flag;

addsimpleCut(scList,newCt);

} }

if (tPara->bound == Adesk::kTrue ) { simpleCut* newCt;

newCt=createsimpleCut(dSlice->p2dPl,tPara->height);

addsimpleCut(scList,newCt);

for (i=0;i<pPlines.length();i++) {

AcDbEntity* ent;

ent = (AcDbEntity*) pPlines[i];

AcDb2dPolyline *pPl;

if ((pPl = AcDb2dPolyline ::cast (ent))!=NULL) {

newCt=createsimpleCut(pPl,tPara->height);

addsimpleCut(scList,newCt);

} }

}

// tao chuoi cac duong chay dao/////////////////////////////

AcDbVoidPtrArray

createRayCutting(AcDb2dPolyline *p2dPl,techPara* tPara) {

if (p2dPl->isClosed()!=Adesk::kTrue) {

acutPrintf("Polyline bao ngoai chua dong");

return NULL;

}

//Nhap gia tri step:

ads_real angle;

angle=tPara->angle;

///Nhap tam gia cong AcGePoint3d ptCen;

CPY_PT(ptCen,tPara->ptCen);

///////Phan xu ly du lieu dau vao////////

double runAngle=PI*angle/180.0;

double runTemp=runAngle;

int numRay=int(360/angle);

///////Xay dung pRayBase ///////Xet giao voi p2dPl AcDbRay* pRayBase;

AcDbVoidPtrArray curves;

for (int i=0;i<numRay;i++) {

pRayBase = createRay(ptCen,runAngle);

curves.append(pRayBase);

runAngle=runAngle+runTemp;

}

return curves;

}

1.6. Môdun tính toán đường chạy dao thô /////tao cau truc Cut tho cho mot duong chay dao/////////

simpleCut*

createsimpleCut(AcDbVoidPtrArray curves,AcGePoint3dArray ptArr,ads_real z)

{

int len=ptArr.length();

simpleCut *newCt =(simpleCut*)calloc(1,sizeof(simpleCut));

newCt->flag.setLogicalLength(len-1);

for (int i=1;i<len;i++) {

AcGePoint3d midPt;

midPt=midlePoint(ptArr[i-1],ptArr[i]);

newCt->flag[i-1]=1;

for (int j=0;j<curves.length();j++) {

AcDb2dPolyline* pPline;

AcDbEntity* pEnt;

pEnt = (AcDbEntity*)curves[j];

if ((pPline = AcDb2dPolyline::cast(pEnt)) !=NULL ) {

if (j==0)

if (inside(pPline,midPt)==1) newCt->flag[i-1]=0;

if (j!=0)

if (inside(pPline,midPt)==0) newCt->flag[i-1]=0;

} }

}

for (i=0;i<len;i++) ptArr[i].z=z;

newCt->ptArr=ptArr;

return newCt;

}

// tao cau truc simpleCut theo 1 polyline kin simpleCut*

createsimpleCut(AcDb2dPolyline* pPline,ads_real z)

{ simpleCut *newCt =(simpleCut*)calloc(1,sizeof(simpleCut));

AcGePoint3dArray ptArr;

ptArr = iterate(pPline);

AcGeIntArray flag;

flag.setLogicalLength(len-1);

for (int i=0;i<len-1;i++) {

flag[i]=0;

}

for (i=0;i<len;i++) ptArr[i].z=z;

newCt->flag=flag;

newCt->ptArr=ptArr;

return newCt;

}

int addsimpleCut(simpleCut** scList,simpleCut* newCt) {

if (scList==NULL) {

acutPrintf("loi bo nho");

return RTERROR;

}

if (*scList==NULL) {

(*scList)=newCt;

return RTNORM;

}

for (simpleCut* temp=(*scList);temp->next!=NULL;temp=temp->next);

temp->next=newCt;

return RTNORM;

}

// giai phong bo nho

void freesimpleCut(simpleCut** scList) {

simpleCut *temp,*hold;

temp = (*scList);

while (temp!=NULL) {

hold = temp->next;

free(temp);

temp=hold;

} }

1.7. Môdun tính toán đường chạy dao tinh

void CreateRadialToolpath(Toolpath *boundaries,double ang,Point startpt,int show,Toolpath **tp) {

int num_ang=(int)((180/ang)+1);

double ang_exact=(double)180/(double)num_ang;

double cur_ang=0.001;

Point vtcp;

SeriPoint *PTP=NULL;

Toolpath *tp1=NULL,*temptp1=NULL;

for(int i=0;i<num_ang;i++) {

double radian_ang=(PI*cur_ang)/180;

vtcp.p[0]=10*cos(radian_ang);

vtcp.p[1]=10*sin(radian_ang);

FindInterWithBoundaries(boundaries,startpt,vtcp,&PTP);

if(PTP!=NULL) {

if(tp1==NULL) {

Toolpath *pp;

pp=(Toolpath*)calloc(1,sizeof(Toolpath));

pp->next=NULL;

pp->begin=PTP;

tp1=pp;

temptp1=tp1;

}

else {

Toolpath *pp;

pp=(Toolpath*)calloc(1,sizeof(Toolpath));

temptp1->next=pp;

temptp1=temptp1->next;

} }

cur_ang=cur_ang+ang_exact;

}

if(tp1==NULL) {

*tp=NULL;

return;

}

ForcePointsInOrderRD(&tp1,startpt,ang);

if(show)

for(Toolpath *tu=tp1;tu!=NULL;tu=tu->next) {

acedCommand(RTSTR,".3DPOLY",NULL);

for(SeriPoint *ppp=tu->begin;ppp!=NULL;ppp=ppp->next) {

ads_point pg;

CPY_PT(pg,ppp->p);

acedCommand(RT3DPOINT,pg,NULL);

}

acedCommand(RTSTR,"",NULL);

} *tp=tp1;

}

void ForcePointsInOrderRD(Toolpath **tp,Point startpt,double ang) {

Point vtcp,vtcp1,pt1,pt2;

double radian_ang;

int num_ang=(int)((180/ang)+1);

double ang_exact=(double)180/(double)num_ang;

double cur_ang=0;

for(Toolpath *temp1=*tp;temp1!=NULL;temp1=temp1->next) {

int num_points=0;

for(SeriPoint *sp=temp1->begin;sp!=NULL;sp=sp->next)

num_points++;

radian_ang=(PI*cur_ang)/180;

vtcp.p[0]=10*cos(radian_ang);

vtcp.p[1]=10*sin(radian_ang);

CPY_PT(pt1.p,temp1->begin->p);

CPY_PT(pt2.p,temp1->begin->next->p);

VECTOR(vtcp1.p,pt1.p,pt2.p);

while(!CONG_TUYEN2D(vtcp,vtcp1)&&(cur_ang<180)) {

cur_ang=cur_ang+ang_exact;

radian_ang=(PI*cur_ang)/180;

vtcp.p[0]=10*cos(radian_ang);

vtcp.p[1]=10*sin(radian_ang);

}

double f;

if((num_points/2)==1)//chi kiem tra chieu {

sp=temp1->begin;

if(ZERO(vtcp.p[0])) {

f=vtcp.p[1]/(sp->next->p[1]-sp->p[1]);

}

else {

f=vtcp.p[0]/(sp->next->p[0]-sp->p[0]);

}

if(f<0)//nguoc chieu, phai dao lai {

Point tg;

CPY_PT(tg.p,sp->p);

CPY_PT(sp->p,sp->next->p);

CPY_PT(sp->next->p,tg.p);

} }

else// Co hon 1 cap diem

SeriPoint *p1=NULL,*p2=NULL,*bfp2=NULL;

p1=temp1->begin;

bfp2=p1;

p2=p1->next;

double dis=0.0,dis1,dis2;

if(CMP_PT(p1->p,p2->p)) {

p2=p2->next;

bfp2=bfp2->next;

}

else {

while(p2!=NULL) {

int flag=1;

if(ZERO(vtcp.p[0])) {

f=vtcp.p[1]/(p2->p[1]-p1->p[1]);

} else {

f=vtcp.p[0]/(p2->p[0]-p1->p[0]);

}

if(f<0) {

SeriPoint *t1=NULL;

t1=p2;

p2=p2->next;

bfp2->next=p2;

temp1->begin=t1;

t1->next=p1;

p1=temp1->begin;

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,bfp2->p);

dis=DIST(pt1,pt2);

flag=0;

}

else {

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,p2->p);

dis1=DIST(pt1,pt2);

if(dis1<dis) {

SeriPoint *spp=p1;

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,spp->next->p);

dis2=DIST(pt1,pt2);

while(dis2<dis1) {

spp=spp->next;

CPY_PT(pt2.p,spp->next->p);

dis2=DIST(pt1,pt2);

}

SeriPoint *t1=NULL;

t1=p2;

p2=p2->next;

bfp2->next=p2;

t1->next=spp->next;

spp->next=t1;

flag=0;

} }

if(flag) {

dis=dis1;

p2=p2->next;

bfp2=bfp2->next;

} }

} }

//Chia doi tung doan ra tai diem startpt Toolpath *ttp=NULL,*temp2=NULL;

for(temp1=*tp;temp1!=NULL;temp1=temp1->next) {

SeriPoint *temp1_sp=temp1->begin;

CPY_PT(pt1.p,temp1_sp->p);

for(SeriPoint *temp2_sp=temp1->begin;temp2_sp-

>next!=NULL;temp2_sp=temp2_sp->next);

CPY_PT(pt2.p,temp2_sp->p);

if(IN_OUT_LINE(startpt,pt1,pt2))//phai cat doi {

//Tim doan ma startpt nam giua Point start,runpt;

SeriPoint *beginsp,*runsp;

beginsp=(SeriPoint*)calloc(1,sizeof(SeriPoint));

beginsp->next=NULL;

CPY_PT(beginsp->p,temp1->begin->p);

beginsp->next=temp1->begin;

runsp=beginsp;

CPY_PT(start.p,temp1->begin->p);

CPY_PT(runpt.p,runsp->next->p);

double len_begin_startpt=DIST(startpt,start);

while(DIST(start,runpt)<len_begin_startpt) {

runsp=runsp->next;

CPY_PT(runpt.p,runsp->next->p);

}

temp2=(Toolpath*)calloc(1,sizeof(Toolpath));

temp2->next=NULL;

temp2->begin=temp1->begin;

//Kiem tra xem startpt co nam trong vung cat hay khong if(InCuttingArea(startpt,temp1->begin))

{

SeriPoint *tmid;

tmid=(SeriPoint*)calloc(1,sizeof(SeriPoint));

tmid->next=NULL;

CPY_PT(tmid->p,startpt.p);

tmid->next=runsp->next;

temp1->begin=tmid;

tmid=NULL;

tmid=(SeriPoint*)calloc(1,sizeof(SeriPoint));

tmid->next=NULL;

CPY_PT(tmid->p,startpt.p);

runsp->next=tmid;

}

else {

temp1->begin=runsp->next;

runsp->next=NULL;

}

if(ttp==NULL) ttp=temp2;

else {

for(Toolpath *temp_ttp=ttp;temp_ttp-

>next!=NULL;temp_ttp=temp_ttp->next);

temp_ttp->next=temp2;

} }

}

for(temp1=*tp;temp1->next!=NULL;temp1=temp1->next);

temp1->next=ttp;

//Xep lai lan nua cur_ang=0;

for(temp1=*tp;temp1!=NULL;temp1=temp1->next) {

int num_points=0;

for(SeriPoint *sp=temp1->begin;sp!=NULL;sp=sp->next) num_points++;

radian_ang=(PI*cur_ang)/180;

vtcp.p[0]=10*cos(radian_ang);

vtcp.p[1]=10*sin(radian_ang);

VECTOR(vtcp1.p,pt1.p,pt2.p);

while(!CONG_TUYEN2D(vtcp,vtcp1)&&(cur_ang<360)) {

cur_ang=cur_ang+ang_exact;

radian_ang=(PI*cur_ang)/180;

vtcp.p[0]=10*cos(radian_ang);

vtcp.p[1]=10*sin(radian_ang);

}

double f;

if((num_points/2)==1)//chi kiem tra chieu {

sp=temp1->begin;

if(ZERO(vtcp.p[0])) {

f=vtcp.p[1]/(sp->next->p[1]-sp->p[1]);

}

else {

f=vtcp.p[0]/(sp->next->p[0]-sp->p[0]);

}

if(f<0)//nguoc chieu, phai dao lai {

Point tg;

CPY_PT(tg.p,sp->p);

CPY_PT(sp->p,sp->next->p);

CPY_PT(sp->next->p,tg.p);

} }

else// Co hon 1 cap diem {

Point pt1,pt2;

SeriPoint *p1,*p2,*bfp2;

p1=temp1->begin;

bfp2=p1;

p2=p1->next;

double dis=0.0,dis1,dis2;

if(CMP_PT(p1->p,p2->p))

{

p2=p2->next;

bfp2=bfp2->next;

}

else {

while(p2!=NULL) {

int flag=1;

if(ZERO(vtcp.p[0])) {

f=vtcp.p[1]/(p2->p[1]-p1->p[1]);

} else {

f=vtcp.p[0]/(p2->p[0]-p1->p[0]);

}

if(f<0) {

SeriPoint *t1;

t1=p2;

p2=p2->next;

bfp2->next=p2;

temp1->begin=t1;

t1->next=p1;

p1=temp1->begin;

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,bfp2->p);

dis=DIST(pt1,pt2);

flag=0;

} else {

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,p2->p);

{

SeriPoint *spp=p1;

CPY_PT(pt1.p,p1->p);

CPY_PT(pt2.p,spp->next->p);

dis2=DIST(pt1,pt2);

while(dis2<dis1) {

spp=spp->next;

CPY_PT(pt2.p,spp->next->p);

dis2=DIST(pt1,pt2);

}

SeriPoint *t1;

t1=p2;

p2=p2->next;

bfp2->next=p2;

t1->next=spp->next;

spp->next=t1;

flag=0;

} }

if(flag) {

dis=dis1;

p2=p2->next;

bfp2=bfp2->next;

} }

} }

cur_ang=cur_ang+ang_exact;

}

temp1=*tp;

while(temp1!=NULL) {

int num_points=0;

for(SeriPoint *sp=temp1->begin;sp!=NULL;sp=sp->next)

num_points++;

if((num_points/2)>1) {

Toolpath *tt;

tt=(Toolpath*)calloc(1,sizeof(Toolpath));

tt->next=NULL;

tt->begin=temp1->begin->next->next;

temp1->begin->next->next=NULL;

tt->next=temp1->next;

temp1->next=tt;

}

temp1=temp1->next;

} }

int InCuttingArea(Point pt,SeriPoint *sp) {

if(sp==NULL) return 0;

else {

Point stp,ndp;

SeriPoint *temp=sp;

while(temp!=NULL) {

CPY_PT(stp.p,temp->p);

CPY_PT(ndp.p,temp->next->p);

if(IN_OUT_LINE(pt,stp,ndp)) return 1;

temp=temp->next->next;

} } return 0;

}

Một phần của tài liệu Báo cáo nghiên cứu ứng dụng hệ thống tính toán song song hiệu nâng cao để lập trình gia công các bề mặt khuôn mẫu trên máy công cụ CNC (Trang 144 - 432)

Tải bản đầy đủ (PDF)

(432 trang)