Multi clients in python remote api

Typically: "How do I... ", "How can I... " questions
KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Multi clients in python remote api

Post by KaiYang » 17 Mar 2018, 03:42

Hello,

I use v-rep edu 3.4 as the environment with reinforcement learning to do some cooool thing. In order to speed up in training, I start 3 clients with server_port = 19997, 19998 and 19999, and I also add

Code: Select all

portIndex1_port             = 19997
portIndex1_debug            = false
portIndex1_syncSimTrigger   = true

portIndex2_port             = 19998
portIndex2_debug            = false
portIndex2_syncSimTrigger   = true

portIndex3_port             = 19999
portIndex3_debug            = false
portIndex3_syncSimTrigger   = true
in remoteApiConnections.txt. The three clients connected to the server successfully, but problem happened when I try to use vrep.simxSetJointTargetPosition() in my code. For example,

Code: Select all

            action1 = [0, 0, 0, 0, 0, 0]
            action2 = [45, 45, 45, 45, 45, 45]
            action3 = [90, 90, 90, 90, 90, 90]
            vrep.simxSetJointTargetPosition(client1.cID, handle, action1, vrep.simx_opmode_blocking))
            vrep.simxSetJointTargetPosition(client2.cID, handle, action2, vrep.simx_opmode_blocking))
            vrep.simxSetJointTargetPosition(client3.cID, handle, action3, vrep.simx_opmode_blocking))
When I use vrep.simxGetJointPosition() to read the 3 clients' joint angles, I found that they are all the same position as one of the clients. It seems that the robot in the simulation only executed one of the clients command. Should I use multi thread or other things to get the right result when I make the 3 clients act with different actions?

fferri
Posts: 206
Joined: 09 Sep 2013, 19:28

Re: Multi clients in python remote api

Post by fferri » 17 Mar 2018, 12:05

What are you trying to achieve? Run three simulations in parallel?

KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Re: Multi clients in python remote api

Post by KaiYang » 19 Mar 2018, 03:04

Thanks for your reply. Yes, I use v-rep as like the openai gym environment. So I really want to run multi simulations in parallel to execute different actions to speed up collecting data.

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

Re: Multi clients in python remote api

Post by coppelia » 19 Mar 2018, 07:43

Hello,

in your code it seems your 3 clients are all acting on the same joint. Why is that, or why do you need 3 clients for that?

Right now you have 3 clients connecting to the same V-REP instance and trying to act on the same joint.
Are you maybe trying to connect to 3 different V-REP instances? In that case, each instance should contain a different port number in their respective remoteApiConnections.txt file. This means that each instance should be started from a different folder. Or, which would be a better way of doing: simply start the appropriate remote APi server service from a child script or from a customization script.

Cheers

KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Re: Multi clients in python remote api

Post by KaiYang » 19 Mar 2018, 08:26

Thanks for your reply! So the problem is that I try to connect the same instance with 3 different clients, and the robot in the scene receive 3 different actions command and execute one of them. To accomplish what I want, I should also provide multi instances for multi clients. Is it right?

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

Re: Multi clients in python remote api

Post by coppelia » 21 Mar 2018, 11:29

to achieve what you want, you need to launch V-REP 3 times.
Then, from a customization script, open a remote API server service as previously mentioned. You cannot use the remoteApiConnections.txt file, since all 3 instances will try to open the same 3 ports (and this will fail, only one instance can open a specific port). So make sure to restore the remoteApiConnections.txt file to its original state, and open 3 distinct remote API server services (e.g. 20000, 20001 and 20002) via simRemoteApi.start.

Cheers

KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Re: Multi clients in python remote api

Post by KaiYang » 22 Mar 2018, 04:11

coppelia wrote:
21 Mar 2018, 11:29
to achieve what you want, you need to launch V-REP 3 times.
Then, from a customization script, open a remote API server service as previously mentioned. You cannot use the remoteApiConnections.txt file, since all 3 instances will try to open the same 3 ports (and this will fail, only one instance can open a specific port). So make sure to restore the remoteApiConnections.txt file to its original state, and open 3 distinct remote API server services (e.g. 20000, 20001 and 20002) via simRemoteApi.start.

Cheers
Hello,

I reset my remoteApiConnections.txt to the original state, and add the simExtRemoteApiStart(port) in 3 different scene*.ttt with the same objects. I used three port number 19997, 19998 and 19999 added in the non-thread child scripts. For example, in scene19998.ttt, I added simExtRemoteApiStart(19998) in the non-thread script. And the new problems is that, I use ./vrep.sh -h /path/to/scene19997.ttt, ./vrep.sh -h /path/to/scene19998.ttt and ./vrep.sh -h /path/to/scene19999.ttt in command line to start the vrep server, but only port 19997 can connect to the server. I knew that I could use ./vrep.sh /path/to/scene*.ttt to start the server and click on the start simulation and my clients would be connected. So is there any way to use multi clients with headless mode?

Best wishes!
Last edited by KaiYang on 22 Mar 2018, 07:28, edited 2 times in total.

KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Re: Multi clients in python remote api

Post by KaiYang » 22 Mar 2018, 07:23

Oh, I found that I can use ./vrep.sh -h -s to start automatically with headless mode, and my problems solved completely. Thank you very much!!

KaiYang
Posts: 9
Joined: 16 Mar 2018, 10:40

Re: Multi clients in python remote api

Post by KaiYang » 22 Mar 2018, 10:18

Problem solved.

enbolee
Posts: 1
Joined: 28 Mar 2018, 09:01

Re: Multi clients in python remote api

Post by enbolee » 05 Apr 2018, 14:25

hello,

I am doing the same thing as you do,and I don't know how to start several different port,could you please help me or share your codes?
my email wolienbo@gmail.com

thanks

Post Reply