# Calculated offset?

**URL:** <https://tech-community.robotics.abb.com/t/calculated-offset/7334>\
**Category:** RobotStudio\
**Created:** [August 31, 2016, 4:08am UTC](https://tech-community.robotics.abb.com/t/calculated-offset/7334 "2016-08-31T04:08:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColoradoPacific](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/coloradopacific/32/2870_2.png) [@ColoradoPacific](https://tech-community.robotics.abb.com/u/ColoradoPacific)\
**Post date:** [August 31, 2016, 4:08am UTC](https://tech-community.robotics.abb.com/t/calculated-offset/7334/1 "2016-08-31T04:08:56Z")

</div>

I’m attempting to use an incremented counter in a part laydown routine to calculate/modify an offset as I stack parts into a hopper. I need to the laydown position to shift 15mm in the +Z direction after each part, but I don’t want to use dozens of robtargets to do it. One robtarget and a calculated offset based on a counter seems much cleaner, I just can’t figure out how to do it.  
Is there a way to use the counter to modify or select the offset I want?

---

<div class="post-metadata">

**Author:** ![John\_Verheij](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/john_verheij/32/1724_2.png) [@John\_Verheij](https://tech-community.robotics.abb.com/u/John_Verheij)\
**Post date:** [August 31, 2016, 6:53am UTC](https://tech-community.robotics.abb.com/t/calculated-offset/7334/2 "2016-08-31T06:53:21Z")

</div>

You can just use a _FOR_ or _WHILE_ loop and every iteration increment the offset. With the function _Offs_ you can modify the position.

So you can do something like this:

```auto

PERS num noParts := 5;

PERS num offset := 15;

PERS robtarget pFirst := [[1000,0,400],[0,1,0,0],[0,0,0,0],[9e9,9e9,9e9,9e9,9e9,9e9]];

PROC main()

  VAR num totalOffset := 0;

  FOR i FROM 1 TO noParts DO

    MoveJ Offs(pFirst,0,0,totalOffset), v1000, fine, tool0;

    totalOffset := totalOffset + offset;

  ENDFOR

ENDPROC

```

---

<div class="post-metadata">

**Author:** ![ColoradoPacific](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/coloradopacific/32/2870_2.png) [@ColoradoPacific](https://tech-community.robotics.abb.com/u/ColoradoPacific)\
**Post date:** [August 31, 2016, 7:18pm UTC](https://tech-community.robotics.abb.com/t/calculated-offset/7334/3 "2016-08-31T19:18:34Z")

</div>

That’s quite a bit cleaner than what I ended up doing. Might have to go back and modify…

Incr HopperCount;  
MoveAbsJ jposHOME,v1000,z50,tGripper;  
TEST HopperCount  
CASE 1:  
p1000Ct\_PlacePos.trans.z := + 15;  
p1000Ct\_PlaceDepart.trans.z := + 15;  
CASE 2:  
p1000Ct\_PlacePos.trans.z := + 30;  
p1000Ct\_PlaceDepart.trans.z := + 30;  
CASE 3:  
p1000Ct\_PlacePos.trans.z := + 45;  
p1000Ct\_PlaceDepart.trans.z := + 45;  
etc, etc…

Then reset the Z values at completion of the routine.
