Hi Michal,
In this case you should right some Rapid code to avoid the rotating of the gripper in the wrong direction but when doing this you will loose some cycle time.
I have used this simple code:
I check the angle Z of the item and according to the angle I force the axis 4 to rotate in the direction I want.
PROC Pick(num Index)
VAR num nAngleZ;
VAR num nRotZ1;
VAR num nRotZ2;
VAR num nRotZ3;
nRotZ1:=0;
nRotZ2:=0;
nRotZ3:=0;
nAngleZ:=EulerZYX(,PickTarget.RobTgt.rot);
IF nAngleZ>-135 and nAngleZ<-45 THEN
!nothing todo
ELSE
nRotZ1:=-130;
nRotZ2:=-70;
nRotZ3:=-180;
ENDIF
TriggLConc,RelTool(PickTarget.RobTgt,0,0,-ItmSrcData{Index}.OffsZRz:=nRotZ1),MaxSpeed,ItmSrcData{Index}.VacuumAct1,z5,tGripWObj:=WObjPick;
MoveLConc,PickTarget.RobTgt,LowSpeed,z1Inpos:=ItmSrcData{Index}.TrackPoint,tGripWObj:=WObjPick;
GripLoad ItemLoad;
MoveL RelTool(PickTarget.RobTgt,0,0,-60Rz:=nRotZ2),LowSpeed,z1,tGripWObj:=WObjPick;
TriggL RelTool(PickTarget.RobTgt,0,0,-ItmSrcData{Index}.OffsZRz:=nRotZ3),LowSpeed,ItmSrcData{Index}.AckT2:=PickDone,z5,tGripWObj:=WObjPick;
ENDPROC
Do not forget to add some code in the GotoRestartPos routine :
PROC GotoRestartPos()
VAR num nJointPosRotZ;
VAR speeddata vSpeed1:=[300,200,1000,1000];
VAR robtarget TempPos1;
WaitTime 0.2;
TempPos1:=CRobT(Tool:=tGripWObj:=Wobj0);
TempPos1.trans.z:=SafePos.trans.z;
MoveL TempPos1,vSpeed1,fine,tGripWObj:=wobj0;
WaitTime 0.2;
JointPos2:= CJointT();
JointPos2.robax.rax_4:=0;
MoveAbsJ JointPos2,vSpeed1,fine,tGripWObj:=wobj0;
tGrip:=tGrip3;
FOR i FROM 1 TO MaxNoSources DO
IF (ItmSrcData{i}.Used) THEN
TriggL SafePos,VeryLowSpeed,ItmSrcData{i}.Nack,fine,tGripWObj:=wobj0;
ENDIF
ENDFOR
InitIO;
MoveL MaintPos,LowSpeed,fine,tGripWObj:=wobj0;
ENDPROC
Succes,
BR
Fabrice