RobotStudio event

Common variable between tasks

Hi all,
I've noticed a strange behaviour in my RAPID program: I have 2 parallel normal tasks (at the same level, no backgroung task) that share a robtarget variable. The variable is defined in this way:

TASK 1
 
PERS robtarget setPick := [[535.384,110.907,-22.9616],[0,0.7196,0.694388,0],[0,-1,0,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];
...
PROC main()
....
ENDPROC

TASK2
PERS robtarget SetPick;

PROC main()
....
ENDPROC

I've read that to share a variable in both tasks you have to initialize it in the main one and to just declare it in the others (like I did); but actually in Task 2 I see it at 0. I've solved the problem defining another variable (pickpos) without initializing it in both tasks and passing the value of setPick to the new variable:

TASK 1

PERS robtarget pickpos;
    PERS robtarget setPick := [[535.384,110.907,-22.9616],[0,0.7196,0.694388,0],[0,-1,0,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

PROC main()
....
pickpos := setPick;
....
ENDPROC

TASK 2

PERS robtarget pickpos;

PROC main()
...
ENDPROC

So my question is: why is it working like this? Shouldn't it work with the first solution?

Thank you!

Comments

  • lemster68
    lemster68 ✭✭✭
    I have never heard of two tasks "at the same level".  I would expect that one must be background, with the other in foreground.  Maybe that is why it is not "sharing"?
    Lee Justice
  • Probably it's because of that. So if I want to run 2 tasks in a real parallelism how can I do? If I put one in background then it would be executed just when the other is idle, or not?
  • lemster68
    lemster68 ✭✭✭
    You create the background task, leave it normal for debugging.  If appropriate , after debugging, make it static or semistatic and it will always be running.
    Lee Justice
  • So the fact that the task in background is static or semistatic makes it to run in parallel with the main one (in a round robin way)?
    I've found this manual online where priorities are explained; here it looks like the way in which tasks are executed depends only on the priority and not on the kind of task.


  • lemster68
    lemster68 ✭✭✭
    The static and semistatic will continue to run at all times, even while e stopped.  The difference, as best as I recall, is that when restarting the controller, the semistatic will start back at the top of its main, while the other will resume from where it was.  
    Lee Justice
  • Yes, you are right. But I'm not sure that if I put the second task as semistatic and in background with respect to the main one it will be executed in parallel for real or it will be executed in parallel only when the main task is idle (like when it's executing some motion or waiting for some signal); I need them to be executing all the time "concurrently" because the second task updates the current position value.
  • lemster68
    lemster68 ✭✭✭
    Is that robtarget data?  Or is it sending out the robot's current positional data?  One thing you might consider is to leave it a normal task so that it would start and stop with the main task.
    Lee Justice
  • Yes, it's a robtarget, I'm using CrobT function. I can't set it as normal because it updates the position and checks also if the robot is in a "dangerous" position, so I need this to be checked even if the main task is stopped; but anyway, I think that even if I put it as normal it would be the same. I've solved the problem doing as written in the post, I was just curious to understand why it was working with my solution but not with the first one that should actually be correct  :confused:
  • I have just done a program that works as per your first solution (though the variables are not robtargets).
    The variables are changed in one task and they update in the other.

    How did you check the variable in Task2?
  • I found it wasn't working in task 2 because in that task I check if the current position of the robot is too close to "setPick", so I check this condition: 
    CurrentPos.trans.z - setPick.trans.z < threshold 
    And I saw that with my first solution setPick.trans.z was = 0 and that's not correct. Indeed I initialize it in task 1 as:

    PERS robtarget setPick := [[535.384,110.907,-22.9616],[0,0.7196,0.694388,0],[0,-1,0,1],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]];

    and I don't update it, it's a fixed robtarget.
    Then actually setPick.trans.z should be = -22.9616 but it's not.
  • If SetPick is not changing you only need to declare it in Task2?
  • I need it in task 1 too; typically it's a fixed position where the robot should go and it can be updated after a request from the operator (I'm sure that when I was having the problem "setPick" hasn't been updated). So I need it in both tasks because it is used in both and can be changed.