https://youtu.be/4Ecy9yVFY8Q
Код: Выделить всё
#include "KMotionDef.h"
int DoPC(int cmd);
int DoPCInt(int cmd, int i);
//------USER_DATE------------
#define GATH_OFF 0 // define the offset into the Gather buffer where strings are passed
#define SENS 4 //Номер бита центроискателя
#define II 32574 //Количество импульсов на дюйм
#define AJS 5000 //Скорость перемещения осей при холостых перебегах
#define ASS 600 //Скорость перемещения осей для касания стилуса
//------USER_DATE------------
//--------ОБЯЗАТЕЛЬНО К ПРОЧТЕНИЮ-----------
//Для верного выполнения скрипта необходимо:
//1. Расположить шарик стилуса центроискателя ниже плоскости заготовки в произвольном месте внутри отверстия
//--------ОБЯЗАТЕЛЬНО К ПРОЧТЕНИЮ-----------
main()
{
double *pD = (double *)persist.UserData;
double PX0,PX1,PX2,PX3,PX4,PX5,PX6,PY0,PY1,PY2,PY3,PY4,PY5,PY6,AUP,IMP;
//Расчеты
IMP = II;
AUP = (IMP*0.5)/25.4;
Delay_sec(0.2);
//Перемещаем ось Х в положительном и отрицательном направлениях до касания заготовки с уточнением положения
Jog(0,-AJS);
while (ReadBit(SENS));
Jog(0,0);
PX0 = chan[0].Dest;
PX1 = PX0+AUP;
Delay_sec(0.2);
MoveAtVel(0,PX1,AJS);
while (!CheckDone(0));
Delay_sec(0.2);
Jog(0,-ASS);
while (ReadBit(SENS));
Jog(0,0);
PX2 = chan[0].Dest;
Delay_sec(0.2);
MoveAtVel(0,PX1,AJS);
while (!CheckDone(0));
Delay_sec(0.2);
Jog(0,AJS);
while (ReadBit(SENS));
Jog(0,0);
PX3 = chan[0].Dest;
PX4 = PX3-AUP;
Delay_sec(0.2);
MoveAtVel(0,PX4,AJS);
while (!CheckDone(0));
Delay_sec(0.2);
Jog(0,ASS);
while (ReadBit(SENS));
Jog(0,0);
PX5 = chan[0].Dest;
Delay_sec(0.2);
MoveAtVel(0,PX4,AJS);
while (!CheckDone(0));
Delay_sec(0.2);
PX6 = (PX5+PX2)/2;
Delay_sec(0.2);
MoveAtVel(0,PX6,AJS);
while (!CheckDone(0));
Delay_sec(0.2);
//Перемещаем ось Y в положительном и отрицательном направлениях до касания заготовки с уточнением положения
Jog(1,-AJS);
while (ReadBit(SENS));
Jog(1,0);
PY0 = chan[1].Dest;
PY1 = PY0+AUP;
Delay_sec(0.2);
MoveAtVel(1,PY1,AJS);
while (!CheckDone(1));
Delay_sec(0.2);
Jog(1,-ASS);
while (ReadBit(SENS));
Jog(1,0);
PY2 = chan[1].Dest;
Delay_sec(0.2);
MoveAtVel(1,PY1,AJS);
while (!CheckDone(1));
Delay_sec(0.2);
Jog(1,AJS);
while (ReadBit(SENS));
Jog(1,0);
PY3 = chan[1].Dest;
PY4 = PY3-AUP;
Delay_sec(0.2);
MoveAtVel(1,PY4,AJS);
while (!CheckDone(1));
Delay_sec(0.2);
Jog(1,ASS);
while (ReadBit(SENS));
Jog(1,0);
PY5 = chan[1].Dest;
Delay_sec(0.2);
MoveAtVel(1,PY4,AJS);
while (!CheckDone(1));
Delay_sec(0.2);
PY6 = (PY5+PY2)/2;
Delay_sec(0.2);
MoveAtVel(1,PY6,AJS);
while (!CheckDone(1));
Delay_sec(0.2);
//Присваиваем положению осей в центре отверстия X=0 и Y=0
DoPCFloat(PC_COMM_SET_X,0);
DoPCFloat(PC_COMM_SET_Y,0);
Delay_sec(0.2);
//Перемещем ось Z в положительном направлении в координату Z=0 (в машинный ноль)
MoveAtVel(2,0,AJS);
while (!CheckDone(2));
Jog(2,0);
}
//Далее код для ввода данных от DoPCFloat
int SetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_SET_VARS,varoff); // Var index and Cmd
}
int GetVars(int varoff, int n, int poff)
{
persist.UserData[PC_COMM_PERSIST+2] = n; // number of elements
persist.UserData[PC_COMM_PERSIST+3] = poff; // persist offset (doubles)
return DoPCInt(PC_COMM_GET_VARS,varoff); // Var index and Cmd
}
#define GATH_OFF 0 // define the offset into the Gather buffer where strings are passed
// Trigger a message box on the PC to be displayed
// defines for MS Windows message box styles and Operator
// response IDs are defined in the KMotionDef.h file
int MsgBox(char *s, int Flags)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
persist.UserData[PC_COMM_PERSIST+2] = Flags; // set options
DoPCInt(PC_COMM_MSG,GATH_OFF);
return persist.UserData[PC_COMM_PERSIST+3];
}
// put the MDI string (Manual Data Input - GCode) in the
// gather buffer and tell the App where it is
int MDI(char *s)
{
char *p=(char *)gather_buffer+GATH_OFF*sizeof(int);
int i;
do // copy to gather buffer w offset 0
{
*p++ = *s++;
}while (s[-1]);
// issue the command an wait till it is complete
// (or an error - such as busy)
return DoPCInt(PC_COMM_MDI,GATH_OFF);
}
// Put a Float as a parameter and pass the command to the App
int DoPCFloat(int cmd, float f)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = *(int*)&f;
return DoPC(cmd);
}
// Put an integer as a parameter and pass the command to the App
int DoPCInt(int cmd, int i)
{
int result;
persist.UserData[PC_COMM_PERSIST+1] = i;
return DoPC(cmd);
}
// Pass a command to the PC and wait for it to handshake
// that it was received by either clearing the command
// or changing it to a negative error code
int DoPC(int cmd)
{
int result;
persist.UserData[PC_COMM_PERSIST]=cmd;
do
{
WaitNextTimeSlice();
}while (result=persist.UserData[PC_COMM_PERSIST]>0);
//printf("Result = %d\n",result);
return result;
}