User Tools

Site Tools


plc:oil_change_counter

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
Last revisionBoth sides next revision
plc:oil_change_counter [2017/12/09 11:01] esplc:oil_change_counter [2017/12/11 00:23] es
Line 9: Line 9:
 We take **1280M5** profile as based profile to add **Oil Change Counter **. We take **1280M5** profile as based profile to add **Oil Change Counter **.
  
 +
 +{{mycnc:mycnc-oil-change-.png}}
 +
 +
 +<code c>
 +main()
 +{
 +//touch global variables 6890,6891,6892 to save its values in cnc-variables.xml
 +gvarset(6890,gvarget(6890));
 +gvarset(6891,gvarget(6891));
 +gvarset(6892,gvarget(6892));
 +
 +//get initial machine coordinates  for x,y,z
 +pos_x=gvarget(5021);
 +pos_y=gvarget(5022);
 +pos_z=gvarget(5023);
 +
 +//initialize ticks counter
 +ticks=0;
 +
 +
 +//endless loop to handle Oil-Change Counter
 +do{
 +
 +//read limit Limit values for all axes x,y,x and arrange it to Meters
 +limit_x=gvarget(6890)*1000;
 +limit_y=gvarget(6891)*1000;
 +limit_z=gvarget(6892)*1000;
 +
 +
 +//X axis handler
 +//Check if X position changed
 +dx=pos_x-gvarget(5021);
 +if (dx!=0)
 +{
 + pos_x=gvarget(5021);//update changes
 + if (dx<0){dx=0-dx;};//get absoluet value of x moves
 +//check move length does not exceed 10mm (to exclude possible error)
 +//and add move length to variable #6090
 + if (dx<10){gvarset(6090,gvarget(6090)+dx); };
 +};
 +
 +//Y axis handler
 +dy=pos_y-gvarget(5022);
 +if (dy!=0)
 +{
 + pos_y=gvarget(5022);
 + if (dy<0){dy=0-dy;};
 + if (dy<10){gvarset(6091,gvarget(6091)+dy); };
 +};
 +
 +//Z axis handler
 +dz=pos_z-gvarget(5023);
 +if (dy!=0)
 +{
 + pos_z=gvarget(5023);
 + if (dz<0){dz=0-dz;};
 + if (dz<10){gvarset(6092,gvarget(6092)+dz); };
 +};
 +
 +
 +
 +//Check is any axis mileage exceed limit
 +alarm=0;
 +if (gvarget(6090)>limit_x) { alarm=1; };
 +if (gvarget(6091)>limit_y) { alarm=1; };
 +if (gvarget(6092)>limit_z) { alarm=1; };
 +
 +
 +
 +//In case Oil-Change event handle varaible #6085 blink 1 time per second
 +if (alarm!=0)
 +{
 +  ticks++;
 +  if (ticks<8) {gvarset(6085,0);}
 +  else {gvarset(6085,1);};
 +
 +  if (ticks>10) {ticks=0;};
 +}else
 +{
 +  gvarset(6085,0);portclr(0);
 +};
 +
 +
 +}while(1);
 +
 +
 +exit(99);
 +};
 +
 +</code>
plc/oil_change_counter.txt · Last modified: 2017/12/11 00:26 by es

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki