# Script "MoveRelativBase"

**URL:** <https://forum.universal-robots.com/t/script-moverelativbase/25544>\
**Category:** Technical Questions\
**Created:** [December 8, 2022, 12:42pm UTC](https://forum.universal-robots.com/t/script-moverelativbase/25544 "2022-12-08T12:42:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![franz.mertens](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@franz.mertens](https://forum.universal-robots.com/u/franz.mertens)\
**Post date:** [December 8, 2022, 12:42pm UTC](https://forum.universal-robots.com/t/script-moverelativbase/25544/1 "2022-12-08T12:42:00Z")

</div>

Hallo,  
I have written a script to move the Robot relativ to the Base feature (see below).  
But it works only with offsetz in X,Y,Z. If I want to move relativ in Rx,Ry,Rz the movement  
isn`t what I expect.  
What is wrong in my script?

# define function

def MovelRelativBase(cpRelativ=p[0,0,0,0,0,0],OffsetX=0,OffsetY=0,OffsetZ=0,OffsetRx=0,OffsetRy=0,OffsetRz=0,)

#################################1.0#################################  
#1.0 calculate offset  
cpRelativ[0]=cpRelativ[0]+(OffsetX/1000)  
cpRelativ[1]=cpRelativ[1]+(OffsetY/1000)  
cpRelativ[2]=cpRelativ[2]+(OffsetZ/1000)  
cpRelativ[3]=cpRelativ[3]+ d2r(OffsetRx)  
cpRelativ[4]=cpRelativ[4]+ d2r(OffsetRy)  
cpRelativ[5]=cpRelativ[5]+ d2r(OffsetRz)

#################################2.0#################################  
#3.0 Move to point  
movel(cpRelativ, a=1.2, v0.25, r=0.0)  
end

Regards

---

<div class="post-metadata">

**Author:** ![cg1](https://avatars.discourse-cdn.com/v4/letter/c/c77e96/32.png) [@cg1](https://forum.universal-robots.com/u/cg1)\
**Post date:** [December 9, 2022, 8:16am UTC](https://forum.universal-robots.com/t/script-moverelativbase/25544/2 "2022-12-09T08:16:47Z")

</div>

Hi Franz…  
The UR system uses something called “[Axis Angle](https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation)”, This means that the rotations is not really intuitive, (not that rotations in 3 dimensions really is anyway)…

I would suggest you try using the rpy2rotvec(rpy\_vector), which lets you use roll-picth-yaw values instead, which people tent to find more intuitive

The second thing is that you cannot simply add rotational offsets (one rason is because rotations in 3D are not commutative meaning a_b != b_a ) it might work in simple cases, but not necessarily always.  
Therefore the most commen thing is to use the script function pose\_trans ex: Pose\_offest = pose\_trans(base\_offset , pose) instead.  
or if you need it in the tool frame Pose\_offest = pose\_trans(pose , offset\_tool).

---

<div class="post-metadata">

**Author:** ![franz.mertens](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@franz.mertens](https://forum.universal-robots.com/u/franz.mertens)\
**Post date:** [December 15, 2022, 12:51pm UTC](https://forum.universal-robots.com/t/script-moverelativbase/25544/3 "2022-12-15T12:51:10Z")

</div>

> [@franz.mertens](#):
>
> def MovelRelativBase(cpRelativ=p[0,0,0,0,0,0],OffsetX=0,OffsetY=0,OffsetZ=0,OffsetRx=0,OffsetRy=0,OffsetRz=0,)
> 
> #################################1.0#################################  
> #1.0 calculate offset  
> cpRelativ[0]=cpRelativ[0]+(OffsetX/1000)  
> cpRelativ[1]=cpRelativ[1]+(OffsetY/1000)  
> cpRelativ[2]=cpRelativ[2]+(OffsetZ/1000)  
> cpRelativ[3]=cpRelativ[3]+ d2r(OffsetRx)  
> cpRelativ[4]=cpRelativ[4]+ d2r(OffsetRy)  
> cpRelativ[5]=cpRelativ[5]+ d2r(OffsetRz)
> 
> #################################2.0#################################  
> #3.0 Move to point  
> movel(cpRelativ, a=1.2, v0.25, r=0.0)  
> end

Hi I have test this script:  
But it dosesnt refers to the tool feature and not to the base feature:

###define function###  
def MovelRelativBase(cpRelativ=p[0,0,0,0,0,0],OffsetX=0,OffsetY=0,OffsetZ=0,OffsetRx=0,OffsetRy=0,OffsetRz=0,)

#################################1.0#################################  
#1.0 calculate offset  
cpRelativSave=cpRelativ

Rotation=[d2r(OffsetRx),d2r(OffsetRy),d2r(OffsetRz)]  
newRotation=rpy2rotvec(Rotation)

cpRelativ=pose\_trans(cpRelativSave, OffsetX/1000),OffsetY/1000),OffsetZ/1000),newRotation[0],newRotation[1],newRotation[2]])

#################################2.0#################################  
#3.0 Move to point  
movel(cpRelativ, a=1.2, v0.25, r=0.0)  
end

---

<div class="post-metadata">

**Author:** ![franz.mertens](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@franz.mertens](https://forum.universal-robots.com/u/franz.mertens)\
**Post date:** [December 15, 2022, 12:52pm UTC](https://forum.universal-robots.com/t/script-moverelativbase/25544/4 "2022-12-15T12:52:59Z")

</div>

Sorry but the offset calculation was wrong. Here the correct code:

cpRelativ=pose\_trans(cpRelativSave, p[(OffsetX/1000),(OffsetY/1000),(OffsetZ/1000),newRotation[0],newRotation[1],newRotation[2]])
