This is an old revision of the document!
Table of Contents
Software PLC examples
Endless loop for G-code program
An endless loop can be made in Software PLC procedure. PLC procedure contains an endless loop. In the loop it checks the current status of myCNC controller, if the controller is in Idle mode and ready to run a new program, it reloads G-code file (if needed), reset current program pointer and starts running g-code.
PLC code is -
- ENDLESS.plc
main() { do { do{ a=gvarget(6065); }while(a!=0); //wait Motion Controller ready to accept new program gvarset(100001,1); //Reset G-code pointer to start timer=5; do{ timer--;}while(timer>0); //0.5 sec Pause gvarset(100002,1); //Start G-code }while(1); //endless loop exit(99); };
If Stop button pressed, g-code will be stopped, the procedure will see Motion controller is ready for next loop entry and restart g-code again. This behaviour can be inappropriate for many applications.
A simple solution is to add global variable single/auto and check this variable in the loop.
- NOT_ENDLESS.plc
main() { do { do{ a=gvarget(6065); }while(a!=0); //wait Motion Controller ready to accept new program gvarset(100001,1); //Reset G-code pointer to start timer=5; do{ timer--;}while(timer>0); //0.5 sec Pause gvarset(100002,1); //Start G-code }while(gvarget(400)==0); //endless loop, if #400==0, otherwise exit from procedure exit(99); }; //If variable #400 will be set to non-zero value, NOT_ENDLESS.plc process will be finished
In case no need to exit from ENDLESS.plc and variable #400 should be monitored constantly and run g-code when #400 is set bu user -
- ENDLESS2.plc
main() { do { if (gvarget(400)!=0) //if #400!=0, run g-code, otherwise continue to test #400 { do{ a=gvarget(6065); }while(a!=0); //wait Motion Controller ready to accept new program gvarset(100001,1); //Reset G-code pointer to start timer=5; do{ timer--;}while(timer>0); //0.5 sec Pause gvarset(100002,1); //Start G-code }; }while(1); //endless loop exit(99); }; //If variable #400 will be set to non-zero value, ENDLESS.plc process will be finished
Endless loop with switch to left & right sides of working area
- LEFT-RIGHT.plc
#define MAX_X 800 #define MAX_Y 800 main() { do { auto=gvarget(501); //Automatic mode if (auto) { do { rect_not_ready=gvarget(7369); }while(rect_not_ready==0); left_right=1; xmax=gvarget(7350); if (xmax>MAX_X){ left_right=0;}; ymax=gvarget(7351); if (ymax>MAX_Y){ left_right=0;}; gvarset(502,left_right); //502 - показывает обе стороны или одна LR=gvarget(500); if (LR==0) //левая { // gvarset(9100,1); //показать сообщение №1 //do{ a=portget(11); }while(a==0); //ждем педаль, 11 вход //do{ a=gvarget(6065); }while(a!=0); //ждем педаль, 11 вход // gvarset(9100,0); //убрать сообщение portclr(10);//Vacuum Left OFF portset(9); // portset(11);// portset(22);// // gvarset(9101,1); //показать сообщение №2 //do{ a=portget(13); }while(a==0); //ждем педаль, 13 вход // gvarset(9101,0); //убрать portset(10);//Vacuum Left portclr(9); // timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока присоски сработают portclr(11);//выключить упоры portclr(22);// //// //ждать пока УП завершится do{ a=gvarget(6065); }while(a!=0); //ждем //// do { do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы gvarset(100010,54); //Дать код G54 timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока сменится система n=gvarget(5220);//получить текущий номер системы координат } while(n!=1); //пока текущая система не G54 do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы gvarset(100001,1); //сбросить программу в начало timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы gvarset(100002,1); //запустить программу }else //правая { // gvarset(9110,1); //показать сообщение №1 // do{ a=portget(12); }while(a==0); //ждем педаль, 11 вход // gvarset(9110,0); //убрать сообщение portclr(15); //Vacuum Left OFF portset(16); // portset(14); // portset(23); // // gvarset(9111,1); //показать сообщение №2 // do{ a=portget(14); }while(a==0); //ждем педаль, 13 вход // gvarset(9111,0); //убрать portset(15); //Vacuum Left portclr(16); // timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока присоски сработают portclr(14);//выключить упоры portclr(23);// //// do{ a=gvarget(6065); }while(a!=0); //ждем //ждать пока УП завершится //// do{ do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы gvarset(100010,55); //Дать код G54 timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек пока сработает смена координат n=gvarget(5220);//получить текущий номер системы координат } while(n!=2);//пока текущая система не G55 do{ a=gvarget(6065); }while(a!=0); //ждем пока процессор занят gvarset(100001,1); //сбросить программу в начало timer=5; do{ timer--; }while(timer>0); //ждем 0.5 сек do{ a=gvarget(6065); }while(a!=0); //ждем готовности системы gvarset(100002,1); //запустить программу }; timer=20; do{ timer--; }while(timer>0); //пауза на 3 сек, что программа стартовала do{ a=gvarget(6065); }while(a!=0); //ждем пока завершится программа LR=LR^1; //переключить на другую сторону gvarset(500,LR); };//auto }while(1); exit(99); };
Jog Step (0.001, 0.01, 0.1 1.0) Indication with external LED display
There are global variables which represent current jog step size
Variable Name | Variable Number | Description |
---|---|---|
GVAR_JOG_STEP_SIZE | 5522 | prepresents current jog step size (double) |
GVAR_JOG_STEP_0_0001 | 7381 | the value is “1” if Current Jog Step Size is “0.0001”, otherwize is “0” (integer) |
GVAR_JOG_STEP_0_001 | 7382 | the value is “1” if Current Jog Step Size is “0.001”, otherwize is “0” (integer) |
GVAR_JOG_STEP_0_01 | 7383 | the value is “1” if Current Jog Step Size is “0.01”, otherwize is “0” (integer) |
GVAR_JOG_STEP_0_1 | 7384 | the value is “1” if Current Jog Step Size is “0.1”, otherwize is “0” (integer) |
GVAR_JOG_STEP_1_0 | 7385 | the value is “1” if Current Jog Step Size is “1.0”, otherwize is “0” (integer) |
GVAR_JOG_STEP_10 | 7386 | the value is “1” if Current Jog Step Size is “10”, otherwize is “0” (integer) |
Software PLC procedure can be made to handle LED display according to “Current Jog Step Size”.
- The procedure contains an endless loop.
- Variables a7382…a7385 keep previous state or “Current Jog Step Size”
- There are testing “Current Jog Step Size” global variables values, switching binary output if variables were changed and store new states in the a7382…a7385 local variables
- JOG_STEP_LEDS
main() { a7382=gvarget(7382); a7383=gvarget(7383); a7384=gvarget(7384); a7385=gvarget(7385); do{ if (gvarget(7382)!=a7382) { a7382=gvarget(7382); if (a7382==0){portclr(14);}else {portset(14);}; }; if (gvarget(7383)!=a7383) { a7383=gvarget(7383); if (a7383==0){portclr(13);}else {portset(13);}; }; if (gvarget(7384)!=a7384) { a7384=gvarget(7384); if (a7384==0){portclr(12);}else {portset(12);}; }; if (gvarget(7385)!=a7385) { a7385=gvarget(7385); if (a7385==0){portclr(11);}else {portset(11);}; }; }while(1); exit(99); };