Global values

Typically: "How do I... ", "How can I... " questions
Post Reply
Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Global values

Post by Ruediger » 06 Aug 2013, 13:42

Hello,
is the a way to define some setup parameters (Lua variables) used by different Lua skripts in one scene?

Thanks
Ruediger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: Global values

Post by coppelia » 06 Aug 2013, 14:27

Hi Ruediger,

Yes, you have several possibilities, have a look at this page describing the means of communication in and around V-REP. In particular, have a look at signals.

Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Re: Global values

Post by Ruediger » 07 Aug 2013, 07:43

Thank you, but I have already read the communication page and I use already signals in my application.
Let me try to explain my question more in detail.

My scene has two seperate X/Y stages. Both are controlled with seperate threads and the communication is done with signals.

The X/Y stages inspect the same object by X/Y step moving over the object. In real life there are different step moving cycles possible. This cycles are defined by
X/Y step count and
X/Y step offset

My idea was to define this values only in one text file (simple to change) and use it in both threads.
Yes, I can use signals to distribute this values, but is this the "right way"?
Can I set and read the signal in the initialisation part of the threads?

Thanks
Rüdiger

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: Global values

Post by coppelia » 07 Aug 2013, 19:03

Hello Rüdiger,

Not completely sure if I understood... but:
  • You could read the same configuration file from the 2 threads.
  • You can also set and read a signal in the initialization phase of the threads (but in that case, since one thread is executed before the other, you might not be able to read the signal set by the other one in the initialization phase). You can give a priority value to a child script in the script dialog via the Execution order item.
But using tubes, things could be easier since you could use one tube to communicate from script1 to script2, and another tube to communicate from script2 to script1. And as long as a value is not available on one end of the tube, the script could just wait.

Ok, finally, re-reading your initial post, I think I understood what you meant to do ;) So, yes, you have several possibilities, here just a few:
  • each script could read the same configuration file (i.e. as described here above). Have a look at this post for instance.
  • you could have a special non-threaded child script that would only be in charge of setting-up global variables (i.e. signals). Make sure to flag that child script as Execution order: first (see above's comment). If you have a lot of values to set-up, pack them (e.g. via simPackFloats) into a string signal that the 2 threads can read.
Cheers

Post Reply