⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 profdata.cc

📁 数控系统中的解释器源代码
💻 CC
字号:
#include "rs274ngc.hh"
#include "agl.hh"
#include <math.h>


static int     ParaZInf1[4] = {1,-1,-1,1};  /* line(cos) */

/* ------2C------- */
static int     ParaZInf2[4] = {-1,1,1,-1};  /* line(d  ) */


/* ------34------- */
static int     ParaXInf1[4] = {-1,-1,1,1};  /* line(cos) */

/* ------3C------- */
static int     ParaXInf2[4] = {1,1,-1,-1};  /* line(d  ) */


/* ------44------- */
static BYTE      ProfileCheck1[2][4][4] = {
		       {{0x00,0x02,0xFF,0xFF},
			{0x02,0x00,0xFF,0xFF},
			{0xFF,0xFF,0x00,0x02},
			{0xFF,0xFF,0x02,0x00}},

		       {{0x00,0xFF,0xFF,0x02},
			{0xFF,0x00,0x02,0xFF},
			{0xFF,0x02,0x00,0xFF},
			{0x02,0xFF,0xFF,0x00}}
					};

/* Line not in Coordinate Axis */
/* 1--Parallel Axis,2--Profile Direction,3--Line Direction */


/* -------64------- */
static BYTE        ProfileCheck2[2][4][4] = {
                       {{0x00,0x00,0x02,0xFF},
                        {0x02,0x00,0x00,0xFF},
                        {0x02,0xFF,0x00,0x00},
                        {0x00,0xFF,0x02,0x00}},

		       {{0x00,0x00,0xFF,0x02},
			{0xFF,0x00,0x00,0x02},
			{0xFF,0x02,0x00,0x00},
			{0x00,0x02,0xFF,0x00}}
					};
/* Line in Coordinate Axis */
/* 1--Parallel Axis,2--Profile Direction,3--Line Direction */



/* -------84------- */
static BYTE        ProfileCheck3[2][2][4][4] = {
                        {
                            {
				{0xFF,0x04,0x03,0x03},
                                {0xFF,0x02,0x00,0xFF},
                                {0x03,0x03,0xFF,0x04},
				{0x00,0xFF,0xFF,0x02},
			    },
                            {
                                {0x02,0xFF,0xFF,0x00},
                                {0x04,0xFF,0x03,0x03},
                                {0xFF,0x00,0x02,0xFF},
                                {0x03,0x03,0x04,0xFF},
                            },
                        },
                        {
                            {
				{0x02,0x00,0xFF,0xFF},
				{0x03,0xFF,0x04,0x03},
				{0xFF,0xFF,0x02,0x00},
				{0x04,0x03,0x03,0xFF},
			    },
			    {
				{0xFF,0x03,0x03,0x04},
				{0x00,0x02,0xFF,0xFF},
				{0x03,0x04,0xFF,0x03},
                                {0xFF,0xFF,0x00,0x02},
                            },
                        }
                };
/* 1st Arg-Paralleled Axis,2rd Arg-Circle Direction(CW,CCW) */
/* 3th Arg-Profile Direction,4--Circle Quadrant No. */


/* ---------CC--------- */
static BYTE            CriticalTab[2][4] = {
				{0,0,1,1},
				{1,0,0,1}
				};

        /* get Circle Critical Point Value ,0--Maxium Value,1-Minum Value */

/* ---------CC--------- */
static BYTE            IntersectTab[2][2][4] = {
                                {{1,0,1,0},{0,1,0,1}},
                                {{0,1,0,1},{1,0,1,0}}
                                        };

/* Circle intersect Line */
/* 1--Parallel Axis,2--Circle Direction(CW,CCW),3--Profile Direction */



/********************************************************************
 * Procedure:
 *	Compute the Data used by Special Cycle.
 *
 ********************************************************************/
void  CNC_GetDataUsedBySpeCycle(Special_Cycle       *pSpeCycle,
					  BYTE                   SpeCycleState)
{

double		    InchMm;
   

   /* if (pProc->pMeasureInf->ConvertFlag)
	{
	InchMm = pProc->pMeasureInf->Inchmm;
	pSpeCycle->AbsMove *= InchMm;
	pSpeCycle->AbsUOV  *= InchMm;
	pSpeCycle->OrdMove *= InchMm;
	pSpeCycle->OrdUOV  *= InchMm;
	}
  */
    if	( SpeCycleState == 9 )
	{
	pSpeCycle->AbsAdd =
	    (pSpeCycle->AbsMove - pSpeCycle->AbsUOV) / (pSpeCycle->CutStepNum - 1);
	pSpeCycle->OrdAdd =
	    (pSpeCycle->OrdMove - pSpeCycle->OrdUOV) / (pSpeCycle->CutStepNum - 1);
	}
}


/********************************************************************
 * Procedure:
 *	Change the tooling direction accorfing to the tools an profile.
 *
 ********************************************************************/
void  CNC_ChangeToolDirect(Special_Cycle       *pSpeCycle,
				     ProfBlockStruc   *pProfBlock,
				     int    *exception)
{
float           minvalue;
double          d0;
//ProfBlockStruc   *pProfBlock=pSpeCycle->Block,

    minvalue = 0;
    if (pSpeCycle->AbsMove != 0.0 || pSpeCycle->AbsUOV != 0.0)
	{
	d0 = pSpeCycle->AbsMachineValue2 - pProfBlock->Point.PosX;
	if( fabs(d0) < minvalue )
	    *exception = 0x47;
	else if( d0 < 0 )
	    {
	    pSpeCycle->AbsMove = -pSpeCycle->AbsMove;
	    pSpeCycle->AbsUOV  = -pSpeCycle->AbsUOV;
	    pSpeCycle->AbsAdd  = -pSpeCycle->AbsAdd;
	    }
	}

    if ( !*exception )
	if (pSpeCycle->OrdMove != 0.0 || pSpeCycle->OrdUOV != 0.0)
	    {
	    d0 = pSpeCycle->OrdMachineValue2 - pProfBlock->Point.PosY;
	    if ( fabs(d0) < minvalue )
		*exception = 0x47;
	    else if ( d0 < 0 )
		{
		pSpeCycle->OrdMove = -pSpeCycle->OrdMove;
		pSpeCycle->OrdUOV  = -pSpeCycle->OrdUOV;
		pSpeCycle->OrdAdd  = -pSpeCycle->OrdAdd;
		}
	    }
}


/********************************************************************
 * Function:
 *	Determine the direction of a line.
 *
 ********************************************************************/
int  CNC_GetOriginOfLine(ProfBlockStruc            *pProfBlock)
{
float       minvalue;
double      negSineValue, cosineValue;
int         ret = 0;

    minvalue =0;
    negSineValue = pProfBlock->CurveExpression.Element[0];
    cosineValue  = pProfBlock->CurveExpression.Element[1];

    if( (1 - minvalue ) < cosineValue)
	ret = - 1;
    if( (minvalue - 1) > negSineValue)
	ret = - 2;
    if( (minvalue - 1) > cosineValue)
	ret = - 3;
    if( (1 - minvalue) < negSineValue)
	ret = - 4;

    if (ret)
       return(ret);
    if (cosineValue==0)
		if (negSineValue<0)
			ret=4;
		else
			ret=2;
    if (ret)
       return(ret);	
    if (cosineValue >= 0)
	if(negSineValue < 0)
	    ret = 1;
	else
	    ret = 4;
    else
	if(negSineValue <= 0)
	    ret = 2;
	else
	    ret = 3;

    return(ret);
}


/********************************************************************
 * Procedure:
 *	 Determine a line parallel to axis.
 *
 ********************************************************************/
void  CNC_GetLineOfParallelAxis(ProfBlockStruc      *pProfBlock,
					  int                    Paraaxisflag,
					  int                    Profdirection)
{
    if (Paraaxisflag == 1)
	{
	pProfBlock->CurveExpression.Element[0] = 0.0;
	pProfBlock->CurveExpression.Element[1] = ParaZInf1[Profdirection-1];
	pProfBlock->CurveExpression.Element[2] =
		pProfBlock->Point.PosY * ParaZInf2[Profdirection-1];
	}
    else
	{
	pProfBlock->CurveExpression.Element[1] = 0.0;
	pProfBlock->CurveExpression.Element[0] = ParaXInf1[Profdirection-1];
	pProfBlock->CurveExpression.Element[2] =
		pProfBlock->Point.PosX * ParaXInf2[Profdirection-1];
	}
}


/********************************************************************
 * Function:
 *	Determine whether the point locate in the line range.
 *	return 1 if located.
 ********************************************************************/
BYTE  CNC_CheckPointInSegment(Special_Cycle           *pSpeCycle,
					PointVar                *Point)
{
float               minvalue;
BYTE                ret0 = 0, block1;

    block1 = pSpeCycle->BlockNum;
    block1 --;
    minvalue = 0;
   /* if (!pSpeCycle->ParaAxisFlag)
	{
	if ( pSpeCycle->ProfDirection == 0||pSpeCycle->ProfDirection == 1 || pSpeCycle->ProfDirection == 4)
	    {
	    if ( (pSpeCycle->Block[block1].Point.PosX - minvalue)
					       > Point->PosX &&
		 (pSpeCycle->Block[block1-1].Point.PosX - minvalue)
					       < Point->PosX)
		ret0 = 1;
	    }
	else
	    {
	    if ( (pSpeCycle->Block[block1].Point.PosX + minvalue)
						< Point->PosX&&
		 (pSpeCycle->Block[block1-1].Point.PosX + minvalue)
						> Point->PosX)
		ret0 = 1;
	    }
	}
    else
	{
	//if (pSpeCycle->ProfDirection == 0||pSpeCycle->ProfDirection == 1 || pSpeCycle->ProfDirection == 2)
	if (1)
	{
	    DEBUG_PRINT("in \n");
	    if ( (pSpeCycle->Block[block1].Point.PosY - minvalue)
						> Point->PosY &&
		 (pSpeCycle->Block[block1-1].Point.PosY - minvalue)
						< Point->PosY )
		ret0 = 1;
	    }
	else
	    {
	    if ( (pSpeCycle->Block[block1].Point.PosY + minvalue)
						< Point->PosY &&
		 (pSpeCycle->Block[block1-1].Point.PosY + minvalue)
						> Point->PosY )
		ret0 = 1;
	    }
	}*/
    if (pSpeCycle->ParaAxisFlag)
	{
	    
	    if ( (pSpeCycle->Block[block1].Point.PosY - minvalue)
						>= Point->PosY &&
		 (pSpeCycle->Block[block1-1].Point.PosY - minvalue)
						<= Point->PosY )
		ret0 = 1;
		//DEBUG_PRINT("in %d\n",ret0);
		//DEBUG_PRINT("blodk[%d] Y %f ,%f----  %f\n",block1,pSpeCycle->Block[block1].Point.PosY ,pSpeCycle->Block[block1-1].Point.PosY,Point->PosY);
	    }
	else
		{
		if ( (pSpeCycle->Block[block1].Point.PosX - minvalue)
					       >=Point->PosX &&
		 (pSpeCycle->Block[block1-1].Point.PosX - minvalue)
					       <= Point->PosX)
				ret0 = 1;
		//DEBUG_PRINT("in %d\n",ret0);
		//DEBUG_PRINT("blodk[%d] Y %f ,%f----  %f\n",block1,pSpeCycle->Block[block1].Point.PosX,pSpeCycle->Block[block1-1].Point.PosX,Point->PosX);
		}
    return(ret0);
}


/********************************************************************
 * Function:
 *	Determine the relationship between line and previous curve.
 *	return 1(normal),2(cavice),-1(illegal)
 ********************************************************************/
int  CNC_RelationOfLine(int    ParaAxisFlag,
				  int    ProfDirection,
				  int    DirOfLine)
{
int     ret0;

    if ( DirOfLine > 0 )
      ret0 = ProfileCheck1[ParaAxisFlag][ProfDirection -1 ][ DirOfLine - 1];
    else
      ret0 = ProfileCheck2[ParaAxisFlag][ProfDirection -1 ][-DirOfLine - 1];

    return( ret0 );
}


/********************************************************************
 * Function:
 *	Determine the relationship between circle and previous curve.
 *
 ********************************************************************/
int  CNC_RelationOfArc(int                ParaAxisFlag,
				 int                ProfDirection,
				 int                ZoneNo,
				 double          *pDouble)
{
BYTE   circleDir, quad;

    if ( *pDouble > 0 )
	{
	circleDir = 1;
	quad      = (ZoneNo + 2) % 4 + 1;
	}
    else
	{
	circleDir = 0;
	quad      = ZoneNo;
	}

    return( ProfileCheck3[ParaAxisFlag][circleDir][ProfDirection-1][quad-1] );
}


/********************************************************************
 * Procedure:
 *	Determine the polar point in the direction paralled to axis.
 *
 ********************************************************************/
void  CNC_FindArcPolarPoint(ProfBlockStruc      *pProfBlock,
				      int                    ParaAxisFlag,
				      int                    ProfDirection)
{
    pProfBlock->Point.PosX = pProfBlock->CurveExpression.Element[0];
    pProfBlock->Point.PosY = pProfBlock->CurveExpression.Element[1];
    if ( !CriticalTab[ParaAxisFlag][ProfDirection - 1] )
	{
	if ( ParaAxisFlag )
	    pProfBlock->Point.PosY += pProfBlock->CurveExpression.Element[2];
	else
	    pProfBlock->Point.PosX += pProfBlock->CurveExpression.Element[2];
	}
    else
	{
	if ( ParaAxisFlag )
	    pProfBlock->Point.PosY -= pProfBlock->CurveExpression.Element[2];
	else
	    pProfBlock->Point.PosX -= pProfBlock->CurveExpression.Element[2];
	}
}


/********************************************************************
 * Function:
 *	Determine whether the point is on the arc.
 *
 ********************************************************************/
int  CNC_CheckPointOnArc(Special_Cycle           *pSpeCycle,
				   float              MinValue,
				   float                   *MinMeasure)
{
int                 ret0, flag, exception;
BYTE                circleDir, circleDir1, block1;
AGL                 gtl;
double              more1, more2;

    block1 = pSpeCycle->BlockNum;
    block1 --;
    if (pSpeCycle->Block[block1].CurveExpression.Element[2] > 0)
	circleDir = 1;
    else
	circleDir = 0;
    flag = IntersectTab[pSpeCycle->ParaAxisFlag][circleDir][pSpeCycle->ProfDirection];
    CNC_AGLPointOfLineArc((LineVar *)&pSpeCycle->Block[block1-1].CurveExpression,
			  (CircleVar *)&pSpeCycle->Block[block1].CurveExpression,
			  &flag,
			  (PointVar *)&pSpeCycle->AbsValue,
			  MinValue,
			  &exception,
			  &ret0);
    if ( !ret0 )
	{
	CNC_AGLArcOf3Point(&pSpeCycle->Block[block1-1].Point,
			   &pSpeCycle->Block[block1].Point,
			   (PointVar *)&pSpeCycle->AbsValue,
			   (CircleVar *)&gtl,
			   MinValue,
			   MinMeasure,
			   &ret0);
	if ( ret0 )
	    {
	    more1=pSpeCycle->Block[block1-1].Point.PosX - pSpeCycle->AbsValue;
	    more2=pSpeCycle->Block[block1-1].Point.PosY - pSpeCycle->OrdValue;
	    if (fabs(more1) > *MinMeasure ||
		fabs(more2) > *MinMeasure )
	      ret0 = 1;
	    else
	      ret0 = 0;
	    }
	else
	    {
	    if (gtl.Element[2] > 0)
		circleDir1 = 1;
	    else
		circleDir1 = 0;
	    if (circleDir == circleDir1)
		ret0 = 1;
	    }
	}
    return(ret0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -