Ejemplo n.º 1
0
def set_gamepad(control, throttle, breakk):
    if control == -1:  # stop the car
        client.sendMessage(Commands(0.0, 1, control))
        return

    client.sendMessage(Commands(float(throttle), float(breakk),
                                float(control)))
Ejemplo n.º 2
0
    def work(self):
        """
        Pretend this worker method does work that takes a long time. During this time, the thread's
        event loop is blocked, except if the application's processEvents() is called: this gives every
        thread (incl. main) a chance to process events, which in this sample means processing signals
        received from GUI (such as abort).
        """
        thread_name = QThread.currentThread().objectName()
        thread_id = int(
            QThread.currentThreadId())  # cast to int() is necessary
        self.sig_msg.emit('Running worker #{} from thread "{}" (#{})'.format(
            self.__id, thread_name, thread_id))

        # Creates a new connection to DeepGTAV using the specified ip and port.
        # If desired, a dataset path and compression level can be set to store in memory all the data received in a gziped pickle file.
        # We don't want to save a dataset in this case
        self.client = Client(ip=self.args.host, port=self.args.port)
        # self.client = Client(ip="127.0.0.1", port=8000)

        # We set the scenario to be in manual driving, and everything else random (time, weather and location).
        # See deepgtav/messages.py to see what options are supported
        scenario = Scenario(drivingMode=-1)  #manual driving

        # Send the Start request to DeepGTAV. Dataset is set as default, we only receive frames at 10Hz (320, 160)
        self.client.sendMessage(Start(scenario=scenario))

        # Dummy agent
        model = Model()

        # Start listening for messages coming from DeepGTAV. We do it for 80 hours
        stoptime = time.time() + 80 * 3600
        while (time.time() < stoptime and (not self.__abort)):
            # We receive a message as a Python dictionary
            app.processEvents()
            message = self.client.recvMessage()

            # The frame is a numpy array that can we pass through a CNN for example
            image = frame2numpy(message['frame'], (320, 160))
            commands = model.run(image)
            self.sig_step.emit(self.__id, 'step ' + str(time.time()))
            self.sig_image.emit(image.tolist())
            # We send the commands predicted by the agent back to DeepGTAV to control the vehicle
            self.client.sendMessage(
                Commands(commands[0], commands[1], commands[2]))

        # We tell DeepGTAV to stop
        self.client.sendMessage(Stop())
        self.client.close()

        self.sig_done.emit(self.__id)
Ejemplo n.º 3
0
    # We set the scenario to be in manual driving, and everything else random (time, weather and location).
    # See deepgtav/messages.py to see what options are supported
    scenario = Scenario(drivingMode=-1)  #manual driving

    # Send the Start request to DeepGTAV. Dataset is set as default, we only receive frames at 10Hz (320, 160)
    client.sendMessage(Start(scenario=scenario))

    # Dummy agent
    model = Model()

    # Start listening for messages coming from DeepGTAV. We do it for 80 hours
    stoptime = time.time() + 80 * 3600
    while time.time() < stoptime:
        try:
            # We receive a message as a Python dictionary
            message = client.recvMessage()
            print(message)

            # The frame is a numpy array that can we pass through a CNN for example
            image = frame2numpy(message['frame'], (320, 160))
            commands = model.run(image)
            # We send the commands predicted by the agent back to DeepGTAV to control the vehicle
            client.sendMessage(Commands(commands[0], commands[1], commands[2]))
        except KeyboardInterrupt:
            break

    # We tell DeepGTAV to stop
    client.sendMessage(Stop())
    client.close()
Ejemplo n.º 4
0
count = 0
print("Starting Loop...")
while True:
    try:
        # Collect and preprocess image
        message = client.recvMessage()
        image = frame2numpy(message['frame'], (320, 160))
        image = ((image / 255) - .5) * 2

        # Corrects for model input shape
        model_input = []
        model_input.append(image)

        # Converts classification to float for steering input
        category_prediction = np.argmax(model.predict(np.array(model_input)))
        decimal_prediction = (category_prediction - 500) / 500
        print('Category: ' + str(category_prediction) + '     Decimal: ' +
              str(decimal_prediction))

        client.sendMessage(Commands(
            0.0, 0.0, decimal_prediction *
            3))  # Mutiplication scales decimal prediction for harder turning
        count += 1
    except Exception as e:
        print("Excepted as: " + str(e))
        continue

client.sendMessage(Stop())  # Stops DeepGTAV
client.close()
Ejemplo n.º 5
0
                print('lane controler takes: ', time.time() - t0)

                t0 = time.time()
                vehicle_controler.input(tracked_coord, speed_tracked,
                                        s_tracked_coord, pitch_lidar,
                                        roll_lidar, yaw_rate, steering_angle,
                                        gas_brake, speed_now, acc, target_lane)
                command = vehicle_controler.run()
                print('sttering:  ', steering_angle)
                ##print('Command: ', command) # in camera coord, turn left is +
                ##print('Comannd now: ', steering_angle)
                print('vehicle controler takes: ', time.time() - t0)

                client.sendMessage(
                    Commands(avoid_dead_zone(command[0]),
                             avoid_dead_zone(command[1]), -avoid_dead_zone(
                                 command[2])))  # steering is opposite for GTAV
                #client.sendMessage(Commands(0.8, 0, 0.3))

                all_calculation_time = time.time() - time_now

                # monitor
                if reference_x is not None:
                    if 1:  # for movement detectoin
                        marker_ground_ref = GE.ground_marker_2_image(
                            ground_marker, reference_x, reference_y)
                        image_monitor = IMG.lidar_result_fusion(
                            image_2, marker, marker_ground_ref)

                        #if lanes_3d is not None:
                        #    image_monitor = IMG.test_show_lidar_line(image_monitor, lanes_3d, focus)
Ejemplo n.º 6
0
                    #ax + b = y
                    xx = -(yy - (359 + 1 / steering * 320)) * steering
                else:
                    xx = 320

                cv2.line(img, (320, 319), (int(xx), int(yy)), [255, 0, 0], 2)

                cv2.imshow('binary_image', img)
                cv2.waitKey(1)

                pass
            except Exception as e:
                raise e
        if image_source == USE_GTAV:
            client.sendMessage(
                Commands(throttle, breaker, steering)
            )  # Mutiplication scales decimal prediction for harder turning
        print('loop time: {:.5f}s'.format(time.time() - t_loop_start))

    except KeyboardInterrupt:
        break
    except Exception as e:
        print("Excepted as: " + str(e))
        #if image_source == USE_GTAV:
        #    client.sendMessage(Stop()) # Stops DeepGTAV
        #    client.close()
        raise e
        continue

if image_source == USE_GTAV:
    client.sendMessage(Stop())  # Stops DeepGTAV
Ejemplo n.º 7
0
count = 0
print("Starting Loop...")
while True:
    try:
        # Collect and preprocess image
        # message = client.recvMessage()
        # window title 을 이용해 받아온 window 에서 frame 을 따온다.
        # 기존의 기능에서 이를 제대로 지원하지 않는듯 하기 때문에 추가로 작성함.
        frame_image = screenshot(hwnd=hwnd_list[0])
        # frame_image = normalize(frame_image)
        frame_image = ((frame_image / 255) - .5) * 2  # Simple preprocessing

        # Corrects for model input shape
        # frame_image = image.img_to_array(frame_image)
        frame_image = np.reshape(frame_image, (1,) + frame_image.shape)

        prediction = model.predict(frame_image)
        steering = prediction[0][0]
        steering = float(steering)
        print("predicted steering : " + str(steering))
        client.sendMessage(Commands(0.0, 0.0, steering=steering))
        # Mutiplication scales decimal prediction for harder turning
        count += 1

    except Exception as e:
        print("Excepted as: " + str(e))
        continue

client.sendMessage(Stop())  # Stops DeepGTAV
client.close()
Ejemplo n.º 8
0
 def send_message(self, throttle, brake, steering):
     self.client.sendMessage(Commands(throttle, brake, steering))
     pass
Ejemplo n.º 9
0
        # brake_prediction = np.argmax(nn_output[36:85])
        # brake_prediction = brake_prediction / 50
        duration = time.time() - lasttime
        print('Predicted Steering Value :', str(steering_prediction))
        print('Prediction Probability :', str(steering_probability))
        if steering_prediction > 0.08:
            print('Right')
        elif steering_prediction < -0.05:
            print('Left')
        else:
            print('Straight')
        # print('FPS :',  str(1/(duration)))
        # Mutiplication scales decimal prediction for harder turning

        client.sendMessage(
            Commands(0.3, 0.0,
                     2 / (1 + 2.718**(-5.5 * steering_prediction)) - 1))
        # client.sendMessage(Commands(0.3, 0.0, steering_prediction))
        count += 1

        degrees = (2 / (1 + 2.718**(-5.5 * steering_prediction)) - 1) * 180
        smoothed_angle += 0.2 * pow(abs(
            (degrees - smoothed_angle)), 2.0 / 3.0) * (
                degrees - smoothed_angle) / abs(degrees - smoothed_angle)
        M = cv2.getRotationMatrix2D((cols / 2, rows / 2), -smoothed_angle, 1)
        dst = cv2.warpAffine(img, M, (cols, rows))
        cv2.imshow("steering wheel", dst)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    except Exception as e:
        print("Excepted as: " + str(e))
Ejemplo n.º 10
0
 interval = 0
 while (sqrt((location[0]-args.des[0])**2+(location[1]-args.des[1])**2)>100) and time.time()<stoptime:
     try:
         message = client.recvMessage()
         start = time.time()
         # message is python dict; keys: timestamp, trafficSigns, speed,
         # frame
         if (message['speed']>1) and (manual == False) and time.time()-labelchange[-1]>5:
             manual = True
             labelchange.append(time.time())
             if message['speed']<3:
                 interval = 0.5
             else:
                 interval = 0.25
             random_steering = np.random.uniform(0.5, 0.7) * ((-1.0) ** (np.random.randint(2)))
             client.sendMessage(Commands(throttle=max(message['throttle'],0.3), brake=0.0, steering=random_steering, manual=1))
         if manual:
             print(message['throttle'], message['brake'], message['steering'])
             client.sendMessage(Commands(throttle=max(message['throttle'],0.3), brake=0.0, steering=random_steering, manual=-1))
             if time.time()-labelchange[-1]>interval:
                 manual=False
                 labelchange.append(time.time())
                 client.sendMessage(Commands(throttle=1.0, brake=0.0, steering=1, manual=0))
         if manual:
             print("*"*50)
         location = message['location']
         if message is None:
             stoptime = time.time()
         # The frame is a numpy array and can be displayed using OpenCV
         # or similar
         # image = frame2numpy(message['frame'],
Ejemplo n.º 11
0
                      yawRate=args.yawRate,
                      location=args.if_location,
                      time=args.dataset_time,
                      roadinfo=args.roadinfo,
                      direction=args.des)
    scenario = Scenario(vehicle=args.vehicle,
                        weather=weather,
                        time=args.time,
                        location=args.location)
    client.sendMessage(Start(dataset=dataset, scenario=scenario))
    time.sleep(5)  # wait for the scene to be ready
    # Setup multi-threading for receiving messages
    queue = Queue(maxsize=1)
    manager = Manager()
    c = BufferClient(('localhost', 8766))
    capture_gta_to_queue_only_final(c, queue)

    while True:
        imgtime, img = queue.get()
        imgtime = int(time)
        speed, angle = model(Variable(torch.Tensor(img)))
        throttle, brake, steering = pid(speed, angle)
        client.sendMessage(
            Commands(throttle=throttle,
                     brake=brake,
                     steering=steering,
                     manual=1))

    del queue
    client.close()
Ejemplo n.º 12
0
 def send_message(self, throttle, brake, steering, gear):
     self.client.sendMessage(Commands(throttle, brake, steering,
                                      gear))  #yyz
     pass