Заметил интерестную особенность.
У меня на станке включение усилителей и двигателей происходит только после нажатия на кнопку инит. При нажатии СТОП на нее питание подается но двигателя выключены. Все так и работает, но если проводить процедуру ХОУМ или если во время нее возник какой-то сбой, то при нажатии СТОП, двигателя двигаются и для того что бы их остановить нужно опять нажать инит и СТОП. Как это побороть?
Код для ХОУМ
(для просмотра содержимого нажмите на ссылку)#include "KMotionDef.h"
//simple routine to:
//
// #1 disable limits
// #2 jog to a limit at speed
// #3 Reverse till index pulse
// #4 stop
// #5 zero the axis
// #6 move back inside
// #7 enable limits
int SimpleHomeIndexFunction(int axis, // axis number to home
float speed, // speed to move toward home
int dir, // direction to move toward home (+1 or -1)
int limitbit, // limit bit number to watch for
int limitpolarity, // limit polarity to wait for (1 or 0)
float indexspeed, // speed to move while searching for index
int indexbit, // index bit number to watch for (use -1 for none)
int indexpolarity, // index polarity to wait for (1 or 0)
float offset) // amount to move inside limits
{
int SaveLimits; //place to save limit switch settings
//DisableAxis(axis); -------------------
// disable the limits (first save how they were set)
SaveLimits = chan[axis].LimitSwitchOptions;
chan[axis].LimitSwitchOptions = 0;
//EnableAxis(axis); // enable axis and begin servoing where we are ---------------------
// Home - jog until it sees the limit
Jog(axis,speed*dir); // jog slowly
while (ReadBit(limitbit)!=limitpolarity) // loop until Limit bit goes to specified polarity
if (!chan[axis].Enable) return 1; // abort/exit if disabled
chan[axis].set = 20
if (indexbit!=-1) // index bit specified?
{
Jog(axis,-indexspeed*dir); // reverse and jog slowly
while (ReadBit(indexbit)!=indexpolarity) // loop until index bit goes to specified polarity
if (!chan[axis].Enable) return 1; // abort/exit if disabled
}
Jog(axis,0); // stop
while (!CheckDone(axis)) // loop until motion completes
if (!chan[axis].Enable) return 1; // abort/exit if disabled
//DisableAxis(axis); // disable the axis-------------------
Zero(axis); // Zero the position
//EnableAxis(axis); // re-enable---------------------------
Move(axis,-dir * offset); // move some amount inside the limits
while (!CheckDone(axis)) ; // loop until motion completes
if (!chan[axis].Enable) return 1; // abort/exit if disabled
chan[axis].LimitSwitchOptions = SaveLimits; // restore limit settings
return 0;
}
int DoPC(int cmd);
int DoPCInt(int cmd, int i);
#define GATH_OFF 0 // define the offset into the Gather buffer where strings are passed
main()
{
//определяем пины для индексных меток, как ВХОД
SetBitDirection(36,0); // для оси Х
SetBitDirection(37,0); // для оси Y
SetBitDirection(38,0); // для оси Z
// поиск НОМЕ по Z
SimpleHomeIndexFunction(
2, // axis number to home
2500, // speed to move toward home
1, // direction to move toward home (+1 or -1)
138, // limit bit number to watch for
1, // limit polarity to wait for (1 or 0)
2000, // speed to move while searching for index
38, // index bit number to watch for (use -1 for none)
1, // index polarity to wait for (1 or 0)
400); // amount to move inside limits
// поиск НОМЕ по X
SimpleHomeIndexFunction(
0, // axis number to home
2330, // speed to move toward home
-1, // direction to move toward home (+1 or -1)
136, // limit bit number to watch for
1, // limit polarity to wait for (1 or 0)
2000, // speed to move while searching for index
36, // index bit number to watch for (use -1 for none)
1, // index polarity to wait for (1 or 0)
390.625); // amount to move inside limits
// поиск НОМЕ по y
SimpleHomeIndexFunction(
1, // axis number to home
2330, // speed to move toward home
-1, // direction to move toward home (+1 or -1)
137, // limit bit number to watch for
1, // limit polarity to wait for (1 or 0)
2000, // speed to move while searching for index
37, // index bit number to watch for (use -1 for none)
1, // index polarity to wait for (1 or 0)
400); // amount to move inside limits
MDI("G92.1"); // очистка всех действующих оффсетов
}
//далее код обеспечивающий ввод команды в MDI
// 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 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);
return result;
}