6.4 Special Application of NC Axis


For special applications of NC axis, for example: analog spindle movement or reciprocating motion, M4PLC32.CPP can be written as follows:


1.

At first, we were using handshake protocol PlcMotionHandShake in plc.h, and structure PlcMotionHandShake plcMotion in PlcBlock. It also had better to define PLC symbol and its value.

struct PlcMotionHandShake {

int flag;

long data0;

long data1;

int finish;

};

struct PlcBlock {

...

struct PlcMotionHandShake plcMotion;

};


The PLC parameters shown below should be defined:

#define USE_CONTI_PLC_MOTION 0x01

#define USE_B_N_F_PLC_MOTION 0x02

#define pUsePlcMotion (plcData[52]) // 0x01:continuous 0x10:back and forth


2.

The type of application to be used and the axis must be defined in plcOpen: (must be defined in plcOpen and can only be defined in plcOpen otherwise no action will be generated)


a. Continuous motion mode (For example: use the fourth axis as the spindle)

First, check the option "Rotary axis" in the fourth axis mechanical parameter. This must be selected at boot time. If not, check it and reboot. Then add the following definition in plcOpen:

if( pUsePlcMotion&USE_CONTI_PLC_MOTION ) {

// Defines the continuous motion mode and requires a given PLC_MOTION_OF_DATA0

plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS|PLC_MOTION_OF_DATA0;

plc.plcMotion.data0 = PLC_MOTION_OF_A; // PLC_MOTION_OF_CONTINUOUS axis

}


 flag: Define NC axis continuous motion mode.

 data0: Define axis.

 data1: No definition.


*((short *)&plc.plcMotion.data0+1)=20, 20 is a custom value, so:

 plcData[20]: Acceleration and deceleration of continuous motion axes.

 plcData[21]: The maximum speed of the axis of motion.


The PLC example is as follows:

if(pUsePlcMotion & USE_CONTI_PLC_MOTION){

       plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS | PLC_MOTION_OF_DATA0;

       plc.plcMotion.data0 = PLC_MOTION_OF_A;

       plc.plcMotion.flag |= PLC_MOTION_OF_PARA;

       *((short *)&plc.plcMotion.data0+1) = 22; //plcData[22]:accel plcData[23]:max rpm

   }



b. Reciprocating motion (here the Y-axis is taken as an example)

Add the following definition in plcOpen:

if( pUsePlcMotion&USE_B_N_F_PLC_MOTION ) {

// Defines the continuous motion mode and requires a given PLC_MOTION_OF_DATA1

plc.plcMotion.flag = PLC_MOTION_OF_BACK_N_FORTH|PLC_MOTION_OF_DATA1;

plc.plcMotion.data1 = PLC_MOTION_OF_Y; // PLC_MOTION_OF_BACK_N_FORTH axis

}


 flag: Define NC axis to go and return application mode.

 data0: No definition.

 data1: Define axis.


3.

In plcRun, add the following code:

a. Continuous motion mode (For example: use the fourth axis as the spindle)

The format of this movement instruction is:

Mxx, Hh1

among them,

xx: M code specified by M4PLC32.CPP

h1: Speed

Then copy the following code as required to M4PLC32.CPP.

case 33:

if( pUsePlcMotion & USE_CONTI_PLC_MOTION ) {

 if( plc.plcMotion.flag ) {

  if( plc.plcMotion.finish ) {

   plc.plcMotion.flag = 0;

   plc.mCode.finish = 1;

  }

 } else if( plc.mhAttr&PLC_MH_ATTR_0 ) {

  // PLC_MOTION_OF_DATA1 speed arrival percentage

  plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS|PLC_MOTION_OF_CW|  

  PLC_MOTION_OF_DATA0|PLC_MOTION_OF_DATA1;                        

  plc.plcMotion.data0 = plc.mhCode0; // speed

  plc.plcMotion.data1 = 90; // speed arrival percentage

 } else

  plc.mCode.finish = 1;

}

break;

case 34:

if( pUsePlcMotion & USE_CONTI_PLC_MOTION ) {

 if( plc.plcMotion.flag ) {

  if( plc.plcMotion.finish ) {

   plc.plcMotion.flag = 0;

   plc.mCode.finish = 1;

  }

 } else if( plc.mhAttr&PLC_MH_ATTR_0 ) {

  // PLC_MOTION_OF_DATA1 speed arrival percentage

  plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS|PLC_MOTION_OF_CCW|  

  PLC_MOTION_OF_DATA0|PLC_MOTION_OF_DATA1;                          

  plc.plcMotion.data0 = plc.mhCode0; // speed

  plc.plcMotion.data1 = 90; // speed arrival percentage

  }

}

break;

case 35:

if( pUsePlcMotion & USE_CONTI_PLC_MOTION ) {

 if( plc.plcMotion.flag ) {

  if( plc.plcMotion.finish ) {

   plc.plcMotion.flag = 0;

   plc.mCode.finish = 1;

  }

 } else {

  // PLC_MOTION_OF_DATA1 zero speed percentage

  plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS|PLC_MOTION_OF_STOP|  

  PLC_MOTION_OF_DATA1;                                              

  Plc.plcMotion.data1 = 10; // zero speed percentage

 }

}

break;


For overriding, add the following code: (without waiting for plc.plcMotion.finish)

static int oldSpindleOverride, curSpindleOverride;


if( pUsePlcMotion & USE_CONTI_PLC_MOTION ) {

if( curSpindleOverride != oldSpindleOverride ) {

 oldSpindleOverride = curSpindleOverride;

 plc.plcMotion.flag = PLC_MOTION_OF_CONTINUOUS|PLC_MOTION_OF_OVERRIDE|  

 PLC_MOTION_OF_DATA0;                                                  

 plc.plcMotion.data0 = oldSpindleOverride;

}

}



b. Reciprocating motion (with Y axis as example)

The format of this movement instruction is:

Mxx, Hh1, Hh2

among them,

xx: M code specified by M4PLC32.CPP

h1: Target location

h2: Speed

Add the following code to M4PLC32.CPP.

case 31:

if( pUsePlcMotion & USE_B_N_F_PLC_MOTION ) {

 if( plc.plcMotion.flag ) {

  if( plc.plcMotion.finish ) {

   plc.plcMotion.flag = 0;

   plc.mCode.finish = 1;

  }

 } else if( plc.mhAttr&PLC_MH_ATTR_0 && plc.mhAttr&PLC_MH_ATTR_1 ) {

  plc.plcMotion.flag = PLC_MOTION_OF_BACK_N_FORTH|

  PLC_MOTION_OF_DATA0|PLC_MOTION_OF_DATA1;                                          

  plc.plcMotion.data0 = plc.mhCode0 - sts.pgmPos.y; // incremental distance

  plc.plcMotion.data1 = plc.mhCode1; // speed

 } else

  plc.mCode.finish = 1;

 } else

  plc.mCode.finish = 1;

break;

case 32:

if( pUsePlcMotion & USE_B_N_F_PLC_MOTION ) {

 if( plc.plcMotion.flag ) {

  if( plc.plcMotion.finish ) {

   plc.plcMotion.flag = 0;

   plc.mCode.finish = 1;

  }

 } else

  plc.plcMotion.flag = PLC_MOTION_OF_BACK_N_FORTH|PLC_MOTION_OF_STOP;

 }

break;


For Override, add the following code: (Don't wait plc.plcMotion.finish)

static int oldBnFOverride, curBnFOverride;


if( pUsePlcMotion & USE_B_N_F_PLC_MOTION ) {

 if( curBnFOverride != oldBnFOverride ) {

  oldBnFOverride = curBnFOverride;

  plc.plcMotion.flag = PLC_MOTION_OF_BACK_N_FORTH|PLC_MOTION_OF_OVERRIDE|  

  PLC_MOTION_OF_DATA0;

  plc.plcMotion.data0 = oldBnFOverride;

 }

}


4.

About EMG, add the following code to the code that handles emgStopFlag. (does not have to wait for plc.plcMotion.finish)

if( pUsePlcMotion ) {

 // stop plc motion, no waiting plc.plcMotion.finish

 plc.plcMotion.flag = PLC_MOTION_OF_STOP;


 //  stop PLC_MOTION_OF_CONTINUOUS

 if( pUsePlcMotion & USE_CONTI_PLC_MOTION )

  plc.plcMotion.flag |= PLC_MOTION_OF_CONTINUOUS;


 //  stop PLC_MOTION_OF_BACK_N_FORTH normally

 if( pUsePlcMotion & USE_B_N_F_PLC_MOTION )

  plc.plcMotion.flag |= PLC_MOTION_OF_BACK_N_FORTH;


 //  stop PLC_MOTION_OF_BACK_N_FORTH

 // if( pUsePlcMotion & USE_B_N_F_PLC_MOTION )

 // plc.plcMotion.flag |= PLC_MOTION_OF_BACK_N_FORTH|PLC_MOTION_OF_DATA1;

}


5.

All axes used as PLC axes of motion can also be used as normal NC axes. For example, use the following instructions to position the axis:

G00 C100.

G00 Y50.


But an axis cannot be as normal axis and special application, if this axis was against the rule, the controller will occur alarm.


The following is a wrong example:

M33 ,H1000

G00 C100.


example:

.

.

.

M33 ,H1000 ; rotate CW, F=1000

.

.

G00 Y10.         ; BACK_N_FORTH motion initial position

M31 ,H40. ,H1000 ; BACK_N_FORTH motion target position

; 30mm relative to initial position

; Y-axis moves between 10mm and 40mm

.

.

M32 ; stop BACK_N_FORTH motion at initial position

M35 ;axis stop

.

.

M30