User Tools

Site Tools


plc:plc_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
plc:plc_examples [2017/10/20 18:49] skirillovplc:plc_examples [2017/10/20 18:55] skirillov
Line 181: Line 181:
 ==== Gantry Alignment Procedure (with Homing) ==== ==== Gantry Alignment Procedure (with Homing) ====
  
-<code c file=M132>+<code c M132>
 G10 L80 P5521 Q1 G10 L80 P5521 Q1
 G10 L80 P5525 Q1 G10 L80 P5525 Q1
Line 192: Line 192:
 G91 G0 Y   300.0000 F    30.00 G91 G0 Y   300.0000 F    30.00
 G04 P0.1 G04 P0.1
- 
 M135 M135
 +</code>
 +
 +<code c M135>
 +G10 L80 P5521 Q1
 +G10 L80 P5525 Q1
 +
 +M146 P0 L1028
 +
 +M144
 +G91 G0 Y100 F30
 +G04 P0.1
 +
 +G90 G10 L70 P0 Y0
 +G04 P0.1
 +M145 P0 L1028
 +G90 G10 L193 P97 Q5531
 +
 +debug #98
 +G90 G10 L192 P98 Q7525
 +debug #98
 +debug #97
 +G90 G10 L190 P97 Q98
 +debug #97
 +
 +G90 G28.9 Y97 F200
 +
 +M146 P0 L1028
 +
 +G90 G10 L70 P0 Y0
 +
 +G90 G10 L80 P5521 Q0
 +G90 G10 L80 P5525 Q0
 +G90 G10 L80 P7395 Q0 (Homing Flag)
 +
 +</code>
 +
 +<code c M144.plc>
 +//Look after input1 & input2 sensors, remember position, when triggered
 +
 +main()
 +{
 +
 +timer=0;
 +
 +message=PLCCMD_MOTION_CONTINUE;
 +texit=timer+2;do{timer++;}while(timer<texit);
 +
 +ready=0;
 +
 +state1=0;
 +state2=0;
 +
 +e9000=portget(13);//gvarget(9000);
 +e9001=portget(14);//gvarget(9001);
 +
 +state0=0;
 +
 +m1=0;
 +m2=0;
 +
 +do
 +{
 + timer++;
 +
 +if (state0==0)
 +{
 + a=portget(13);//gvarget(9000);
 + if (a!=e9000)
 + {
 + m1=1;
 + position1=gvarget(5021+1); //Machine Y
 +state0=1;
 + };
 + a=portget(14);//gvarget(9100);
 + if (a!=e9001)
 + {
 + m1=2;
 + position1=gvarget(5021+1); //Machine Y
 +state0=1;
 + };
 +}else
 +{
 +if (m1==2)
 +{
 + a=portget(13);//gvarget(9000);
 + if (a!=e9000)
 + {
 + m2=1;
 + position2=gvarget(5021+1); //Machine Y
 +state0=2;
 + };
 +}else
 +{
 + a=portget(14);//gvarget(9100);
 + if (a!=e9001)
 + {
 + m2=2;
 + position2=gvarget(5021+1); //Machine Y
 +state0=2;
 + };
 +};
 +};
 +
 +
 +}while(state0<2);
 +
 +
 +b=position1-position2;
 +
 +
 +
 +if (b>25000)
 +{
 +b=50000-b;
 +};
 +c=0-25000;
 +if (b<c)
 +{
 +b=50000+b;
 +};
 +
 +
 +
 +gvarset(97,b);
 +texit=timer+30;do{timer++;}while(timer<texit);
 +
 +gvarset(7230,m1);
 +if (m1==1) { gvarset(98,1);}
 +else { x=0-1; gvarset(98,x);};
 +
 +message=PLCCMD_MOTION_SKIP;
 +//message=PLCCMD_MOTION_SOFT_SKIP;
 +texit=timer+2;do{timer++;}while(timer<texit);
 +
 +exit(99);
 +};
 +</code>
 +
 +<code c M145.plc>
 +#define var_address var00
 +#define var_value   var01
 +
 +main()
 +{
 + timer=0;
 +
 + lparam=eparam>>16;
 +
 +  axis=1;     //
 + n=gvarget(7230);
 +
 + channel=0xff;
 + if (n==1) {channel=0;};
 + if (n==2) {channel=1;};
 + if (n==4) {channel=2;};
 + if (n==8) {channel=3;};
 +
 + if (channel>8)
 + {
 + message=PLCCMD_MOTION_ABORT;
 + texit=timer+2;do{timer++;}while(timer<texit);
 + exit(99);
 + };
 +
 +
 + var_value=15;
 + var_address=112+channel;//channel turn off
 + message=PLCCMD_SET_CNC_VAR;
 + texit=timer+2;do{timer++;}while(timer<texit);
 +
 + exit(99);
 +
 +};
 +</code>
 +
 +<code c M146.plc>
 +#define var_address var00
 +#define var_value   var01
 +
 +main()
 +{
 + timer=0;
 +
 +  dir=0;
 +
 +  axis=1;
 +  channel=0;
 +
 + var_address=112+channel;//channel 0 set up
 + var_value=axis;
 + if (dir!=0) {  var_value=16+axis;  };
 + message=PLCCMD_SET_CNC_VAR;
 + texit=timer+10;do{timer++;}while(timer<texit);
 +
 +
 +  channel=1;
 +
 + var_address=112+channel;//channel 0 set up
 + var_value=axis;
 + if (dir!=0) {  var_value=16+axis;  };
 + message=PLCCMD_SET_CNC_VAR;
 + texit=timer+10;do{timer++;}while(timer<texit);
 +
 + gvarset(7230,1);
 +
  
 + exit(99);
 +};
 </code> </code>
-<code c></code> 
-<code c></code> 
-<code c></code> 
-<code c></code> 
  
plc/plc_examples.txt · Last modified: 2024/02/21 13:59 by ivan

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki