I'm try to control the joints in separate threads with Python under Windows 7 32bit. But I cannot get connected to V-REP successfully.
Here my code goes,
Code: Select all
import threading import time import sys import traceback sys.path.insert(0, 'C:\\Program Files\\V-REP3\\V-REP_PRO_EDU\\programming\\Python') import vrep class Joint(threading.Thread): def __init__(self, joint_name, port): threading.Thread.__init__(self) self.client_id = -1 self.port = port self.joint_name = joint_name def run(self): try: # connect to V-REP server self.client_id = vrep.simxStart("127.0.0.1", self.port, False, True, 5000, 5) if self.client_id == -1: raise Exception('Failed to connect V-REP remote API server.') # get handle res, p = vrep.simxGetObjectHandle(self.client_id, self.joint_name.encode(), vrep.simx_opmode_oneshot_wait) if res == vrep.simx_error_noerror: print('[Joint %s] handle= %s' % (self.joint_name, p)) else: raise Exception('Error in getting joint handles.') except Exception as e: print('[Joint %s] %s' % (self.joint_name, e.args)) traceback.print_exc() finally: # disconnect with V-REP server vrep.simxFinish(self.client_id) if __name__ == "__main__": joints = [Joint("joint1", 19999), Joint("joint2", 19998)] for joint in joints: joint.start() time.sleep(1) for joint in joints: joint.join() print("Done")
I have set the content of remoteApiConnections.txt to
// This file defines all the continuous remote API server services (started at remote API plugin initialization)
// Each remote API server service requires following 3 entries:
// portIndex@_port = xxxx // where xxxx is the desired port number (below 20000 are preferred for server services starting at V-REP start-up)
// portIndex@_debug = xxxx // where xxxx is true or false
// portIndex@_syncSimTrigger = xxxx // where xxxx is true or false. When true, then the service will be pre-enabled for synchronous operation. Only one service at a time can be pre-enabled for synchronous operation!
// In above strings, @ can be any number starting with 1. If more than one server service is required, then numbers need to be consecutive and starting with 1
// As an example:
portIndex1_port = 19999
portIndex1_debug = false
portIndex1_syncSimTrigger = true
portIndex2_port = 19998
portIndex2_debug = false
portIndex2_syncSimTrigger = false
And I also checked the connection of port 19998 and 19999, surprisingly port 19999 is not working, I suppose that if these 2 ports are both working, the V-REP connection would be OK, but how can I set the both ports connected?