예제 #1
0
def connect():
    clientId = deepdrive_client.create('127.0.0.1', 9876)
    if clientId > 0:
        print('Connected ...', clientId)

        sharedMem = deepdrive_client.get_shared_memory(clientId)
        print('SharedMemName:', sharedMem[0], "Size", sharedMem[1])

        deepdrive_client.register_camera(clientId, 60, 1024, 1024,
                                         [0.0, 0.0, 200.0])

        connected = deepdrive.reset(sharedMem[0], sharedMem[1])
    return clientId
예제 #2
0
    deepdrive_client.release_agent_control(clientId)
    deepdrive_capture.close()
    deepdrive_client.close(clientId)


client = deepdrive_client.create('127.0.0.1', 9876)

if client != None:
    clientId = client['client_id']
    print('Connected ...', clientId)

    sharedMem = deepdrive_client.get_shared_memory(clientId)
    print('SharedMemName:', sharedMem[0], "Size", sharedMem[1])

    deepdrive_client.register_camera(clientId, 60, 1024, 1024,
                                     [0.0, 0.0, 200.0], [0, 0, 0],
                                     'MainCamera')

    deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0],
                                     [0.0, 0.0, 60.0], 'FrontRight')
    deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0],
                                     [0.0, 0.0, -60.0], 'FrontLeft')
    #deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0], [0.0, 0.0, 120.0])
    #deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0], [0.0, 0.0, -120.0])
    #deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0], [0.0, 0.0, 180.0])
    #deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0], [0.0, 0.0, -60.0])
    #deepdrive_client.register_camera(clientId, 60, 512, 256, [0.0, 0.0, 200.0], [0.0, 0.0, -60.0])

    connected = deepdrive_capture.reset(sharedMem[0], sharedMem[1])
    if connected:
        print('Capture connected')
import socket
import sys
import time

import deepdrive
import deepdrive_client

clientId = deepdrive_client.create('127.0.0.1', 19876)

if clientId > 0:
	print('Connected ...', clientId)

	sharedMem = deepdrive_client.get_shared_memory(clientId)
	print('Connected ...', deepdrive_client.get_shared_memory(clientId))

	deepdrive_client.register_camera(clientId, 60, 1024, 1024, [1.0,2,3])

	ctrlAcquired = deepdrive_client.request_agent_control(clientId)
	print('Control acquired', ctrlAcquired)

	connected = deepdrive.reset(sharedMem[0], sharedMem[1])
	if connected:
		print('Capture connected')
		try:
			while True:
				snapshot = deepdrive.step()
				if snapshot:
					print(snapshot.capture_timestamp, snapshot.sequence_number, snapshot.speed, snapshot.is_game_driving, snapshot.camera_count, len(snapshot.cameras) )
					for c in snapshot.cameras:
						print('Id', c.id, c.capture_width, 'x', c.capture_height)
import deepdrive_client
import numpy

deepdrive_client.register_camera(12, 0.5, 1024, 1024, numpy.array([1.0, 2, 3]))
예제 #5
0
    def connect(self, cameras=None, render=False):
        def _connect():
            try:
                self.connection_props = deepdrive_client.create(
                    '127.0.0.1', 9876)
                if isinstance(self.connection_props, int):
                    raise Exception(
                        'You have an old version of the deepdrive client - try uninstalling and reinstalling with pip'
                    )
                if not self.connection_props or not self.connection_props[
                        'max_capture_resolution']:
                    # Try again
                    return
                self.client_id = self.connection_props['client_id']
                server_version = semvar(
                    self.connection_props['server_protocol_version']).version
                # TODO: For dev, store hash of .cpp and .h files on extension build inside VERSION_DEV, then when
                #   connecting, compute same hash and compare. (Need to figure out what to do on dev packaged version as
                #   files may change - maybe ignore as it's uncommon).
                #   Currently, we timestamp the build, and set that as the version in the extension. This is fine unless
                #   you change shared code and build the extension only, then the versions won't change, and you could
                #   see incompatibilities.

                if semvar(
                        self.client_version).version[:2] != server_version[:2]:
                    raise RuntimeError(
                        'Server and client major/minor version do not match - server is %s and client is %s'
                        % (server_version, self.client_version))

            except deepdrive_client.time_out:
                _connect()

        _connect()
        cxn_attempts = 0
        max_cxn_attempts = 10
        while not self.connection_props:
            cxn_attempts += 1
            sleep = cxn_attempts + random.random(
            ) * 2  # splay to avoid thundering herd
            log.warning(
                'Connection to environment failed, retry (%d/%d) in %d seconds',
                cxn_attempts, max_cxn_attempts, round(sleep, 0))
            time.sleep(sleep)
            _connect()
            if cxn_attempts >= max_cxn_attempts:
                raise RuntimeError('Could not connect to the environment')

        if cameras is None:
            cameras = [c.DEFAULT_CAM]
        self.cameras = cameras
        if self.client_id and self.client_id > 0:
            for cam in self.cameras:
                cam['cxn_id'] = deepdrive_client.register_camera(
                    self.client_id, cam['field_of_view'], cam['capture_width'],
                    cam['capture_height'], cam['relative_position'],
                    cam['relative_rotation'], cam['name'])

            shared_mem = deepdrive_client.get_shared_memory(self.client_id)
            self.reset_capture(shared_mem[0], shared_mem[1])
            self._init_observation_space()
        else:
            self.raise_connect_fail()
        if render:
            self.init_pyglet(cameras)

        self._perform_first_step()
        self.has_control = False