Discussion

Left ArrowBack to discussions page
cwwstccwwstc Posts: 4 Apprentice

Hello,

I have a question about generate new variables automatically with UR5 robot while performing a path recording task.

Assume I have a starting position variable Var_start, and a variable get current position Var_now. From waypoint 1 to waypoint 2, I need to record the trajectory for each displacement of 0.1 m, and store the position in new variables starting from Var_1, Var2,...etc. However, I do not know the exact number of new variables needed to perform this task. Therefore, I am asking if there is a way the script can generate new variables with different names automatically?

The pseudo code is as following:

i = 1

Var_start = waypoint 1

While True:

    Var_now = get_actual_tcp_pose()

    if point_dist( Var_start,Var_now) > 0.1 then

        (Var_) + i = Var_now

        Var_start = Var_now

    end if

Loop


Comments: I have few thoughts about achieving this, such as:

1) update new name of variables as in pseudo code.

Problem: UR script cannot combine string and integer together, which is able to be done in Python 3.0 but not here. And new name string cannot be accessed as new name of variable directly.


2) Create a long array of position variables and then use them in sequence.

Problem: position value itself is already an array of 6. I have not tried, but I do think I can create 2-D array for achieving this since UR script defines strickly on the format of its variables.


Thus, please let me know if there is a way or an alternative way can achieve to generate unknown number of new variables in a UR program.


Thank you very much in advance.


Regards,

Denis


Best Answer

  • matthewd92matthewd92 Posts: 699 Handy
    Accepted Answer
    You can store a list of poses, just not a list of lists.  You could predefine your list, but you would need to fill it with poses when it is created to have it be of the correct type and length.  You could then just index through the list.  Also, if you defined your initial pose as something unique, you could iterate until you reach the first un-altered pose, then you are done.  I know we create lists that have I think up to 254 elements in them with an RPC call that we have created, we do this for being able to quickly generate the list and fill it how we want.

Comments

  • cwwstccwwstc Posts: 4 Apprentice

    I am not sure if I understand this correctly. I created a list as following:

    pose_all = [p[0,0,0,0,0,0], p[0,0,0,0,0,0],p[0,0,0,0,0,0],p[0,0,0,0,0,0],]

    Assuming that I may need only 4 points, and the max points I can create is 254 elements.

    Then I can re-register their value by (pose_all [i] ; i = i +1) loop.

    Just need to confirm if this is what you meant exactly.

    Thank you very much. This logic seems already solved my problem.

    Regards.

  • matthewd92matthewd92 Posts: 699Founding Pro, Tactile Sensor Beta Testers Handy
    Yes, that is exactly what I meant.  I have never tried creating large lists of poses but I know a regular list can hold somewhere around 254 elements before there are issues.  If you get this working please let the community know so that we can see how you solved that problem.
  • cwwstccwwstc Posts: 4 Apprentice
    Yes, that is exactly what I meant.  I have never tried creating large lists of poses but I know a regular list can hold somewhere around 254 elements before there are issues.  If you get this working please let the community know so that we can see how you solved that problem.


    Thank you so much! The test will be conducted next week. I will upload the result and follow ups of this program.

  • cwwstccwwstc Posts: 4 Apprentice
    Sorry, the developpment is stopped  immediately from now. The mentioned method and test will be conducted in un-defined future. When there will be any update, I will let you know if the method works.
Sign In or Register to comment.
Left ArrowBack to discussions page