# Changing TCP in urscript to TCP already created in the system

**URL:** https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194
**Category:** URScript
**Created:** [October 3, 2022, 11:11am UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194 "2022-10-03T11:11:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anon90109984](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@anon90109984](https://forum.universal-robots.com/u/anon90109984)
#### Post date: [October 3, 2022, 11:11am UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/1 "2022-10-03T11:11:19Z")

</div>

Usually in other robot environments its possible to get the Tool pose by reference from within their system. To my knowledge this isn’t possible with urscript?  
I have tried to manually define the TCP pose as a variable but when given the same name as it is specified in the TCP it says that a variable of that name already exists…, but if it says there is a variable with that name why can’t I access it within the urscript?

---

<div class="post-metadata">

### Author: ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)
#### Post date: [October 3, 2022, 2:10pm UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/2 "2022-10-03T14:10:05Z")

</div>

filipe.jorge,  
I’m not quite sure what your asking exactly!

You can easily get the TCP pose by using the get\_tcp\_actual\_pose() scrip you can assign it to a variable by writing  
Variable\_name = get\_tcp\_actual\_pose()

this will give you the position of the TCP relative to the Base of your Robot.

do you have a copy of the UR Script manual?  
[https://www.universal-robots.com/download/manuals-e-series/script/script-manual-e-series-sw-511/](https://www.universal-robots.com/download/manuals-e-series/script/script-manual-e-series-sw-511/)

---

<div class="post-metadata">

### Author: ![anon90109984](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@anon90109984](https://forum.universal-robots.com/u/anon90109984)
#### Post date: [October 3, 2022, 2:56pm UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/3 "2022-10-03T14:56:15Z")

</div>

That would require for the TCP to be set before running the script.

Imagine this, you create multiple TCP’s using the console (using the UR measure tools for example), but the only way I find to change tool in urscript is to copy the values from the TCP into a variable manually, and then set\_tcp(variable). For example in Kuka I would change the tool in code with “$TOOL = TOOL\_DATA[7”], in Yaskawa “///TOOL 7”, etc…

Since a name is assigned to the TCP, and this name cannot be reused as a global variable, why can’t I access it in urscript, or why can’t I access the specific TCP with an ID\_Number…

Edit: Also I forgot to specify that I do have a copy of the urscript manual.

---

<div class="post-metadata">

### Author: ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)
#### Post date: [October 4, 2022, 8:36am UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/4 "2022-10-04T08:36:26Z")

</div>

filipe.jorge,  
Yes I understand your problem  
the UR does lack some of the capabilities you would find in most industrial robot controllers.  
Make a request for what you want on the wish list and UR might consider adding it to future software releases.

You can set a TCP in the the program with the SET node (set no action and then set the TCP you want)  
however I suspect you want to set the TCP based on certain conditions.

I have a crude solution.

You could create a Matrix of positions  
TCP\_List = [p[0,0,0,0,0,0,],p[0,0,0,0,0,0,],p[0,0,0,0,0,0,]] as many tools as required.  
then set the TCP (as described above)  
then write the TCP value to the List  
TCP\_List[i] = get\_tcp\_offset  
repeat until your list is full  
then when you want to call the required TCP  
write set\_tcp = TCP\_List[\*]

hope this helps

---

<div class="post-metadata">

### Author: ![anon90109984](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@anon90109984](https://forum.universal-robots.com/u/anon90109984)
#### Post date: [October 4, 2022, 1:31pm UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/5 "2022-10-04T13:31:24Z")

</div>

That is kinda what I have been doing, except more manually beacuse I just copy paste the values that calibrating the tool gave me and manually code them into the urscript.  
Thank you for the tip, I was just hoping something like that would exist in their environment to make my life easier.

---

<div class="post-metadata">

### Author: ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)
#### Post date: [October 4, 2022, 1:59pm UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/6 "2022-10-04T13:59:10Z")

</div>

Glad I could help  
I would imagine something like this could be easily done in a URCap but I have no experience in writing one

---

<div class="post-metadata">

### Author: ![m.hammerton](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@m.hammerton](https://forum.universal-robots.com/u/m.hammerton)
#### Post date: [March 1, 2023, 11:59am UTC](https://forum.universal-robots.com/t/changing-tcp-in-urscript-to-tcp-already-created-in-the-system/24194/7 "2023-03-01T11:59:15Z")

</div>

filipe.jorge,  
I know it’s been a while since I last commented on this so if you have a solution that’s great.

but it just so happens I came upon the issue for myself when needing to dynamically adjust my TCP.

this is the solution I came up with to create a variable with TCP Data.  
I firstly created a Flange TCP with X=0, Y=0, Z=0, Rx=0, Ry=0, Rz=0 in the installation tab TCP  
then Created my Tools TCP with the TCP Wizard.

then in my program wrote the following (as a test program)

Program  
Variables Setup  
Robot Program  
MoveJ  
Waypoint\_3  
Get TCP Value  
‘Set TCP To Flange TCP’  
Set  
toolvar1≔Tool\_const  
‘Set TCP To Tool TCP’  
Set  
toolvar2≔Tool\_const  
‘Calculate TCP Values’  
Tool\_TCP≔pose\_inv(pose\_sub(toolvar1, toolvar2))  
MoveJ  
Waypoint\_1  
Wait: 1.0  
‘Move to Pos with Tool TCP’  
Wait: 1.0  
MoveL  
Waypoint\_2  
TCP Offset Input  
‘enter TCP offset values’  
X\_shift≔’X Distance to offset TCP’  
Y\_shift≔’Y Distance to offset TCP’  
Z\_shift≔’Z Distance to offset TCP’  
Tool\_TCP[0]=Tool\_TCP[0]+(X\_shift/1000)  
Tool\_TCP[1]=Tool\_TCP[1]+(Y\_shift/1000)  
Tool\_TCP[2]=Tool\_TCP[2]+(Z\_shift/1000)  
‘Set TCP with offset values’  
set\_tcp(Tool\_TCP)  
‘Move to Pos with Active TCP’  
MoveL  
Waypoint\_2  
Wait: 3.0

You could loop this section to populate a TCP\_List instead of having to type it in manually every time you adjust or add a TCP in the installation tab  
Set  
toolvar2≔Tool\_const  
‘Calculate TCP Values’  
Tool\_TCP≔pose\_inv(pose\_sub(toolvar1, toolvar2))
