Example #1
0
void CGCodeInterpreter::ConvertAbsoluteToMachine(double x,double y,double z,double a,double b,double c, 
											double *gx,double *gy,double *gz,double *ga,double *gb,double *gc)
{
	*gx  = InchesToUserUnitsX(x);
	*gy  = InchesToUserUnits(y);
	*gz  = InchesToUserUnits(z);
	*ga  = InchesOrDegToUserUnitsA(a);
	*gb  = InchesOrDegToUserUnitsB(b);
	*gc  = InchesOrDegToUserUnitsC(c);
}	
Example #2
0
void CGCodeInterpreter::ConvertAbsoluteToInterpreterCoord(double x,double y,double z,double a,double b,double c, 
													double *gx,double *gy,double *gz,double *ga,double *gb,double *gc)
{
	*gx  = InchesToUserUnits(x) - _setup.axis_offset_x  - _setup.origin_offset_x;
	*gy  = InchesToUserUnits(y) - _setup.axis_offset_y  - _setup.origin_offset_y;
	*gz  = InchesToUserUnits(z) - _setup.axis_offset_z  - _setup.origin_offset_z - _setup.tool_length_offset;
	*ga  = InchesOrDegToUserUnitsA(a) - _setup.AA_axis_offset - _setup.AA_origin_offset;
	*gb  = InchesOrDegToUserUnitsB(b) - _setup.BB_axis_offset - _setup.BB_origin_offset;
	*gc  = InchesOrDegToUserUnitsC(c) - _setup.CC_axis_offset - _setup.CC_origin_offset;
}
Example #3
0
void CGCodeInterpreter::ConvertAbsoluteToInterpreterCoord(double x,double y,double z,double a,double b,double c, 
													double *gx,double *gy,double *gz,double *ga,double *gb,double *gc,setup_pointer psetup)
{
	if (!psetup) psetup = p_setup;

	*gx  = InchesToUserUnitsX(x) - psetup->axis_offset_x  - psetup->origin_offset_x - psetup->tool_xoffset;
	*gy  = InchesToUserUnits(y) - psetup->axis_offset_y  - psetup->origin_offset_y - psetup->tool_yoffset;
	*gz  = InchesToUserUnits(z) - psetup->axis_offset_z  - psetup->origin_offset_z - psetup->tool_length_offset;
	*ga  = InchesOrDegToUserUnitsA(a) - psetup->AA_axis_offset - psetup->AA_origin_offset;
	*gb  = InchesOrDegToUserUnitsB(b) - psetup->BB_axis_offset - psetup->BB_origin_offset;
	*gc  = InchesOrDegToUserUnitsC(c) - psetup->CC_axis_offset - psetup->CC_origin_offset;
}
Example #4
0
double CGCodeInterpreter::ConvertAbsToUserUnitsA(double a)
{
	return InchesOrDegToUserUnitsA(a - p_setup->AA_axis_offset  - p_setup->AA_origin_offset);
}
Example #5
0
int CGCodeInterpreter::DoReverseSearch(const char * InFile, int CurrentLine)
{
	int GCodeReads,status;
	char trash[INTERP_TEXT_SIZE];
	char * read_ok;
	char s[MAX_LINE];

	if (CurrentLine==0) return 0;  // should always be ok to set the first line

	CoordMotion->m_Stopping = STOPPED_NONE;

// always read the tool file now (some users set it externally)
//	if (m_restart || m_ReadToolFile)
	{
		if (ToolFile[0]!=0)
		{
			status = read_tool_file(ToolFile, &_setup);
			if (status != RS274NGC_OK)	return rs274ErrorExit(status);
		}
		m_ReadToolFile = false;
	}
	

	if (!CoordMotion->m_Simulate)
	{
		int result;

		// find out which axis is which
		// force refresh and save results

		CoordMotion->m_DefineCS_valid = false;

		if  (CoordMotion->m_PreviouslyStopped)
			result = CoordMotion->ReadCurAbsPosition(&CoordMotion->current_x,&CoordMotion->current_y,&CoordMotion->current_z,
													&CoordMotion->current_a,&CoordMotion->current_b,&CoordMotion->current_c,true);
		else
			result = ReadAndSyncCurPositions(&_setup.current_x,&_setup.current_y,&_setup.current_z,&_setup.AA_current,&_setup.BB_current,&_setup.CC_current);

		if (result == 1)
		{
			if (CoordMotion->m_AxisDisabled)
				strcpy(ErrorOutput,"Unable to read defined coordinate system axis positions - Axis Disabled ");
			else
				strcpy(ErrorOutput,"Unable to read defined coordinate system axis positions ");
		}

		if (result != 0) return 1005;
	}

	status = rs274ngc_open(InFile); 
	if (status != RS274NGC_OK)	return rs274ErrorExit(status);

	if (_setup.percent_flag == ON)
		GCodeReads = 1;
	else
		GCodeReads = 0;


	// read the entire file into this array of lines
	// up until the line we wish to start
#ifdef _KMOTIONX
	//char *LineArray = new char[CurrentLine+1][INTERP_TEXT_SIZE+1];
	//this works on linux due to a C++ extension
	char LineArray[CurrentLine+1][INTERP_TEXT_SIZE+1];
#define CLEAN_ARRAY do{ } while( false )
#else
	CString *LineArray = new CString[CurrentLine+1];
	if (!LineArray) return 1;
#define CLEAN_ARRAY do{ delete [] LineArray; } while( false )
#endif

	for( ; GCodeReads<=CurrentLine ; GCodeReads++)
	{
		read_ok = fgets(trash, INTERP_TEXT_SIZE,_setup.file_pointer);
		if (!read_ok) 
		{
			rs274ngc_close();
			CLEAN_ARRAY;
			AfxMessageBox("Error while reading GCode file ");
			return 1;
		}
#ifdef _KMOTIONX
		strcpy(LineArray[GCodeReads],trash);
#else
		LineArray[GCodeReads] = trash;
#endif
	}

	rs274ngc_close();

	bool Done=false;

	bool FoundG=false;
	bool FoundF=false;
	bool FoundUnits=false;
	bool FoundX=CoordMotion->x_axis < 0;
	bool FoundY=CoordMotion->y_axis < 0;
	bool FoundZ=CoordMotion->z_axis < 0;
	bool FoundA=CoordMotion->a_axis < 0;
	bool FoundB=CoordMotion->b_axis < 0;
	bool FoundC=CoordMotion->c_axis < 0;

	bool FoundX0,FoundY0,FoundZ0,FoundA0,FoundB0,FoundC0,FoundG0,FoundF0,FoundUnits0;


	int G=-1;
	int Units=-1;
	double x=0,y=0,z=0,a=0,b=0,c=0,f=0;
	block *BL=&p_setup->block1;
	block block0;
	bool FirstLoop=true;

	if (--GCodeReads<0) {CLEAN_ARRAY; return 1;}

	status = rs274ngc_read(LineArray[GCodeReads]);
	if (status == RS274NGC_ENDFILE)
	{
		rs274ngc_close();
		CLEAN_ARRAY;
		return RS274NGC_ENDFILE;
	}

	// save what is on the line the User wants to switch to

	block0=p_setup->block1;

	// we need to determine what everthing would be 
	// after the previous line was executed

	while (!FoundG || (!FoundF && (G==-1 || G==G_1 || G==G_2 || G==G_3)) 
		    || !FoundX || !FoundY || !FoundZ || !FoundA || !FoundB || !FoundC
			|| !FoundUnits)
	{
		if (--GCodeReads<0) break;

		status = rs274ngc_read(LineArray[GCodeReads]);
		if (status == RS274NGC_ENDFILE)
		{
			rs274ngc_close();
			CLEAN_ARRAY;
			return RS274NGC_ENDFILE;
		}

		if (!FoundG)
		{
			if (BL->motion_to_be == G_0 ||
				BL->motion_to_be == G_1 ||
				BL->motion_to_be == G_2 ||
				BL->motion_to_be == G_3 ||
				BL->motion_to_be == G_4) FoundG=true;

			if (FoundG) G=BL->motion_to_be;
		}

		if (!FoundUnits)
		{
			if (BL->g_modes[6] == G_20 ||
				BL->g_modes[6] == G_21) FoundUnits=true;

			if (FoundUnits) Units=BL->g_modes[6];
		}

		if (!FoundF && BL->f_number >= 0.0) {FoundF=true; f=BL->f_number;}
		if (!FoundX && BL->x_flag) {FoundX=true; x=BL->x_number;}
		if (!FoundY && BL->y_flag) {FoundY=true; y=BL->y_number;}
		if (!FoundZ && BL->z_flag) {FoundZ=true; z=BL->z_number;}
		if (!FoundA && BL->a_flag) {FoundA=true; a=BL->a_number;}
		if (!FoundB && BL->b_flag) {FoundB=true; b=BL->b_number;}
		if (!FoundC && BL->c_flag) {FoundC=true; c=BL->c_number;}

		if (FirstLoop)
		{
			FirstLoop=false;
			FoundX0=FoundX;
			FoundY0=FoundY;
			FoundZ0=FoundZ;
			FoundA0=FoundA;
			FoundB0=FoundB;
			FoundC0=FoundC;
			FoundG0=FoundG;
			FoundF0=FoundF;
			FoundUnits0=FoundUnits;
		}
	}

	CLEAN_ARRAY;

	if ((block0.g_modes[6]!=G_20 || block0.g_modes[6]!=G_21) && FoundUnits)  // if units not specified on current line and different 
	{
		if (Units==G_20 && p_setup->length_units!=CANON_UNITS_INCHES)
		{
			if (AfxMessageBox("Backward scan found G20 Inches Mode.  Switch to Inches?" ,MB_YESNO)==IDYES)
			{
				p_setup->length_units=CANON_UNITS_INCHES;
			}
		}
		if (Units==G_21 && p_setup->length_units!=CANON_UNITS_MM)
		{
			if (AfxMessageBox("Backward scan found G21 MM Mode.  Switch to MM?" ,MB_YESNO)==IDYES)
			{
				p_setup->length_units=CANON_UNITS_MM;
			}
		}
	}

	// if jumping to a G0 assume User knows what is intended and it is ok to rapid to that location 
	if (block0.motion_to_be==G_0) return 1;


	if (GCodeReads<0)
	{
		strcpy(s,"Unable to determine starting conditions for this line.\r\r");
		if (!FoundX) strcat(s,"X? ");
		if (!FoundY) strcat(s,"Y? ");
		if (!FoundZ) strcat(s,"Z? ");
		if (!FoundA) strcat(s,"A? ");
		if (!FoundB) strcat(s,"B? ");
		if (!FoundC) strcat(s,"C? ");
		if (!FoundF && (G==-1 || G==G_1 || G==G_2 || G==G_3))strcat(s,"F? ");
		if (!FoundUnits) strcat(s,"G20/21? ");
		
		AfxMessageBox(s);
		return 1;
	}

	if (block0.motion_to_be==-1)
	{
		sprintf(s, "New Line does not contain a G mode.  Backward scan found:\r\rG%d\r\rUse this mode?",G/10);

		if (AfxMessageBox(s,MB_YESNO)==IDNO)
		{
			return 1;
		}
	}

	if (block0.f_number==-1)
	{
		if (FoundF)
		{
			sprintf(s, "New Line does not contain a Feedrate F command.  Backward scan found:\r\rF%g\r\rUse this feedrate?",f);
			if (AfxMessageBox(s,MB_YESNO)==IDYES)
			{
				p_setup->feed_rate=m_StoppedInterpState.feed_rate=f;
			}
			else
			{
				m_StoppedInterpState.feed_rate=p_setup->feed_rate;
			}
		}
		else
		{
			AfxMessageBox("New Line does not contain a Feedrate F command.  Unable to determine previous feedrate");
		}
	}
	else
	{
		p_setup->feed_rate=m_StoppedInterpState.feed_rate=block0.f_number;
	}


	if (!FoundX0 || !FoundY0 ||!FoundZ0 ||!FoundA0 ||!FoundB0 ||!FoundC0)
	{
		char v[32];
		strcpy(s,"Backward scan found previous position as:\r\r");
		if (CoordMotion->x_axis >= 0){ sprintf(v," X%g",x); strcat(s,v);}
		if (CoordMotion->y_axis >= 0){ sprintf(v," Y%g",y); strcat(s,v);}
		if (CoordMotion->z_axis >= 0){ sprintf(v," Z%g",z); strcat(s,v);}
		if (CoordMotion->a_axis >= 0){ sprintf(v," A%g",a); strcat(s,v);}
		if (CoordMotion->b_axis >= 0){ sprintf(v," B%g",b); strcat(s,v);}
		if (CoordMotion->c_axis >= 0){ sprintf(v," C%g",c); strcat(s,v);}
		strcat(s,"\rShould a Safe Z move be made using these coordinates?");
		if (AfxMessageBox(s,MB_YESNO)==IDNO)
		{
			return 1;
		}
	}

	if (!FoundG0)
	{
		int group = _gees[G*10];

		if (group==0)  // G4 = group0
			p_setup->active_g_codes[1]=-1;
		else           // G0,G1,G2,G3
			p_setup->active_g_codes[0]=-1;

		p_setup->motion_mode=G;
	}

	if (FoundX) {CoordMotion->m_Stoppedx=x; p_setup->current_x=x;}
	if (FoundY) {CoordMotion->m_Stoppedy=y; p_setup->current_y=y;}
	if (FoundZ) {CoordMotion->m_Stoppedz=z; p_setup->current_z=z;}
	if (FoundA) {CoordMotion->m_Stoppeda=a; p_setup->AA_current=a;}
	if (FoundB) {CoordMotion->m_Stoppedb=b; p_setup->BB_current=b;}
	if (FoundC) {CoordMotion->m_Stoppedc=c; p_setup->CC_current=c;}

	CoordMotion->m_StoppedMachinex = UserUnitsToInchesX(CoordMotion->m_Stoppedx+_setup.axis_offset_x+_setup.origin_offset_x+_setup.tool_xoffset);
	CoordMotion->m_StoppedMachiney = UserUnitsToInches(CoordMotion->m_Stoppedy+_setup.axis_offset_y+_setup.origin_offset_y+_setup.tool_yoffset);
	CoordMotion->m_StoppedMachinez = UserUnitsToInches(CoordMotion->m_Stoppedz+_setup.axis_offset_z+_setup.origin_offset_z+_setup.tool_length_offset);
	CoordMotion->m_StoppedMachinea  = InchesOrDegToUserUnitsA(CoordMotion->m_Stoppeda) - _setup.AA_axis_offset - _setup.AA_origin_offset;
	CoordMotion->m_StoppedMachineb  = InchesOrDegToUserUnitsB(CoordMotion->m_Stoppedb) - _setup.BB_axis_offset - _setup.BB_origin_offset;
	CoordMotion->m_StoppedMachinec  = InchesOrDegToUserUnitsC(CoordMotion->m_Stoppedc) - _setup.CC_axis_offset - _setup.CC_origin_offset;



	CoordMotion->m_PreviouslyStopped = CoordMotion->m_Stopping = STOPPED_INDEP;

	return 0;
}