LauMotion

NEED HELP, TwinCat 3 NCI SlaveAxis

7 posts in this topic

i am trying to set up dual motors   "master and slave"  on a X axis in TwinCat NCI ,   so far i don some test with "MC_GearIn"   but i keep getting this error       "Error    40    14-05-2016 11:27:39 417 ms | 'TCNC' (500): NC-Ctrl (R0), Cannot configurate axis 4 into group 4 because a slave is coupled or this axis is a slave itself (CoupleState: 1) !!"                when i activate NCI.

also i did try using a virtual axis as X and link two slave , but i get the same result :(

 

anybody knows how to do this ?

 

Share this post


Link to post
Share on other sites

Hey there! Did you solve your problem? Because I have the same problem.

But I coupled  each axes in motion, I didn't use MC_GearIn. 

Many thanks,

Share this post


Link to post
Share on other sites

Hi , yes i use MC_GearIn after i have created the "NCI interpolation group"  works fine.

How can i do it in motion ?

1 person likes this

Share this post


Link to post
Share on other sites
34 minutes ago, LauMotion said:

Hi , yes i use MC_GearIn after i have created the "NCI interpolation group"  works fine.

How can i do it in motion ?

I use this way (shared as photo).

Do you have an example for solution for share?

Thanks,

Untitled.png

Edited by serhatozyildiz

Share this post


Link to post
Share on other sites
16 hours ago, LauMotion said:

Hi , yes i use MC_GearIn after i have created the "NCI interpolation group"  works fine.

How can i do it in motion ?

I tried that way and it works now. but  when I cancel the MC_GearIn after my NCI program end, it gives error. When should I cancel the MC_GearIn after NCI program end?

Share this post


Link to post
Share on other sites

Here is some code i used for testing back in 2016, for two X axis.
Hope it helps:-)
 

	(******* Main Program, State Machine  *******)
	
CASE nState OF
0:  (******* Manual mode *******)
    IF nState <> 60 AND NOT bTestLaser THEN bTurnLaserOn := FALSE; ELSE bTurnLaserOn := TRUE;  END_IF 
	(* Home Axis *)
	fbMC_HomeX(Axis:=  X_AXIS, Execute:=bHomeX , Position:=0 , HomingMode:=0 , bCalibrationCam:=NOT bHome_X_CAM ,);
    fbMC_HomeX2(Axis:= X2_AXIS,Execute:=bHomeX , Position:=0 , HomingMode:=0 , bCalibrationCam:=NOT bHome_X2_CAM ,);
    fbMC_HomeY(Axis:=  Y_AXIS, Execute:=bHomeY , Position:=0 , HomingMode:=0 , bCalibrationCam:=NOT bHome_Y_CAM ,);
	(* Jog Axis*)
	
	
	IF iJogMode = 1 THEN JogMode := MC_JOGMODE_STANDARD_FAST ; END_IF;
	IF iJogMode = 2  THEN JogMode := MC_JOGMODE_INCHING   ; END_IF;
	IF iJogMode = 3  THEN JogMode := MC_JOGMODE_INCHING   ; END_IF;
	IF iJogMode = 4  THEN JogMode := MC_JOGMODE_INCHING   ; END_IF;
	IF iJogMode = 5  THEN JogMode := MC_JOGMODE_INCHING   ; END_IF;
    fbMC_Jog_Y(Axis:=  Y_AXIS, JogForward:= bJogForwardY,JogBackwards:=bJogBackwardsY,Mode:= JogMode,Velocity:=800,Position:=lrJogDistance,);  	
    fbMC_Jog_X(Axis:=  X_AXIS, JogForward:= bJogForwardX,JogBackwards:=bJogBackwardsX,Mode:= JogMode,Velocity:=800,Position:=lrJogDistance,);
    fbMC_Jog_X2(Axis:= X2_AXIS,JogForward:= bJogForwardX,JogBackwards:=bJogBackwardsX,Mode:= JogMode,Velocity:=800,Position:=lrJogDistance,); 
    (* Store Zero shift G54 *)
    IF bZeroX THEN arr_ZeroShiftDesc[54].fShiftX:= X_AXIS.NcToPlc.ActPos; END_IF;
	IF bZeroY THEN arr_ZeroShiftDesc[54].fShiftY:= Y_AXIS.NcToPlc.ActPos; END_IF;
	(* Run A G-code *)
	IF bExec THEN bBusy	:= TRUE;bErr	:= FALSE;nErrId	:= 0;nLastState	:= 0;nState := 10;END_IF
	
10: (******* build interpolation group *******)
	fbBuildGrp(bExecute	:= TRUE ,nGroupId	:= ItpGetGroupId(sNciToPlc:= in_stItpToPlc),nXAxisId	:=  X_AXIS.NcToPlc.AxisId,nYAxisId	:=  Y_AXIS.NcToPlc.AxisId,tTimeOut:= T#200MS);
    IF NOT fbBuildGrp.bBusy THEN fbBuildGrp( bExecute := FALSE );IF NOT fbBuildGrp.bErr THEN nState	:= 11;
	ELSE (* an error occured *) bErr:= TRUE; nErrId	:= fbBuildGrp.nErrId; nLastState:= nState; nState:= 510; END_IF END_IF
	
11: (******* Write ZeroShift [G54] *******)			
	fbItpWriteZeroShiftEx(bExecute:= TRUE,nZsNo:= 54,tTimeOut:= T#2S,sNciToPlc:= in_stItpToPlc,sZeroShiftDesc:= arr_ZeroShiftDesc[54],);
	IF NOT fbItpWriteZeroShiftEx.bBusy THEN fbItpWriteZeroShiftEx(bExecute:= FALSE,nZsNo:= 54,tTimeOut:= T#2S,sNciToPlc:= in_stItpToPlc,sZeroShiftDesc:= arr_ZeroShiftDesc[54], );	
	IF NOT fbItpWriteZeroShiftEx.bErr THEN nState:= 12; 
    ELSE (* an error occured *)  bErr:= TRUE; nErrId:= fbItpWriteZeroShiftEx.nErrId; nLastState	:= nState; nState:= 510; END_IF END_IF;	
				
12: (******* Write R Parameters *******)	
    fbItpWriteRParamsEx(bExecute:= TRUE, pAddr:= ADR (arr_R_ParameterToNci), nIndex:= 0, nCount:= SIZEOF(arr_R_ParameterToNci) / SIZEOF(arr_R_ParameterToNci[1]), tTimeOut:= T#2S, sNciToPlc:= in_stItpToPlc, );		
    IF NOT fbItpWriteRParamsEx.bBusy THEN
	fbItpWriteRParamsEx(bExecute:= FALSE, pAddr:= ADR (arr_R_ParameterToNci), nIndex:= 0, nCount:= SIZEOF(arr_R_ParameterToNci) / SIZEOF(arr_R_ParameterToNci[1]), tTimeOut:= T#2S, sNciToPlc:= in_stItpToPlc,);	IF NOT fbItpWriteRParamsEx.bErr THEN 
	iIndex:=1;   nState:= 13;
	ELSE (* an error occured *)bErr:= TRUE; nErrId:= fbItpWriteRParamsEx.nErrId; nLastState:=nState;nState:= 510;END_IF END_IF
	
13:	(******** Write Tool Parameters *******)	
	fbItpWriteToolDescEx(bExecute:= TRUE,nDNo:= iIndex, tTimeOut:= T#2S, sNciToPlc:=in_stItpToPlc , sToolDesc:= arr_ToolDescToNci[iIndex], );
    IF NOT fbItpWriteToolDescEx.bBusy THEN fbItpWriteToolDescEx(bExecute:= FALSE, nDNo:= 1, tTimeOut:= T#2S, sNciToPlc:=in_stItpToPlc , sToolDesc:= arr_ToolDescToNci[1],);
	IF NOT fbItpWriteToolDescEx.bErr THEN 
	nState := 14;
	ELSE (* an error occured *) bErr:= TRUE;nErrId	:= fbItpWriteToolDescEx.nErrId; nLastState	:= nState; nState:= 510;END_IF END_IF
	
14: (******** Check if more Tool Parameters *******)

    IF iIndex = 2 THEN nState:= 20; ELSE iIndex:= iIndex +1 ;  nState := 13 ; END_IF
	
20:(******* load part program *******)
	fbLoadProg(bExecute	:= TRUE,sPrg:= sFileName,nLength:= LEN(sFileName),tTimeOut:= T#200MS,sNciToPlc:=in_stItpToPlc);
    IF NOT fbLoadProg.bBusy THEN fbLoadProg( bExecute:=FALSE, sNciToPlc:=in_stItpToPlc);IF NOT fbLoadProg.bErr THEN nState	:= 30;
	ELSE(* an error occured *)bErr:= TRUE;nErrId:= fbLoadProg.nErrId;nLastState:=nState;nState:= 510;END_IF END_IF

30:(******* wait until interpreter is in ready state *******)
    nItpState	:=	ItpGetStateInterpreter(  in_stItpToPlc );
	IF nItpState = NCI_INTERPRETER_READY THEN
	(* load part program succeeded *) 
    nState	:= 31;
	ELSIF nItpState = NCI_INTERPRETER_ABORTED THEN
	(* load program failed - probably there is a load time error, e.g. syntax error *)
	(* add error handling here *)bErr:= TRUE;nErrId	:= 4711;	(* substitute with own error code *)   nLastState:= nState;nState:= 510;	END_IF

31:(******* Gear In X + X2 *******)
    fbMC_GearIn(Master:= X_AXIS,Slave:= X2_AXIS,Execute:= TRUE,RatioNumerator:=1,RatioDenominator:=1,);
    IF fbMC_GearIn.InGear THEN fbMC_GearIn( Master:= X_AXIS, Slave:= X2_AXIS, Execute:= FALSE,);IF NOT fbMC_GearIn.Error THEN nState	:= 40;     
    ELSE (* an error occured *)bErr		:= TRUE;nErrId	:= fbMC_GearIn.ErrorID;nLastState:= nState;nState:= 510;END_IF END_IF 

40:(******* start part program *******)
	fbStart(bStart	:= TRUE,bStop		:= FALSE,tTimeOut	:= T#200MS,sNciToPlc:= in_stItpToPlc );
    IF NOT fbStart.bBusy THEN fbStart( bStart:=FALSE, sNciToPlc:=in_stItpToPlc );IF NOT fbStart.bErr THEN nState:= 50;
	ELSE(* an error occured *)bErr:= TRUE;nErrId:= fbStart.nErrId;nLastState	:= nState;nState	:= 510;END_IF END_IF

50: (******* check if the part program is really started *******)
	(* as long as the part program is active we are not in the ready state *)
	(* if the part program has finished without an error we switch back to the ready state *)
	(* if the program has finished with an error the interpreter is in the aborted state *)
	nItpState	:=	ItpGetStateInterpreter( in_stItpToPlc );
	IF nItpState <> NCI_INTERPRETER_READY THEN
	nState	:= 60; END_IF
	
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
60: (******* Running State *******)
    (* Stop *)
	
	IF bStop THEN nState := 61; END_IF;
	(* confirm m-func - e.g. m30 *)
	
	bTurnLaserOn := ItpIsFastMFunc( nFastMFuncNo:= FastMFuncs.M22_LaserOn,sNciToPlc:= in_stItpToPlc );
	
	(* Laser Power *)
	
	IF ( ItpIsHskMFunc(in_stItpToPlc) ) THEN bConfirm:= TRUE; ELSE bConfirm	:= FALSE; END_IF
	fbConfirm(bExecute:= bConfirm,sNciToPlc:= in_stItpToPlc,sPlcToNci:=  out_stPlcToItp );IF NOT fbConfirm.bBusy THEN IF fbConfirm.bErr 
    THEN(* an error occured *)
	(* this usually can just occur, if a confirmation is triggered without a request *)	
	bErr:= TRUE; nErrId	:= fbStart.nErrId; nLastState	:= nState; nState	:= 510; END_IF END_IF
    nItpState:=	ItpGetStateInterpreter(  in_stItpToPlc );
	IF nItpState = NCI_INTERPRETER_READY THEN
	(* part program is finished without an error *)
	fbConfirm( bExecute:= FALSE, sNciToPlc:=  in_stItpToPlc, sPlcToNci:=  out_stPlcToItp );
	nState	:= 69;
	ELSIF nItpState = NCI_INTERPRETER_ABORTED THEN
	(* a runtime error occured - e.g. a lag distance error occured *)
	 bErr:= TRUE;  nErrId	:= ItpGetError(in_stItpToPlc);nLastState:= nState;nState:= 510;	END_IF
	 
	 
	 
	 
	 
	 
	 
	 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	

	 
61: (******* Stop State *******)
    
    bTurnLaserOn:= FALSE;
    fbItpEStopEx(sNciToPlc:=in_stItpToPlc,bExecute:=TRUE,);
	IF NOT fbItpEStopEx.bBusy THEN 
	fbItpEStopEx(sNciToPlc:=in_stItpToPlc,bExecute:=FALSE,);
	IF NOT fbItpEStopEx.bErr THEN nState := 62;
    ELSE(* an error occured *)bErr:= TRUE;nErrId:= fbItpEStopEx.nErrId;nLastState:= nState;nState:= 510;END_IF  END_IF

62:(******* Restart Part Program *******)
    IF bReset THEN nState := 63; END_IF 
    IF bExec THEN fbItpStepOnAfterEStop(bExecute:=TRUE,nGrpId:=5,);
	IF NOT fbItpStepOnAfterEStop.bBusy THEN	
	fbItpStepOnAfterEStop(bExecute:=FALSE,nGrpId:=5,);
	IF NOT fbItpStepOnAfterEStop.bErr THEN nState := 60;
	ELSE(* an error occured *)bErr:= TRUE;nErrId:= fbItpStepOnAfterEStop.nErrId;nLastState	:= nState;nState	:= 510;END_IF END_IF END_IF 
  
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
63: (******* Reset *******)
	fbItpResetEx2(bExecute:=TRUE ,sNciToPlc:=in_stItpToPlc , );
	IF NOT fbItpResetEx2.bBusy THEN
	fbItpResetEx2(bExecute:=FALSE,sNciToPlc:=in_stItpToPlc,);
	IF NOT fbItpResetEx2.bErr THEN nState:=69;
	ELSE(* an error occured *)bErr:= TRUE;nErrId	:= fbItpResetEx2.nErrId;nLastState	:= nState;nState	:= 510;END_IF END_IF

69: (******* Gear out *******)
    fbMC_GearOut(Slave:=X2_AXIS,Execute:=TRUE,);
	IF fbMC_GearOut.Done THEN fbMC_GearOut(Slave:=X2_AXIS,Execute:=FALSE ,) ;
	IF NOT fbMC_GearOut.Error THEN nState := 70;
	ELSE(* an error occured *)bErr		:= TRUE;nErrId	:= fbMC_GearOut.ErrorID;nLastState	:= nState;nState	:= 510;END_IF END_IF

70: (******* clear interpolation group *******)
	fbClearGrp(bExecute:= TRUE,nGroupId:= ItpGetGroupId(sNciToPlc:=in_stItpToPlc),tTimeOut:= T#200MS);
    IF NOT fbClearGrp.bBusy THEN fbClearGrp(bExecute:= FALSE);IF NOT fbClearGrp.bErr THEN nState	:= 500;
    ELSE(* an error occured *)bErr:= TRUE;nErrId	:= fbClearGrp.nErrId;nLastState	:= nState;nState	:= 510;END_IF END_IF

500: (******* Finsh *******)
    bBusy:=FALSE;IF NOT bExec THEN nState:= 0;END_IF IF bReset THEN nState := 0;END_IF
	
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
510: (******* Error State *******)
    
    fbItpEStopEx(sNciToPlc:=in_stItpToPlc ,bExecute:=TRUE, );
	fbBuildGrp( bExecute := FALSE );
	fbLoadProg(bExecute	:= FALSE,sPrg:= sFileName,tTimeOut	:= T#200MS,sNciToPlc:=  in_stItpToPlc );
	fbMC_GearIn(Master:= X_AXIS,Slave:= X2_AXIS,Execute:= FALSE,RatioNumerator:=1,RatioDenominator:=1, );
	fbMC_ResetX(Axis:=X_AXIS , Execute:=FALSE, );
    fbMC_ResetX2(Axis:=X_AXIS , Execute:=FALSE , );
    fbMC_ResetY(Axis:=X_AXIS , Execute:=FALSE , );
	IF bReset THEN nState:= 511;END_IF

511:  (******* Reset State *******)
    fbMC_GearOut(Slave:=X2_AXIS,Execute:=TRUE,);
	fbClearGrp(bExecute:= TRUE,nGroupId:= ItpGetGroupId(sNciToPlc:=in_stItpToPlc),tTimeOut:= T#200MS);
	fbItpResetEx2(bExecute:=TRUE,tTimeOut:=,sNciToPlc:=in_stItpToPlc ,);
	fbMC_ResetX(Axis:=X_AXIS , Execute:=TRUE, );
    fbMC_ResetX2(Axis:=X_AXIS , Execute:=TRUE , );
    fbMC_ResetY(Axis:=X_AXIS , Execute:=TRUE , );
	fbTimer(IN:=TRUE , PT:=T#200MS , Q=> , ET=> );
    IF fbTimer.Q THEN nState:=512;END_IF  

512: (******* Error State *******)
    fbItpEStopEx(sNciToPlc:=in_stItpToPlc ,bExecute:=FALSE, );
    fbMC_GearOut(Slave:=X2_AXIS,Execute:=FALSE,);
	fbClearGrp(bExecute:= FALSE,nGroupId:= ItpGetGroupId(sNciToPlc:=in_stItpToPlc),tTimeOut:= T#200MS);
	fbItpResetEx2(bExecute:=FALSE,tTimeOut:=,sNciToPlc:=in_stItpToPlc ,);
	fbMC_ResetX(Axis:=X_AXIS , Execute:=FALSE, );
    fbMC_ResetX2(Axis:=X_AXIS , Execute:=FALSE , );
    fbMC_ResetY(Axis:=X_AXIS , Execute:=FALSE , );
	fbTimer(IN:=FALSE , PT:=T#200MS , Q=> , ET=> );
	nState:= 513;
 513:
    bErr	:= FALSE;
	nErrId	:= 0;
	nLastState	:= 0;
	bBusy := FALSE; 
	nState := 0;
   	  
END_CASE



 

Share this post


Link to post
Share on other sites

Thanks a lot.... 
Mc_GearIn works for NCI as you said, 
After NCI completed cancel mc_gearin and re open again. then you can move it in any ways. in jogging, move_abs, anything.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now