# Trouble getting a variable robtarget program to function (variable robtarget module)

**URL:** <https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947>\
**Category:** RobotStudio\
**Created:** [December 1, 2022, 5:32pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947 "2022-12-01T17:32:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkadiKyaa](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/skadikyaa/32/798_2.png) [@SkadiKyaa](https://tech-community.robotics.abb.com/u/SkadiKyaa)\
**Post date:** [December 1, 2022, 5:32pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/1 "2022-12-01T17:32:06Z")

</div>

Hi there,

I’m fairly new to RAPID/RobotStudio and only have some fairly decent programming experience in Python.

I currently have a Python script that writes a RAPID module bases on user input that contains basically robtargets of work locations.  
The amount of robtargets can change with every new product. One time it’s 5 work locations, other time it’s over a 100.  
Example code of the robtarget module looks like this:

_MODULE data\_module_

_CONST robtarget WL\_1 := [[1750,2750,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];_  
_CONST robtarget WL\_2 := [[1750,3250,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];_  
_CONST robtarget WL\_3 := [[2250,3250,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];_  
_CONST robtarget WL\_4 := [[2250,2750,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];_  
_CONST robtarget WL\_5 := [[2500,2500,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];_

_CONST num **amount** := 5;_  
_CONST string **robtargetnames** {5} := [“WL\_1”,“WL\_2”,“WL\_3”,“WL\_4”,“WL\_5”];_

_ENDMODULE_

This Python written module is supposed to be loaded in the controller in addition with the robot’s main modules that work on the provided robtargets.  
However I’m having trouble realising this.

I’ve tried doing it like in an array way:

_PROC Path\_10()_  
_VAR robtarget current\_robtarget;_

_FOR i FROM 1 TO **amount** DO_  
_GetDataVal **robtargetnames** {i},current\_robtarget;_  
_MoveJ current\_robtarget,v1000,z100,MyTool\WObj:=wobj1;_  
_ENDFOR_  
_ENDPROC_

Also tried it with Offsets (with a script written module containing CONST of robtarget, x, y ~~and z values~~ ):

##Example of segments in data\_module:  
_CONST num x\_coor\_1:=100_  
_CONST num y\_coor\_1:=300_

```auto
*CONST num amount := 5;*
*CONST string x_coor_list{5}:=**["x_coor_1","x_coor_2",* ~~~~~ ETC.
~~~~ ETC.
##

*PROC Path_10()*
*CONST robtarget home:=**[[1000,0,100.00], [0, 0, 0, 0], [0, 0, 0, 0], [9E9, 9E9, 9E9, 9E9, 9E9, 9E9] ];*
*VAR robtarget current_robtarget;*
*VAR num x_value;*
*VAR num y_value;*

_FOR i FROM 1 to **amount** DO_
xval:=x_coor_list{i};
yval:=y_coor_list{i};
current_robtarget:=Offs(home, xval, yval, 0);
MoveJ current_robtarget,*v1000,z100,MyTool\WObj:=wobj1;*
*ENDFOR*
*ENDPROC*

Non really has run smooth and I can't really find clear examples of working with variable robtargets.

A lot of attempts in RobotStudio end up in constant errors like:
*Check the controller status*
*Execution Error*
*Argument Error*
*and more...*

Other times it tries to straight up move to the world coordinate 0,0,0 (robotarms base).

I can't really find likewise problems except a handfull of array and offset based questions/example videos but they all work with pre-existing robtargets.

The only "functionable" solution I know of is writing all the instructions with their unique work locations as a script in Python and uploading that to a controller, but I'm trying to have all the instructions pre-written in RAPID itself.

Any advise is appreciated!
```

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [December 1, 2022, 9:06pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/2 "2022-12-01T21:06:57Z")

</div>

Forget the GetDataVal.

```auto
FOR i FROM 1 to  **amount ** DO
  MoveJ **robtargetnames{i},** v1000,z100,MyTool\WObj:=wobj1
ENDFOR

```

Change the datatype for robtargetnames from string to robtarget and store the positions in the array.

---

<div class="post-metadata">

**Author:** ![SkadiKyaa](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/skadikyaa/32/798_2.png) [@SkadiKyaa](https://tech-community.robotics.abb.com/u/SkadiKyaa)\
**Post date:** [December 2, 2022, 11:30am UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/3 "2022-12-02T11:30:03Z")

</div>

> [@lemster68](#):
>
> Forget the GetDataVal.
> 
> ```auto
> FOR i FROM 1 to  **amount ** DO
> MoveJ **robtargetnames{i},** v1000,z100,MyTool\WObj:=wobj1
> ENDFOR
> 
> ```
> 
> Change the datatype for robtargetnames from string to robtarget and store the positions in the array.

I tried it like you said, but now I keep getting Type Error (101):  
_Type error(101): Type mismatch of expected type robtarget and found type robtarget{3}_

Here’s the short testing code I tried it with:

_CONST robtarget Target\_10:=[_[1750,2750,100.00]_,[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];_  
_CONST robtarget Target\_20:=[_[1550,2750,100.00]_,[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];_  
_CONST robtarget Target\_30:=[_[1750,2450,100.00]_,[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];_  
_CONST robtarget robtargetnames{3}:=[Target\_10,Target\_20,Target\_30];_  
_CONST num amount:=3;_

_PROC Path\_10()_  
_FOR i FROM 1 TO amount DO_  
_MoveJ robtargetnames{i},v1000,z100,MyTool\WObj:=wobj1;_  
_ENDFOR_  
_ENDPROC_

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [December 2, 2022, 12:59pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/4 "2022-12-02T12:59:43Z")

</div>

Move the actual data, the declarations with the values, into the array.

---

<div class="post-metadata">

**Author:** ![SkadiKyaa](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/skadikyaa/32/798_2.png) [@SkadiKyaa](https://tech-community.robotics.abb.com/u/SkadiKyaa)\
**Post date:** [December 2, 2022, 1:45pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/5 "2022-12-02T13:45:35Z")

</div>

> [@lemster68](#):
>
> Move the actual data, the declarations with the values, into the array.

I’m sorry but I don’t fully understand how it should look like in RAPID-language, do you mean like this:

_CONST robtarget robtargetnames{3}:=[_  
_[[2222,0,0],[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]],_  
_[[2222,0,150],[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]],_  
_[[2222,0,260],[0,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]_  
_];_

I just keep getting Type Error 101. Tried multiple ways of writing it each giving a check error of “wrong number of record components”.  
I guess I’m probably writing the array wrong in the RAPID language but I just can’t seem to find a clear example of how one should look like in other forums or even in the RAPID manual.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [December 2, 2022, 3:36pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/6 "2022-12-02T15:36:00Z")

</div>

Yes, you are on the right track. Here is one I made in RS:

CONST robtarget myRobtargets{3}:=[[[100,200,300],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]],[[100,200,300],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]],[[100,200,300],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]]];  
Wrong number of components means you said three but it does not see three. Could be a misplaced comma, wrong braces.

---

<div class="post-metadata">

**Author:** ![Newman](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/newman/32/2900_2.png) [@Newman](https://tech-community.robotics.abb.com/u/Newman)\
**Post date:** [December 3, 2022, 4:05pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/7 "2022-12-03T16:05:10Z")

</div>

As far as I know rotation data must be normalized, sum must be=1. [1,0,0,0] as in Lemster example is ok, 0.0.0.0 is not ok.

---

<div class="post-metadata">

**Author:** ![SkadiKyaa](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/skadikyaa/32/798_2.png) [@SkadiKyaa](https://tech-community.robotics.abb.com/u/SkadiKyaa)\
**Post date:** [December 5, 2022, 3:02pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/8 "2022-12-05T15:02:48Z")

</div>

Filling in the rotation data makes the simulation “work”, but I have to write down the correct (possible) values otherwise the arm just ends up in an unable to move state. I feel like this method isn’t really the way to go.

I could also only run the Path inside the RAPID tab and not the simulation/home tab. Using the Move Along Path function in the simulation tab results in errors, but set pointer to path routine in the RAPID tab and selecting Start does work. weird?

I think I’m going to try it with var robtarget offsets and with ConfJ\off function and just use the CONST num X,Y,Z values instead of making a robtarget out of them.

Trying to create robtargets in a script that tries to guess what rotation data to write sounds like a sure-fire way to end up in a lot of problems…

Unless there is a way to copy certain robtarget data from one to another.

---

<div class="post-metadata">

**Author:** ![DenisFR](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@DenisFR](https://tech-community.robotics.abb.com/u/DenisFR)\
**Post date:** [December 7, 2022, 1:11pm UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/9 "2022-12-07T13:11:24Z")

</div>

Hello,  
I’ve made a soft to help in orient data:  
[https://github.com/DenisFR/ABB\_RAPID\_Prog\_Helper](https://github.com/DenisFR/ABB_RAPID_Prog_Helper)  
You can have a look in this [module](https://github.com/DenisFR/ABB_RAPID_Prog_Helper/blob/main/ABB_RAPID_Prog_Helper/modAngles.vb) to know hows to transform Euler to Quaternions.

---

<div class="post-metadata">

**Author:** ![SkadiKyaa](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/skadikyaa/32/798_2.png) [@SkadiKyaa](https://tech-community.robotics.abb.com/u/SkadiKyaa)\
**Post date:** [December 15, 2022, 10:21am UTC](https://tech-community.robotics.abb.com/t/trouble-getting-a-variable-robtarget-program-to-function-variable-robtarget-module/10947/10 "2022-12-15T10:21:02Z")

</div>

Just a short update here:

Instead of using Python written robtargets, I’m more succesful with a Python written array containing the XYZ values and using those with offsets for replacing pre-existing VAR robtargets.

Doing this is have to turn off ConfJ and ConfL as so the robot can move to those points without saying “Argument Error” with every single mm it moves. This hasn’t resulted in trouble yet (but I’m warry of possible problems that might occure).

Short segment of how the working code looks like:

_EntryPointvar:=Offs(TCP\_000,Xvaluetarget,Yvaluetarget,Zvaluetarget);_  
_HoverPointvar:=Offs(EntryPointvar,0,0,HoverHeight);_  
_EndPointvar:=Offs(EntryPointvar,0,0,DrillDepth);_

_ConfJ\Off;_  
_ConfL\Off;_  
_MoveJ HoverPointvar,vmax,fine,Tdrill\WObj:=Object1;_  
_WaitTime 0.5;_  
_MoveL EntryPointvar,v800,fine,Tdrill\WObj:=Object1;_  
_WaitTime 0.5;_  
_MoveL EndPointvar,v100,fine,Tdrill\WObj:=Object1;_  
_WaitTime 0.5;_  
_MoveL HoverPointvar,v500,fine,Tdrill\WObj:=Object1;_  
_WaitTime 0.5;_  
_ConfJ\On;_  
_ConfL\On;_

Thank you Lemster, Newman and Denis for the replies! If I later need to do stuff with rotations and quaternions I’ll known what to look out for.
