# Reading variables while the robot is moving for implementing a loop

**URL:** <https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193>\
**Category:** URScript\
**Created:** [August 10, 2022, 9:20am UTC](https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193 "2022-08-10T09:20:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon27952328](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@anon27952328](https://forum.universal-robots.com/u/anon27952328)\
**Post date:** [August 10, 2022, 9:20am UTC](https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193/1 "2022-08-10T09:20:06Z")

</div>

Hello everyone,  
I’m trying to read the z position and the force in the z direction of the robot to use them in a loop. I didn’t find anything about that online.  
The objective is to push an object with a gripper downward until it reaches a certain height. The force should not exceed 30N. If the force is more than 30N the robot has to open the gripper, move upward, rotate the gripper at 90° and then try again.

I declared 2 variables, one is the third element of the list get\_actual\_tcp-pose and the other is the third element of the list get\_tcp\_force. Then I have a loop using the first variable with the condition : while variable 1\>my final height. I move downward with another condition which is the force should not exceed -30N. The problem is, the variables are not changing while the robot is moving. And the loops never stops.

Can you help please ? Thank you in advance

---

<div class="post-metadata">

**Author:** ![tyshkevichpavel](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@tyshkevichpavel](https://forum.universal-robots.com/u/tyshkevichpavel)\
**Post date:** [August 10, 2022, 11:03am UTC](https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193/2 "2022-08-10T11:03:23Z")

</div>

For example:  
[https://www.universal-robots.com/articles/ur/programming/seek-using-force/](https://www.universal-robots.com/articles/ur/programming/seek-using-force/)  
or  
[https://www.universal-robots.com/articles/ur/programming/urscript-dynamic-force-control/](https://www.universal-robots.com/articles/ur/programming/urscript-dynamic-force-control/)

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [August 10, 2022, 12:11pm UTC](https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193/3 "2022-08-10T12:11:50Z")

</div>

There’s multiple ways to implement this. Can you show us a snippet of your code so we can better help you? Typically when I want to use the value of force() or of a specific TCP coordinate, I put a Thread at the bottom and just assign a variable like myForce = force(). That way the thread is constantly updating these values for use in my program elsewhere. If you go this route, just be sure to include a Script node and type “sync()” as the last instruction.

---

<div class="post-metadata">

**Author:** ![anon27952328](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@anon27952328](https://forum.universal-robots.com/u/anon27952328)\
**Post date:** [August 11, 2022, 9:02am UTC](https://forum.universal-robots.com/t/reading-variables-while-the-robot-is-moving-for-implementing-a-loop/23193/4 "2022-08-11T09:02:23Z")

</div>

Thank you very much, both of you, I succeeded
