RelTool problem

Hi,
I'm having some problems with RelTool command. I'm making a program with IRB120 where I try to pick products from tray and then place them into a pallet using data I get from camera. Products need to placed into pallet with specific angle and they are randomly placed on the tray where they are picked. I'm using Offs command to do every other movement where info from camera is needed because that way I can use workobject that has same coordinate system as the camera does but I still need to use reltool at one point to fix the angle. The problem is that reltool moves the robot in all directions even though it is only given permission to rotate around z-axis. The point where it tries to reach with reltool command seem to be pretty random but it's always close to robots base. So why is it working like that? Here is a small sample of the code:
!First it moves to the products location and then picks it up
MoveL Offs(pKamera,nXOffset,nYOffset,60), v200, fine, tVacuum\WObj:=wobjPoiminta;
MoveL Offs(pKamera,nXOffset,nYOffset,7), v200, fine, tVacuum\WObj:=wobjPoiminta;
SetDO do2Vacuum, 1;
WaitTime 1;
MoveL Offs(pKamera,nXOffset,nYOffset,60), v200, fine, tVacuum\WObj:=wobjPoiminta;
MoveL Offs(pKamera,nXOffset,nYOffset,7), v200, fine, tVacuum\WObj:=wobjPoiminta;
SetDO do2Vacuum, 1;
WaitTime 1;
MoveL Offs(pKamera,nXOffset,nYOffset,60), v200, fine, tVacuum\WObj:=wobjPoiminta;
!Robot moves above static pallet to the right position
MoveJ [[288.61,407.86,89.08],[0.019167,-0.999374,-0.0296428,0.00217687],[0,-1,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tVacuum\WObj:=wobjPoiminta;
!Here I try to correct the angle before placing the product into pallet but it all goes wrong right here
MoveL RelTool (pKamera, 0, 0, 0 \Rz:= nAngle2), v100, fine, tVacuum;
pKulma := CRobT(\Tool:=tVacuum \WObj:=wobjPoiminta);
MoveL Offs(pKulma,0,0,-20), v100, z0, tVacuum\WObj:=wobjPoiminta;
SetDO do2Vacuum, 0;
WaitTime 1;
MoveL Offs(pKulma,0,0,20), v100, z0, tVacuum\WObj:=wobjPoiminta;
pKulma := CRobT(\Tool:=tVacuum \WObj:=wobjPoiminta);
MoveL Offs(pKulma,0,0,-20), v100, z0, tVacuum\WObj:=wobjPoiminta;
SetDO do2Vacuum, 0;
WaitTime 1;
MoveL Offs(pKulma,0,0,20), v100, z0, tVacuum\WObj:=wobjPoiminta;
Comments
Where is your tVacuum tool's TCP? If it is off to one side of the tool the tool will rotate in a strange way.
I don't think so because reltool works in tool coordinate system. Atleast in rapid manual the example code doesn't have reference to any wobj.
Also as jmf says you need to have the move relative to the same work object as the other moves using pKamera or that will also introduce an offset by the difference between wobj0 (base of robot) and your workobject wobjPoiminta.
The reltool offsets and rotations are relative to the tool but the robtarget's starting position (before adding the offset) will be relative to the workobject used in the move command.
MoveJ [[288.61,407.86,89.08],[0.019167,-0.999374,-0.0296428,0.00217687],[0,-1,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]], v100, fine, tVacuum\WObj:=wobjPoiminta;
pKulma := CRobT(\Tool:=tVacuum \WObj:=wobjPoiminta);
MoveL RelTool (pKulma, 0, 0, 0 \Rz:= nAngle2), v100, fine, tVacuum;
pAseta := CRobT(\Tool:=tVacuum \WObj:=wobjPoiminta);
MoveL Offs(pAseta,0,0,-20), v100, z0, tVacuum\WObj:=wobjPoiminta;
SetDO do2Vacuum, 0;
WaitTime 1;